Skip to content

Commit

Permalink
New Resource: alicloud_api_gateway_instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenHanZhang committed Jan 31, 2024
1 parent 6bd22e3 commit 3fa4269
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 94 deletions.
17 changes: 4 additions & 13 deletions alicloud/resource_alicloud_api_gateway_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ func resourceAliCloudApiGatewayInstance() *schema.Resource {
},
"https_policy": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Required: true,
},
"instance_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -74,10 +73,6 @@ func resourceAliCloudApiGatewayInstance() *schema.Resource {
Optional: true,
Sensitive: true,
},
"token": {
Type: schema.TypeString,
Required: true,
},
"user_vpc_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -125,10 +120,7 @@ func resourceAliCloudApiGatewayInstanceCreate(d *schema.ResourceData, meta inter
request["InstanceName"] = d.Get("instance_name")
request["InstanceSpec"] = d.Get("instance_spec")
request["ChargeType"] = convertApiGatewayInstanceChargeTypeRequest(d.Get("payment_type").(string))
request["Token"] = d.Get("token")
if v, ok := d.GetOk("https_policy"); ok {
request["HttpsPolicy"] = v
}
request["HttpsPolicy"] = d.Get("https_policy")
if v, ok := d.GetOk("instance_type"); ok {
request["InstanceType"] = v
}
Expand Down Expand Up @@ -221,9 +213,8 @@ func resourceAliCloudApiGatewayInstanceUpdate(d *schema.ResourceData, meta inter
request["InstanceName"] = d.Get("instance_name")
if !d.IsNewResource() && d.HasChange("https_policy") {
update = true
request["HttpsPolicy"] = d.Get("https_policy")
}

request["HttpsPolicy"] = d.Get("https_policy")
if d.HasChange("egress_ipv6_enable") {
update = true
request["EgressIpv6Enable"] = d.Get("egress_ipv6_enable")
Expand All @@ -246,7 +237,7 @@ func resourceAliCloudApiGatewayInstanceUpdate(d *schema.ResourceData, meta inter
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2016-07-14"), StringPointer("AK"), query, request, &runtime)

request["Token"] = d.Get("token")
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
125 changes: 50 additions & 75 deletions alicloud/resource_alicloud_api_gateway_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import (
)

// Test ApiGateway Instance. >>> Resource test cases, automatically generated.
// Case 对接Terraform_PREPAY 5806
func TestAccAliCloudApiGatewayInstance_basic5806(t *testing.T) {
// Case 对接Terraform_NORMAL 5800
func TestAccAliCloudApiGatewayInstance_basic5800(t *testing.T) {
var v map[string]interface{}
resourceId := "alicloud_api_gateway_instance.default"
ra := resourceAttrInit(resourceId, AlicloudApiGatewayInstanceMap5806)
ra := resourceAttrInit(resourceId, AlicloudApiGatewayInstanceMap5800)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &ApiGatewayServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeApiGatewayInstance")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(10000, 99999)
name := fmt.Sprintf("tf-testacc%sapigatewayinstance%d", defaultRegionToTest, rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudApiGatewayInstanceBasicDependence5806)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudApiGatewayInstanceBasicDependence5800)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
Expand All @@ -35,25 +35,15 @@ func TestAccAliCloudApiGatewayInstance_basic5806(t *testing.T) {
Config: testAccConfig(map[string]interface{}{
"instance_name": name,
"instance_spec": "api.s1.small",
"payment_type": "Subscription",
"token": "1706663347",
"https_policy": "HTTPS2_TLS1_0",
"payment_type": "PayAsYouGo",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"instance_name": name,
"instance_spec": "api.s1.small",
"payment_type": "Subscription",
"token": CHECKSET,
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"https_policy": "HTTPS2_TLS1_0",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"https_policy": "HTTPS2_TLS1_0",
"https_policy": "HTTPS2_TLS1_0",
"payment_type": "PayAsYouGo",
}),
),
},
Expand Down Expand Up @@ -143,10 +133,9 @@ func TestAccAliCloudApiGatewayInstance_basic5806(t *testing.T) {
"instance_spec": "api.s1.small",
"https_policy": "HTTPS2_TLS1_0",
"zone_id": "cn-hangzhou-MAZ6",
"payment_type": "Subscription",
"token": "1706663347",
"payment_type": "PayAsYouGo",
"instance_type": "NORMAL",
"user_vpc_id": "1706663347",
"user_vpc_id": "${alicloud_vpc.defaultVpc.id}",
"egress_ipv6_enable": "true",
"support_ipv6": "true",
"vpc_slb_intranet_enable": "true",
Expand All @@ -157,8 +146,7 @@ func TestAccAliCloudApiGatewayInstance_basic5806(t *testing.T) {
"instance_spec": "api.s1.small",
"https_policy": "HTTPS2_TLS1_0",
"zone_id": "cn-hangzhou-MAZ6",
"payment_type": "Subscription",
"token": CHECKSET,
"payment_type": "PayAsYouGo",
"instance_type": "NORMAL",
"user_vpc_id": CHECKSET,
"egress_ipv6_enable": "true",
Expand All @@ -171,44 +159,48 @@ func TestAccAliCloudApiGatewayInstance_basic5806(t *testing.T) {
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"acl_id", "acl_name", "acl_status", "acl_type", "classic_egress_address", "egress_ipv6_enable", "expired_time", "instance_rps_limit", "instance_spec_attributes", "instance_type", "internet_egress_address", "support_ipv6", "token", "user_vpc_id", "user_vswitch_id", "vip_type_list", "vpc_egress_address", "vpc_intranet_enable", "vpc_owner_id", "vpc_slb_intranet_enable", "zone_local_name"},
ImportStateVerifyIgnore: []string{"acl_id", "acl_name", "acl_status", "acl_type", "classic_egress_address", "egress_ipv6_enable", "expired_time", "instance_rps_limit", "instance_spec_attributes", "instance_type", "internet_egress_address", "support_ipv6", "user_vpc_id", "user_vswitch_id", "vip_type_list", "vpc_egress_address", "vpc_intranet_enable", "vpc_owner_id", "vpc_slb_intranet_enable", "zone_local_name"},
},
},
})
}

