Skip to content

Commit 6200eb8

Browse files
committed
Merge branch fix-vpngateway into v3.18xR
Title: fix tags read bug 本次代码评审主要对VPN网关资源进行了多项改进,包括修复代码格式问题、更新测试用例以匹配新的字段名称(如将`spec`改为`bandwidth`)、移除过时的检查映射,并引入了新的测试案例结构。 Link: https://code.alibaba-inc.com/apsarastack-cross-platform/terraform-provider-apsarastack/codereview/20644518
2 parents e2a8fa7 + a1c95c4 commit 6200eb8

3 files changed

+53
-118
lines changed

alibabacloudstack/resource_apsarastack_vpngateway_vpngateway.go

+31-31
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ func resourceAlibabacloudStackVpnGateway() *schema.Resource {
3030

3131
Schema: map[string]*schema.Schema{
3232
"name": {
33-
Type: schema.TypeString,
34-
Optional: true,
35-
ValidateFunc: validation.StringLenBetween(1, 128),
36-
Computed: true,
37-
Deprecated: "Field 'name' is deprecated and will be removed in a future release. Please use new field 'vpn_gateway_name' instead.",
33+
Type: schema.TypeString,
34+
Optional: true,
35+
ValidateFunc: validation.StringLenBetween(1, 128),
36+
Computed: true,
37+
Deprecated: "Field 'name' is deprecated and will be removed in a future release. Please use new field 'vpn_gateway_name' instead.",
3838
ConflictsWith: []string{"vpn_gateway_name"},
3939
},
4040
"vpn_gateway_name": {
41-
Type: schema.TypeString,
42-
Optional: true,
43-
ValidateFunc: validation.StringLenBetween(1, 128),
44-
Computed: true,
41+
Type: schema.TypeString,
42+
Optional: true,
43+
ValidateFunc: validation.StringLenBetween(1, 128),
44+
Computed: true,
4545
ConflictsWith: []string{"name"},
4646
},
4747
"vpc_id": {
@@ -73,47 +73,47 @@ func resourceAlibabacloudStackVpnGateway() *schema.Resource {
7373
},
7474

7575
"enable_ipsec": {
76-
Type: schema.TypeBool,
77-
Optional: true,
78-
Computed:true,
79-
Deprecated: "Field 'enable_ipsec' is deprecated and will be removed in a future release. Please use new field 'ipsec_vpn' instead.",
76+
Type: schema.TypeBool,
77+
Optional: true,
78+
Computed: true,
79+
Deprecated: "Field 'enable_ipsec' is deprecated and will be removed in a future release. Please use new field 'ipsec_vpn' instead.",
8080
ConflictsWith: []string{"ipsec_vpn"},
8181
},
8282
"ipsec_vpn": {
83-
Type: schema.TypeBool,
84-
Optional: true,
85-
Computed:true,
83+
Type: schema.TypeBool,
84+
Optional: true,
85+
Computed: true,
8686
ConflictsWith: []string{"enable_ipsec"},
8787
},
8888

8989
"enable_ssl": {
90-
Type: schema.TypeBool,
91-
Optional: true,
92-
Computed:true,
93-
Deprecated: "Field 'enable_ssl' is deprecated and will be removed in a future release. Please use new field 'ssl_vpn' instead.",
90+
Type: schema.TypeBool,
91+
Optional: true,
92+
Computed: true,
93+
Deprecated: "Field 'enable_ssl' is deprecated and will be removed in a future release. Please use new field 'ssl_vpn' instead.",
9494
ConflictsWith: []string{"ssl_vpn"},
9595
},
9696
"ssl_vpn": {
97-
Type: schema.TypeBool,
98-
Optional: true,
99-
Computed:true,
97+
Type: schema.TypeBool,
98+
Optional: true,
99+
Computed: true,
100100
ConflictsWith: []string{"enable_ssl"},
101101
},
102102

103103
"ssl_connections": {
104104
Type: schema.TypeInt,
105105
Optional: true,
106-
Computed:true,
106+
Computed: true,
107107
DiffSuppressFunc: vpnSslConnectionsDiffSuppressFunc,
108108
Deprecated: "Field 'ssl_connections' is deprecated and will be removed in a future release. Please use new field 'ssl_max_connections' instead.",
109-
ConflictsWith: []string{"ssl_max_connections"},
109+
ConflictsWith: []string{"ssl_max_connections"},
110110
},
111111
"ssl_max_connections": {
112112
Type: schema.TypeInt,
113113
Optional: true,
114-
Computed:true,
114+
Computed: true,
115115
DiffSuppressFunc: vpnSslConnectionsDiffSuppressFunc,
116-
ConflictsWith: []string{"ssl_connections"},
116+
ConflictsWith: []string{"ssl_connections"},
117117
},
118118

119119
"description": {
@@ -155,7 +155,7 @@ func resourceAlibabacloudStackVpnGatewayCreate(d *schema.ResourceData, meta inte
155155
client.InitRpcRequest(*request.RpcRequest)
156156
request.VpcId = d.Get("vpc_id").(string)
157157

158-
if v, ok := connectivity.GetResourceDataOk(d, "vpn_gateway_name", "name"); ok && v.(string) != ""{
158+
if v, ok := connectivity.GetResourceDataOk(d, "vpn_gateway_name", "name"); ok && v.(string) != "" {
159159
request.Name = v.(string)
160160
}
161161

@@ -193,7 +193,7 @@ func resourceAlibabacloudStackVpnGatewayCreate(d *schema.ResourceData, meta inte
193193

194194
if v, ok := connectivity.GetResourceDataOk(d, "ssl_max_connections", "ssl_connections"); ok {
195195
request.SslConnections = requests.NewInteger(v.(int))
196-
}else {
196+
} else {
197197
//Default must be nil if computed
198198
request.SslConnections = requests.NewInteger(5)
199199
}
@@ -244,7 +244,7 @@ func resourceAlibabacloudStackVpnGatewayRead(d *schema.ResourceData, meta interf
244244
d.Set("internet_ip", object.InternetIp)
245245
d.Set("status", object.Status)
246246
d.Set("vswitch_id", object.VSwitchId)
247-
connectivity.SetResourceData(d, "enable" == strings.ToLower(object.IpsecVpn), "ipsec_vpn", "enable")
247+
connectivity.SetResourceData(d, "enable" == strings.ToLower(object.IpsecVpn), "ipsec_vpn", "enable_ipsec")
248248
connectivity.SetResourceData(d, "enable" == strings.ToLower(object.SslVpn), "ssl_vpn", "enable_ssl")
249249
connectivity.SetResourceData(d, object.SslMaxConnections, "ssl_max_connections", "ssl_connections")
250250
d.Set("business_status", object.BusinessStatus)
@@ -325,7 +325,7 @@ func resourceAlibabacloudStackVpnGatewayUpdate(d *schema.ResourceData, meta inte
325325
return fmt.Errorf("Now Cann't Support modify vpn gateway bandwidth, try to modify on the web console")
326326
}
327327

328-
if d.HasChanges("enable_ipsec","enable_ssl","ipsec_vpn", "ssl_vpn") {
328+
if d.HasChanges("enable_ipsec", "enable_ssl", "ipsec_vpn", "ssl_vpn") {
329329
return fmt.Errorf("Now Cann't Support modify ipsec/ssl switch, try to modify on the web console")
330330
}
331331
if d.HasChanges("ssl_max_connections", "ssl_connections") {

alibabacloudstack/resource_apsarastack_vpngateway_vpngateway_test.go

+19-85
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ import (
44
"fmt"
55
"testing"
66

7+
"github.com/aliyun/alibaba-cloud-sdk-go/services/vpc"
78
"github.com/aliyun/terraform-provider-alibabacloudstack/alibabacloudstack/connectivity"
8-
9+
910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1011
)
1112

1213
func TestAccAlibabacloudStackVpngatewayVpngateway0(t *testing.T) {
13-
var v map[string]interface{}
14+
var v vpc.DescribeVpnGatewayResponse
1415

1516
resourceId := "alibabacloudstack_vpngateway_vpngateway.default"
1617
ra := resourceAttrInit(resourceId, AlibabacloudTestAccVpngatewayVpngatewayCheckmap)
1718
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
1819
return &VpnGatewayService{testAccProvider.Meta().(*connectivity.AlibabacloudStackClient)}
19-
}, "DoVpcDescribevpngatewayRequest")
20+
}, "DescribeVpnGateway")
2021
rac := resourceAttrCheckInit(rc, ra)
2122
testAccCheck := rac.resourceAttrMapUpdateSet()
2223

@@ -43,13 +44,15 @@ func TestAccAlibabacloudStackVpngatewayVpngateway0(t *testing.T) {
4344

4445
"vpn_gateway_name": "test_vpn",
4546

46-
"spec": "10",
47+
"bandwidth": "10",
48+
49+
"vswitch_id": "${alibabacloudstack_vpc_vswitch.default.id}",
4750

48-
"vswitch_id": "${{ref(resource, VPC::VSwitch::2.0.0.2.pre::defaultVswitch_1.VSwitchId)}}",
51+
"vpc_id": "${alibabacloudstack_vpc_vpc.default.id}",
4952

50-
"vpc_id": "${{ref(resource, VPC::VPC::4.0.0.26.pre::defaultVpc.VpcId)}}",
53+
"enable_ssl": "true",
5154

52-
"payment_type": "PayAsYouGo",
55+
"instance_charge_type": "PostPaid",
5356
}),
5457
Check: resource.ComposeTestCheckFunc(
5558
testAccCheck(map[string]string{
@@ -58,13 +61,15 @@ func TestAccAlibabacloudStackVpngatewayVpngateway0(t *testing.T) {
5861

5962
"vpn_gateway_name": "test_vpn",
6063

61-
"spec": "10",
64+
"bandwidth": "10",
6265

63-
"vswitch_id": "${{ref(resource, VPC::VSwitch::2.0.0.2.pre::defaultVswitch_1.VSwitchId)}}",
66+
"vswitch_id": CHECKSET,
6467

65-
"vpc_id": "${{ref(resource, VPC::VPC::4.0.0.26.pre::defaultVpc.VpcId)}}",
68+
"vpc_id": CHECKSET,
6669

67-
"payment_type": "PayAsYouGo",
70+
"enable_ssl": "true",
71+
72+
"instance_charge_type": "PostPaid",
6873
}),
6974
),
7075
},
@@ -85,90 +90,19 @@ func TestAccAlibabacloudStackVpngatewayVpngateway0(t *testing.T) {
8590
}),
8691
),
8792
},
88-
89-
{
90-
Config: testAccConfig(map[string]interface{}{}),
91-
Check: resource.ComposeTestCheckFunc(
92-
testAccCheck(map[string]string{}),
93-
),
94-
},
95-
96-
{
97-
Config: testAccConfig(map[string]interface{}{
98-
99-
"description": "test_vpn",
100-
101-
"vpn_gateway_name": "test_vpn",
102-
103-
"spec": "10",
104-
105-
"vswitch_id": "${{ref(resource, VPC::VSwitch::2.0.0.2.pre::defaultVswitch_1.VSwitchId)}}",
106-
107-
"vpc_id": "${{ref(resource, VPC::VPC::4.0.0.26.pre::defaultVpc.VpcId)}}",
108-
109-
"payment_type": "PayAsYouGo",
110-
}),
111-
Check: resource.ComposeTestCheckFunc(
112-
testAccCheck(map[string]string{
113-
114-
"description": "test_vpn",
115-
116-
"vpn_gateway_name": "test_vpn",
117-
118-
"spec": "10",
119-
120-
"vswitch_id": "${{ref(resource, VPC::VSwitch::2.0.0.2.pre::defaultVswitch_1.VSwitchId)}}",
121-
122-
"vpc_id": "${{ref(resource, VPC::VPC::4.0.0.26.pre::defaultVpc.VpcId)}}",
123-
124-
"payment_type": "PayAsYouGo",
125-
}),
126-
),
127-
},
12893
},
12994
})
13095
}
13196

