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

resource/alicloud_vswitch: Upgrades vswitch including deprecating name and availability_zone, adding vswitch_name and zone_id, using new sdk #3342

Merged
merged 1 commit into from
Mar 16, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
333 changes: 191 additions & 142 deletions alicloud/data_source_alicloud_vswitches.go

Large diffs are not rendered by default.

82 changes: 51 additions & 31 deletions alicloud/data_source_alicloud_vswitches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ func TestAccAlicloudVSwitchesDataSourceBasic(t *testing.T) {
rand := acctest.RandInt()
nameRegexConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
}),
fakeConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}_fake"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}_fake"`,
}),
}

Expand All @@ -28,60 +28,70 @@ func TestAccAlicloudVSwitchesDataSourceBasic(t *testing.T) {
"ids": `[ "${alicloud_vswitch.default.id}_fake" ]`,
}),
}
statusConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"ids": `[ "${alicloud_vswitch.default.id}" ]`,
"status": `"Available"`,
}),
fakeConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"ids": `[ "${alicloud_vswitch.default.id}_fake" ]`,
"status": `"Pending"`,
}),
}

cidrBlockConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
"cidr_block": `"172.16.0.0/24"`,
}),
fakeConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
"cidr_block": `"172.16.0.0/23"`,
}),
}
idDefaultConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
"is_default": `"false"`,
}),
fakeConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
"is_default": `"true"`,
}),
}

vpcIdConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
"vpc_id": `"${alicloud_vpc.default.id}"`,
}),
fakeConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
"vpc_id": `"${alicloud_vpc.default.id}_fake"`,
}),
}

zoneIdConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
"zone_id": `"${data.alicloud_zones.default.zones.0.id}"`,
}),
fakeConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
"zone_id": `"${data.alicloud_zones.default.zones.0.id}_fake"`,
}),
}

tagsConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
"tags": `{
Created = "TF"
For = "acceptance test"
}`,
}),
fakeConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
"tags": `{
Created = "TF-fake"
For = "acceptance test"
Expand All @@ -91,37 +101,39 @@ func TestAccAlicloudVSwitchesDataSourceBasic(t *testing.T) {

resourceGroupIdConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
// The resource route tables do not support resource_group_id, so it was set empty.
"resource_group_id": `""`,
}),
fakeConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
"resource_group_id": fmt.Sprintf(`"%s_fake"`, os.Getenv("ALICLOUD_RESOURCE_GROUP_ID")),
}),
}
allConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
"ids": `[ "${alicloud_vswitch.default.id}" ]`,
"cidr_block": `"172.16.0.0/24"`,
"is_default": `"false"`,
"vpc_id": `"${alicloud_vpc.default.id}"`,
"zone_id": `"${data.alicloud_zones.default.zones.0.id}"`,
"resource_group_id": `""`,
"status": `"Available"`,
}),
fakeConfig: testAccCheckAlicloudVSwitchesDataSourceConfig(rand, map[string]string{
"name_regex": `"${alicloud_vswitch.default.name}"`,
"name_regex": `"${alicloud_vswitch.default.vswitch_name}"`,
"ids": `[ "${alicloud_vswitch.default.id}" ]`,
"cidr_block": `"172.16.0.0/24"`,
"is_default": `"false"`,
"vpc_id": `"${alicloud_vpc.default.id}"`,
"zone_id": `"${data.alicloud_zones.default.zones.0.id}_fake"`,
"resource_group_id": `""`,
"status": `"Pending"`,
}),
}

vswitchesCheckInfo.dataSourceTestCheck(t, rand, nameRegexConf, idsConf, cidrBlockConf, idDefaultConf, vpcIdConf, zoneIdConf, tagsConf, resourceGroupIdConf, allConf)
vswitchesCheckInfo.dataSourceTestCheck(t, rand, nameRegexConf, idsConf, statusConf, cidrBlockConf, idDefaultConf, vpcIdConf, zoneIdConf, tagsConf, resourceGroupIdConf, allConf)

}