var AlicloudApiGatewayInstanceMap5806 = map[string]string{
"https_policy": "HTTPS2_TLS1_0",
var AlicloudApiGatewayInstanceMap5800 = map[string]string{
"vpc_slb_intranet_enable": "false",
"status": CHECKSET,
"create_time": CHECKSET,
"egress_ipv6_enable": "false",
"support_ipv6": "false",
}

func AlicloudApiGatewayInstanceBasicDependence5806(name string) string {
func AlicloudApiGatewayInstanceBasicDependence5800(name string) string {
return fmt.Sprintf(`
variable "name" {
default = "%s"
}
resource "alicloud_vpc" "defaultVpc" {
cidr_block = "172.16.0.0/12"
enable_ipv6 = true
}
`, name)
}

// Case 对接Terraform_NORMAL 5800
func TestAccAliCloudApiGatewayInstance_basic5800(t *testing.T) {
// Case 对接Terraform_PREPAY 5806
func TestAccAliCloudApiGatewayInstance_basic5806(t *testing.T) {
var v map[string]interface{}
resourceId := "alicloud_api_gateway_instance.default"
ra := resourceAttrInit(resourceId, AlicloudApiGatewayInstanceMap5800)
ra := resourceAttrInit(resourceId, AlicloudApiGatewayInstanceMap5806)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &ApiGatewayServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeApiGatewayInstance")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(10000, 99999)
name := fmt.Sprintf("tf-testacc%sapigatewayinstance%d", defaultRegionToTest, rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudApiGatewayInstanceBasicDependence5800)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudApiGatewayInstanceBasicDependence5806)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
Expand All @@ -221,25 +213,15 @@ func TestAccAliCloudApiGatewayInstance_basic5800(t *testing.T) {
Config: testAccConfig(map[string]interface{}{
"instance_name": name,
"instance_spec": "api.s1.small",
"payment_type": "PayAsYouGo",
"token": "1706663347",
"https_policy": "HTTPS2_TLS1_0",
"payment_type": "Subscription",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"instance_name": name,
"instance_spec": "api.s1.small",
"payment_type": "PayAsYouGo",
"token": CHECKSET,
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"https_policy": "HTTPS2_TLS1_0",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"https_policy": "HTTPS2_TLS1_0",
"https_policy": "HTTPS2_TLS1_0",
"payment_type": "Subscription",
}),
),
},
Expand Down Expand Up @@ -329,10 +311,9 @@ func TestAccAliCloudApiGatewayInstance_basic5800(t *testing.T) {
"instance_spec": "api.s1.small",
"https_policy": "HTTPS2_TLS1_0",
"zone_id": "cn-hangzhou-MAZ6",
"payment_type": "PayAsYouGo",
"token": "1706663347",
"payment_type": "Subscription",
"instance_type": "NORMAL",
"user_vpc_id": "1706663347",
"user_vpc_id": "1706693152",
"egress_ipv6_enable": "true",
"support_ipv6": "true",
"vpc_slb_intranet_enable": "true",
Expand All @@ -343,8 +324,7 @@ func TestAccAliCloudApiGatewayInstance_basic5800(t *testing.T) {
"instance_spec": "api.s1.small",
"https_policy": "HTTPS2_TLS1_0",
"zone_id": "cn-hangzhou-MAZ6",
"payment_type": "PayAsYouGo",
"token": CHECKSET,
"payment_type": "Subscription",
"instance_type": "NORMAL",
"user_vpc_id": CHECKSET,
"egress_ipv6_enable": "true",
Expand All @@ -357,22 +337,21 @@ func TestAccAliCloudApiGatewayInstance_basic5800(t *testing.T) {
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"acl_id", "acl_name", "acl_status", "acl_type", "classic_egress_address", "egress_ipv6_enable", "expired_time", "instance_rps_limit", "instance_spec_attributes", "instance_type", "internet_egress_address", "support_ipv6", "token", "user_vpc_id", "user_vswitch_id", "vip_type_list", "vpc_egress_address", "vpc_intranet_enable", "vpc_owner_id", "vpc_slb_intranet_enable", "zone_local_name"},
ImportStateVerifyIgnore: []string{"acl_id", "acl_name", "acl_status", "acl_type", "classic_egress_address", "egress_ipv6_enable", "expired_time", "instance_rps_limit", "instance_spec_attributes", "instance_type", "internet_egress_address", "support_ipv6", "user_vpc_id", "user_vswitch_id", "vip_type_list", "vpc_egress_address", "vpc_intranet_enable", "vpc_owner_id", "vpc_slb_intranet_enable", "zone_local_name"},
},
},
})
}

