Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testcase/alicloud_nat_gateway: Improves the nat gateway testcases; testcase/alicloud_snat_entry: Improves the snat entry testcases; #4474

Merged
merged 1 commit into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 3 additions & 7 deletions alicloud/resource_alicloud_nat_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ func TestAccAlicloudNatGateway_basic(t *testing.T) {
"specification": "Middle",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"specification": "Middle",
}),
testAccCheck(map[string]string{}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是为啥注释掉?是不返回了么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个字段仅当InstanceChargeType为PrePaid(包年包月公网NAT网关)创建的资源才有效,这里虽然可以update,并且update不报错。但是其实update这一步是没有起到修改作用的。包年包月公网NAT网关,才会返回这个字段。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

正常的后付费资源,这个spec字段是返回空的

),
},
{
Expand Down Expand Up @@ -244,7 +242,7 @@ func TestAccAlicloudNatGateway_basic(t *testing.T) {
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"specification": "Small",
"specification": "",
"description": name,
"nat_gateway_name": name,
"tags.%": "2",
Expand Down Expand Up @@ -569,7 +567,7 @@ var AlicloudNatGatewayMap0 = map[string]string{
"payment_type": "PayAsYouGo",
"period": NOSET,
"snat_table_ids": CHECKSET,
"specification": "Small",
"specification": "",
"status": "Available",
"tags.%": "0",
"vswitch_id": "",
Expand Down Expand Up @@ -610,7 +608,6 @@ var AlicloudNatGatewayMap1 = map[string]string{
"payment_type": "PayAsYouGo",
"period": NOSET,
"snat_table_ids": CHECKSET,
"specification": "",
"status": "Available",
"tags.%": "0",
"deletion_protection": "false",
Expand Down Expand Up @@ -649,7 +646,6 @@ var AlicloudNatGatewayMap3 = map[string]string{
"nat_type": CHECKSET,
"payment_type": CHECKSET,
"snat_table_ids": CHECKSET,
"specification": "Small",
"status": "Available",
"tags.%": "0",
"vswitch_id": "",
Expand Down
64 changes: 44 additions & 20 deletions alicloud/resource_alicloud_snat_entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,34 @@ variable "name" {
default = "%s"
}

data "alicloud_enhanced_nat_available_zones" "default" {}

data "alicloud_zones" "default" {
available_resource_creation = "VSwitch"
}
data "alicloud_vpcs" "default" {
name_regex = "default-NODELETING"
name_regex = "default-NODELETING"
}

data "alicloud_vswitches" "default" {
vpc_id = data.alicloud_vpcs.default.ids.0
zone_id = data.alicloud_enhanced_nat_available_zones.default.zones.0.zone_id
vpc_id = data.alicloud_vpcs.default.ids.0
zone_id = data.alicloud_zones.default.zones.0.id
}
resource "alicloud_vswitch" "vswitch" {
count = length(data.alicloud_vswitches.default.ids) > 0 ? 0 : 1
vpc_id = data.alicloud_vpcs.default.ids.0
cidr_block = cidrsubnet(data.alicloud_vpcs.default.vpcs[0].cidr_block, 8, 8)
zone_id = data.alicloud_zones.default.zones.0.id
vswitch_name = var.name
}
locals {
vswitch_id = length(data.alicloud_vswitches.default.ids) > 0 ? data.alicloud_vswitches.default.ids[0] : concat(alicloud_vswitch.vswitch.*.id, [""])[0]
}

resource "alicloud_nat_gateway" "default" {
vpc_id = data.alicloud_vpcs.default.ids.0
nat_gateway_name = var.name
payment_type = "PayAsYouGo"
vswitch_id = data.alicloud_vswitches.default.ids[0]
nat_type = "Enhanced"
vpc_id = data.alicloud_vpcs.default.ids.0
network_type = "internet"
nat_gateway_name = "${var.name}"
vswitch_id = local.vswitch_id
nat_type = "Enhanced"
internet_charge_type = "PayByLcu"
}

resource "alicloud_eip_address" "default" {
Expand All @@ -202,21 +213,34 @@ variable "name" {

data "alicloud_enhanced_nat_available_zones" "default" {}

data "alicloud_zones" "default" {
available_resource_creation = "VSwitch"
}
data "alicloud_vpcs" "default" {
name_regex = "default-NODELETING"
name_regex = "default-NODELETING"
}

data "alicloud_vswitches" "default" {
vpc_id = data.alicloud_vpcs.default.ids.0
zone_id = data.alicloud_enhanced_nat_available_zones.default.zones.0.zone_id
vpc_id = data.alicloud_vpcs.default.ids.0
zone_id = data.alicloud_zones.default.zones.0.id
}
resource "alicloud_vswitch" "vswitch" {
count = length(data.alicloud_vswitches.default.ids) > 0 ? 0 : 1
vpc_id = data.alicloud_vpcs.default.ids.0
cidr_block = cidrsubnet(data.alicloud_vpcs.default.vpcs[0].cidr_block, 8, 8)
zone_id = data.alicloud_zones.default.zones.0.id
vswitch_name = var.name
}
locals {
vswitch_id = length(data.alicloud_vswitches.default.ids) > 0 ? data.alicloud_vswitches.default.ids[0] : concat(alicloud_vswitch.vswitch.*.id, [""])[0]
}

resource "alicloud_nat_gateway" "default" {
vpc_id = data.alicloud_vpcs.default.ids.0
nat_gateway_name = var.name
payment_type = "PayAsYouGo"
vswitch_id = data.alicloud_vswitches.default.ids[0]
nat_type = "Enhanced"
vpc_id = data.alicloud_vpcs.default.ids.0
network_type = "internet"
nat_gateway_name = "${var.name}"
vswitch_id = local.vswitch_id
nat_type = "Enhanced"
internet_charge_type = "PayByLcu"
}

resource "alicloud_eip_address" "default" {
Expand Down