Skip to content

Commit

Permalink
testcase: Adds a new test case for resource alicloud_cen_transit_rout…
Browse files Browse the repository at this point in the history
…er_vpc_attachment
  • Loading branch information
thisnihonglei committed Jan 24, 2022
1 parent d557878 commit 92fecb1
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 6 deletions.
138 changes: 134 additions & 4 deletions alicloud/resource_alicloud_cen_transit_router_vpc_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ func TestAccAlicloudCenTransitRouterVpcAttachment_basic(t *testing.T) {
"zone_mappings": []map[string]interface{}{
{
"vswitch_id": "${local.vswitch_id_master}",
"zone_id": "${alicloud_vswitch.default_master.zone_id}",
"zone_id": "${data.alicloud_zones.default.zones.0.id}",
},
{
"vswitch_id": "${local.vswitch_id}",
"zone_id": "${alicloud_vswitch.default_slave.zone_id}",
"zone_id": "${data.alicloud_zones.default.zones.1.id}",
},
},
}),
Expand All @@ -68,7 +68,7 @@ func TestAccAlicloudCenTransitRouterVpcAttachment_basic(t *testing.T) {
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"auto_create_vpc_route", "dry_run", "route_table_association_enabled", "route_table_propagation_enabled", "transit_router_id"},
ImportStateVerifyIgnore: []string{"dry_run", "route_table_association_enabled", "route_table_propagation_enabled", "transit_router_id"},
},
{
Config: testAccConfig(map[string]interface{}{
Expand Down Expand Up @@ -114,8 +114,81 @@ func TestAccAlicloudCenTransitRouterVpcAttachment_basic(t *testing.T) {
})
}

func TestAccAlicloudCenTransitRouterVpcAttachment_basic1(t *testing.T) {
var v map[string]interface{}
resourceId := "alicloud_cen_transit_router_vpc_attachment.default"
ra := resourceAttrInit(resourceId, AlicloudCenTransitRouterVpcAttachmentMap)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &CbnService{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeCenTransitRouterVpcAttachment")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(1000000, 9999999)
name := fmt.Sprintf("tf-testAccCenTransitRouterVpcAttachment%d", rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudCenTransitRouterVpcAttachmentBasicDependence1)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithRegions(t, true, connectivity.CenTransitRouterVpcAttachmentSupportRegions)
},

IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: rac.checkResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"cen_id": "${alicloud_cen_instance.default.id}",
"transit_router_id": "${alicloud_cen_transit_router.default.transit_router_id}",
"transit_router_attachment_name": name,
"transit_router_attachment_description": "tf-test",
"vpc_id": "${data.alicloud_vpcs.default.ids.0}",
"zone_mappings": []map[string]interface{}{
{
"vswitch_id": "${local.vswitch_id_master}",
"zone_id": "${data.alicloud_zones.default.zones.0.id}",
},
{
"vswitch_id": "${local.vswitch_id}",
"zone_id": "${data.alicloud_zones.default.zones.1.id}",
},
},
"dry_run": "false",
"resource_type": "VPC",
"route_table_association_enabled": "false",
"route_table_propagation_enabled": "false",
"vpc_owner_id": "${data.alicloud_account.default.id}",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"cen_id": CHECKSET,
"transit_router_id": CHECKSET,
"transit_router_attachment_name": name,
"transit_router_attachment_description": "tf-test",
"vpc_id": CHECKSET,
"zone_mappings.0.vswitch_id": CHECKSET,
"zone_mappings.0.zone_id": CHECKSET,
"zone_mappings.1.vswitch_id": CHECKSET,
"zone_mappings.1.zone_id": CHECKSET,
"dry_run": "false",
"resource_type": "VPC",
"route_table_association_enabled": "false",
"route_table_propagation_enabled": "false",
"vpc_owner_id": CHECKSET,
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"dry_run", "route_table_association_enabled", "route_table_propagation_enabled", "transit_router_id"},
},
},
})
}

var AlicloudCenTransitRouterVpcAttachmentMap = map[string]string{
"auto_create_vpc_route": NOSET,
"cen_id": CHECKSET,
"dry_run": NOSET,
"resource_type": "VPC",
Expand Down Expand Up @@ -185,3 +258,60 @@ cen_id= alicloud_cen_instance.default.id
}
`, name)
}

func AlicloudCenTransitRouterVpcAttachmentBasicDependence1(name string) string {
return fmt.Sprintf(`
variable "name" {
default = "%s"
}
data "alicloud_vpcs" "default" {
name_regex = "default-NODELETING"
}
data "alicloud_zones" "default" {
available_resource_creation= "VSwitch"
}
data "alicloud_vswitches" "default" {
vpc_id = data.alicloud_vpcs.default.ids.0
zone_id = data.alicloud_zones.default.zones.0.id
}
data "alicloud_vswitches" "default_master" {
vpc_id = data.alicloud_vpcs.default.ids.0
zone_id = data.alicloud_zones.default.zones.1.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
}
resource "alicloud_vswitch" "vswitch_master" {
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.1.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]
vswitch_id_master = length(data.alicloud_vswitches.default_master.ids) > 0 ? data.alicloud_vswitches.default_master.ids[0] : concat(alicloud_vswitch.vswitch_master.*.id, [""])[0]
}
resource "alicloud_cen_instance" "default" {
cen_instance_name = var.name
protection_level = "REDUCED"
}
resource "alicloud_cen_transit_router" "default" {
cen_id= alicloud_cen_instance.default.id
}
data "alicloud_account" "default" {}
`, name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ resource "alicloud_cen_transit_router_vpc_attachment" "default" {

The following arguments are supported:

* `auto_create_vpc_route` - (Optional) Whether to create vpc route automatically. The system default value is `true`.
* `dry_run` - (Optional) The dry run.
* `cen_id` - (Optional, ForceNew) The ID of the CEN.
* `vpc_id` - (Required, ForceNew) The ID of the VPC.
Expand All @@ -88,7 +87,7 @@ The following arguments are supported:
* `route_table_association_enabled` - (Optional) Whether to enabled route table association. The system default value is `true`.
* `route_table_propagation_enabled` - (Optional) Whether to enabled route table propagation. The system default value is `true`.
* `vpc_owner_id` - (Optional,ForceNew) The owner id of vpc.
* `zone_mapping` - (Required, ForceNew) The list of zone mapping of the VPC.
* `zone_mappings` - (Required, ForceNew) The list of zone mapping of the VPC.

-> **NOTE:** The Zone of CEN has MasterZone and SlaveZone, first zone_id of zone_mapping need be MasterZone. We have a API to describeZones[API](https://help.aliyun.com/document_detail/261356.html)

Expand Down

0 comments on commit 92fecb1

Please sign in to comment.