var AlicloudApiGatewayInstanceMap5800 = map[string]string{
"https_policy": "HTTPS2_TLS1_0",
var AlicloudApiGatewayInstanceMap5806 = map[string]string{
"vpc_slb_intranet_enable": "false",
"status": CHECKSET,
"create_time": CHECKSET,
"egress_ipv6_enable": "false",
"support_ipv6": "false",
}

func AlicloudApiGatewayInstanceBasicDependence5800(name string) string {
func AlicloudApiGatewayInstanceBasicDependence5806(name string) string {
return fmt.Sprintf(`
variable "name" {
default = "%s"
Expand All @@ -382,37 +361,36 @@ variable "name" {
`, name)
}

// Case 对接Terraform_PREPAY 5806 twin
func TestAccAliCloudApiGatewayInstance_basic5806_twin(t *testing.T) {
// Case 对接Terraform_NORMAL 5800 twin
func TestAccAliCloudApiGatewayInstance_basic5800_twin(t *testing.T) {
var v map[string]interface{}
resourceId := "alicloud_api_gateway_instance.default"
ra := resourceAttrInit(resourceId, AlicloudApiGatewayInstanceMap5806)
ra := resourceAttrInit(resourceId, AlicloudApiGatewayInstanceMap5800)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &ApiGatewayServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeApiGatewayInstance")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(10000, 99999)
name := fmt.Sprintf("tf-testacc%sapigatewayinstance%d", defaultRegionToTest, rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudApiGatewayInstanceBasicDependence5806)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudApiGatewayInstanceBasicDependence5800)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
IDRefreshName: resourceId,
Providers: testAccProviders,
//CheckDestroy: rac.checkResourceDestroy(),
CheckDestroy: rac.checkResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"instance_name": name,
"instance_spec": "api.s1.small",
"https_policy": "HTTPS2_TLS1_2",
"zone_id": "cn-hangzhou-MAZ6",
"payment_type": "Subscription",
"token": "1706663341",
"payment_type": "PayAsYouGo",
"instance_type": "NORMAL",
"user_vpc_id": "1706663347",
"user_vpc_id": "${alicloud_vpc.defaultVpc.id}",
"egress_ipv6_enable": "false",
"support_ipv6": "false",
"vpc_slb_intranet_enable": "false",
Expand All @@ -423,8 +401,7 @@ func TestAccAliCloudApiGatewayInstance_basic5806_twin(t *testing.T) {
"instance_spec": "api.s1.small",
"https_policy": "HTTPS2_TLS1_2",
"zone_id": "cn-hangzhou-MAZ6",
"payment_type": "Subscription",
"token": CHECKSET,
"payment_type": "PayAsYouGo",
"instance_type": "NORMAL",
"user_vpc_id": CHECKSET,
"egress_ipv6_enable": "false",
Expand All @@ -437,25 +414,25 @@ func TestAccAliCloudApiGatewayInstance_basic5806_twin(t *testing.T) {
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"acl_id", "acl_name", "acl_status", "acl_type", "classic_egress_address", "egress_ipv6_enable", "expired_time", "instance_rps_limit", "instance_spec_attributes", "instance_type", "internet_egress_address", "support_ipv6", "token", "user_vpc_id", "user_vswitch_id", "vip_type_list", "vpc_egress_address", "vpc_intranet_enable", "vpc_owner_id", "vpc_slb_intranet_enable", "zone_local_name"},
ImportStateVerifyIgnore: []string{"acl_id", "acl_name", "acl_status", "acl_type", "classic_egress_address", "egress_ipv6_enable", "expired_time", "instance_rps_limit", "instance_spec_attributes", "instance_type", "internet_egress_address", "support_ipv6", "user_vpc_id", "user_vswitch_id", "vip_type_list", "vpc_egress_address", "vpc_intranet_enable", "vpc_owner_id", "vpc_slb_intranet_enable", "zone_local_name"},
},
},
})
}