Expand All @@ -139,11 +151,11 @@ data "alicloud_zones" "default" {}
resource "alicloud_vpc" "default" {
cidr_block = "172.16.0.0/16"
name = "${var.name}"
vpc_name = "${var.name}"
}
resource "alicloud_vswitch" "default" {
name = "${var.name}"
vswitch_name = "${var.name}"
cidr_block = "172.16.0.0/24"
vpc_id = "${alicloud_vpc.default.id}"
availability_zone = "${data.alicloud_zones.default.zones.0.id}"
Expand All @@ -161,18 +173,26 @@ data "alicloud_vswitches" "default" {

var existVSwitchesMapFunc = func(rand int) map[string]string {
return map[string]string{
"ids.#": "1",
"names.#": "1",
"vswitches.#": "1",
"vswitches.0.id": CHECKSET,
"vswitches.0.vpc_id": CHECKSET,
"vswitches.0.zone_id": CHECKSET,
"vswitches.0.name": fmt.Sprintf("tf-testAccVSwitchDatasource%d", rand),
"vswitches.0.instance_ids.#": "0",
"vswitches.0.cidr_block": "172.16.0.0/24",
"vswitches.0.description": "",
"vswitches.0.is_default": "false",
"vswitches.0.creation_time": CHECKSET,
"ids.#": "1",
"names.#": "1",
"vswitches.#": "1",
"vswitches.0.id": CHECKSET,
"vswitches.0.vswitch_id": CHECKSET,
"vswitches.0.vpc_id": CHECKSET,
"vswitches.0.zone_id": CHECKSET,
"vswitches.0.name": fmt.Sprintf("tf-testAccVSwitchDatasource%d", rand),
"vswitches.0.vswitch_name": fmt.Sprintf("tf-testAccVSwitchDatasource%d", rand),
"vswitches.0.cidr_block": "172.16.0.0/24",
"vswitches.0.description": "",
"vswitches.0.is_default": "false",
"vswitches.0.creation_time": CHECKSET,
"vswitches.0.tags.%": "2",
"vswitches.0.tags.Created": "TF",
"vswitches.0.tags.For": "acceptance test",
"vswitches.0.status": "Available",
"vswitches.0.route_table_id": CHECKSET,
"vswitches.0.resource_group_id": CHECKSET,
"vswitches.0.available_ip_address_count": CHECKSET,
}
}

Expand Down
6 changes: 3 additions & 3 deletions alicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func Provider() terraform.ResourceProvider {
"alicloud_network_interfaces": dataSourceAlicloudNetworkInterfaces(),
"alicloud_snapshots": dataSourceAlicloudSnapshots(),
"alicloud_vpcs": dataSourceAlicloudVpcs(),
"alicloud_vswitches": dataSourceAlicloudVSwitches(),
"alicloud_vswitches": dataSourceAlicloudVswitches(),
"alicloud_eips": dataSourceAlicloudEips(),
"alicloud_key_pairs": dataSourceAlicloudKeyPairs(),
"alicloud_kms_keys": dataSourceAlicloudKmsKeys(),
Expand Down Expand Up @@ -444,8 +444,8 @@ func Provider() terraform.ResourceProvider {
"alicloud_nas_access_group": resourceAlicloudNasAccessGroup(),
"alicloud_nas_access_rule": resourceAlicloudNasAccessRule(),
// "alicloud_subnet" aims to match aws usage habit.
"alicloud_subnet": resourceAliyunSubnet(),
"alicloud_vswitch": resourceAliyunSubnet(),
"alicloud_subnet": resourceAlicloudVswitch(),
"alicloud_vswitch": resourceAlicloudVswitch(),
"alicloud_route_entry": resourceAliyunRouteEntry(),
"alicloud_route_table": resourceAliyunRouteTable(),
"alicloud_route_table_attachment": resourceAliyunRouteTableAttachment(),
Expand Down
2 changes: 1 addition & 1 deletion alicloud/resource_alicloud_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func testSweepVpcs(region string) error {
runtime.SetAutoretry(true)
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2016-04-28"), StringPointer("AK"), nil, request, &runtime)
if err != nil {
log.Printf("[ERROR] Failed to retrieve resoure manager handshake in service list: %s", err)
log.Printf("[ERROR] Failed to retrieve VPC in service list: %s", err)
return nil
}
resp, err := jsonpath.Get("$.Vpcs.Vpc", response)
Expand Down
Loading