132-
var AlibabacloudTestAccVpngatewayVpngatewayCheckmap = map[string]string{
133-
134-
"ipsec_vpn": CHECKSET,
135-
136-
"ssl_vpn": CHECKSET,
137-
138-
"description": CHECKSET,
139-
140-
"end_time": CHECKSET,
141-
142-
"business_status": CHECKSET,
143-
144-
"vpn_instance_id": CHECKSET,
145-
146-
"internet_ip": CHECKSET,
147-
148-
"payment_type": CHECKSET,
149-
150-
"ssl_max_connections": CHECKSET,
151-
152-
"status": CHECKSET,
153-
154-
"vpn_gateway_name": CHECKSET,
155-
156-
"create_time": CHECKSET,
157-
158-
"vswitch_id": CHECKSET,
159-
160-
"vpc_id": CHECKSET,
161-
162-
"spec": CHECKSET,
163-
}
97+
var AlibabacloudTestAccVpngatewayVpngatewayCheckmap = map[string]string{}
16498

16599
func AlibabacloudTestAccVpngatewayVpngatewayBasicdependence(name string) string {
166100
return fmt.Sprintf(`
167101
variable "name" {
168102
default = "%s"
169103
}
170104
105+
%s
171106
172-
173-
`, name)
107+
`, name, VSwitchCommonTestCase)
174108
}

alibabacloudstack/service_apsarastack_vpc.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,8 @@ func (s *VpcService) ListTagResources(id string, resourceType string) (object in
16641664
var response map[string]interface{}
16651665

16661666
for {
1667-
_, err := s.client.DoTeaRequest("POST", "Vpc", "2016-04-28", action, "", nil, request)
1667+
response, err = s.client.DoTeaRequest("POST", "Vpc", "2016-04-28", action, "", nil, nil, request)
1668+
addDebug("ListTagResources", response, request)
16681669
if err != nil {
16691670
return nil, err
16701671
}
@@ -1675,7 +1676,7 @@ func (s *VpcService) ListTagResources(id string, resourceType string) (object in
16751676
if v != nil {
16761677
tags = append(tags, v.([]interface{})...)
16771678
}
1678-
if response["NextToken"] == nil {
1679+
if response["NextToken"].(string) == "" {
16791680
break
16801681
}
16811682
request["NextToken"] = response["NextToken"]

0 commit comments

Comments
 (0)