// Case 对接Terraform_NORMAL 5800 twin
func TestAccAliCloudApiGatewayInstance_basic5800_twin(t *testing.T) {
// Case 对接Terraform_PREPAY 5806 twin
func TestAccAliCloudApiGatewayInstance_basic5806_twin(t *testing.T) {
var v map[string]interface{}
resourceId := "alicloud_api_gateway_instance.default"
ra := resourceAttrInit(resourceId, AlicloudApiGatewayInstanceMap5800)
ra := resourceAttrInit(resourceId, AlicloudApiGatewayInstanceMap5806)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &ApiGatewayServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeApiGatewayInstance")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(10000, 99999)
name := fmt.Sprintf("tf-testacc%sapigatewayinstance%d", defaultRegionToTest, rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudApiGatewayInstanceBasicDependence5800)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudApiGatewayInstanceBasicDependence5806)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
Expand All @@ -470,10 +447,9 @@ func TestAccAliCloudApiGatewayInstance_basic5800_twin(t *testing.T) {
"instance_spec": "api.s1.small",
"https_policy": "HTTPS2_TLS1_2",
"zone_id": "cn-hangzhou-MAZ6",
"payment_type": "PayAsYouGo",
"token": "1706663348",
"payment_type": "Subscription",
"instance_type": "NORMAL",
"user_vpc_id": "1706663347",
"user_vpc_id": "1706693152",
"egress_ipv6_enable": "false",
"support_ipv6": "false",
"vpc_slb_intranet_enable": "false",
Expand All @@ -484,8 +460,7 @@ func TestAccAliCloudApiGatewayInstance_basic5800_twin(t *testing.T) {
"instance_spec": "api.s1.small",
"https_policy": "HTTPS2_TLS1_2",
"zone_id": "cn-hangzhou-MAZ6",
"payment_type": "PayAsYouGo",
"token": CHECKSET,
"payment_type": "Subscription",
"instance_type": "NORMAL",
"user_vpc_id": CHECKSET,
"egress_ipv6_enable": "false",
Expand All @@ -498,7 +473,7 @@ func TestAccAliCloudApiGatewayInstance_basic5800_twin(t *testing.T) {
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"acl_id", "acl_name", "acl_status", "acl_type", "classic_egress_address", "egress_ipv6_enable", "expired_time", "instance_rps_limit", "instance_spec_attributes", "instance_type", "internet_egress_address", "support_ipv6", "token", "user_vpc_id", "user_vswitch_id", "vip_type_list", "vpc_egress_address", "vpc_intranet_enable", "vpc_owner_id", "vpc_slb_intranet_enable", "zone_local_name"},
ImportStateVerifyIgnore: []string{"acl_id", "acl_name", "acl_status", "acl_type", "classic_egress_address", "egress_ipv6_enable", "expired_time", "instance_rps_limit", "instance_spec_attributes", "instance_type", "internet_egress_address", "support_ipv6", "user_vpc_id", "user_vswitch_id", "vip_type_list", "vpc_egress_address", "vpc_intranet_enable", "vpc_owner_id", "vpc_slb_intranet_enable", "zone_local_name"},
},
},
})
Expand Down

0 comments on commit 3fa4269

Please sign in to comment.