diff --git a/docs/resources/sdrs_protectiongroup_v1.md b/docs/resources/sdrs_protectiongroup_v1.md index 7ee06607..a29382c4 100644 --- a/docs/resources/sdrs_protectiongroup_v1.md +++ b/docs/resources/sdrs_protectiongroup_v1.md @@ -36,6 +36,9 @@ resource "flexibleengine_sdrs_protectiongroup_v1" "group_1" { The following arguments are supported: +* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource. + If omitted, the provider-level region will be used. Changing this parameter will create a new resource. + * `name` - (Required, String) The name of a protection group. * `description` - (Optional, String, ForceNew) The description of a protection group. Changing this creates a new group. diff --git a/docs/resources/sdrs_replication_pair_v1.md b/docs/resources/sdrs_replication_pair_v1.md index 455bdb93..8845394e 100644 --- a/docs/resources/sdrs_replication_pair_v1.md +++ b/docs/resources/sdrs_replication_pair_v1.md @@ -41,6 +41,9 @@ resource "flexibleengine_sdrs_replication_pair_v1" "replication_1" { The following arguments are supported: +* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource. + If omitted, the provider-level region will be used. Changing this parameter will create a new resource. + * `name` - (Required, String) The name of a replication pair. The name can contain a maximum of 64 bytes. The value can contain only letters (a to z and A to Z), digits (0 to 9), decimal points (.), underscores (_), and hyphens (-). diff --git a/flexibleengine/acceptance/resource_flexibleengine_sdrs_protection_group_v1_test.go b/flexibleengine/acceptance/resource_flexibleengine_sdrs_protection_group_v1_test.go new file mode 100644 index 00000000..9794ff64 --- /dev/null +++ b/flexibleengine/acceptance/resource_flexibleengine_sdrs_protection_group_v1_test.go @@ -0,0 +1,110 @@ +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + "github.com/chnsz/golangsdk/openstack/sdrs/v1/protectiongroups" + + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" +) + +func getProtectionGroupResourceFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) { + region := OS_REGION_NAME + client, err := cfg.SdrsV1Client(region) + if err != nil { + return nil, fmt.Errorf("error creating SDRS Client: %s", err) + } + return protectiongroups.Get(client, state.Primary.ID).Extract() +} + +// Lack of testing for `enable`, will test it in resource replication pair +func TestAccProtectionGroup_basic(t *testing.T) { + var obj interface{} + + name := acceptance.RandomAccResourceName() + rName := "flexibleengine_sdrs_protectiongroup_v1.test" + + rc := acceptance.InitResourceCheck( + rName, + &obj, + getProtectionGroupResourceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testProtectionGroup_basic(name), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(rName, "name", name), + resource.TestCheckResourceAttr(rName, "description", "test description"), + resource.TestCheckResourceAttrPair(rName, "source_availability_zone", "data.flexibleengine_availability_zones.test", "names.0"), + resource.TestCheckResourceAttrPair(rName, "target_availability_zone", "data.flexibleengine_availability_zones.test", "names.1"), + resource.TestCheckResourceAttrPair(rName, "domain_id", "data.flexibleengine_sdrs_domain_v1.test", "id"), + resource.TestCheckResourceAttrPair(rName, "source_vpc_id", "flexibleengine_vpc_v1.test", "id"), + ), + }, + { + Config: testProtectionGroup_basic_update(name), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(rName, "name", fmt.Sprintf("%s_update", name)), + ), + }, + { + ResourceName: rName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testProtectionGroup_base(name string) string { + return fmt.Sprintf(` +%s + +data "flexibleengine_sdrs_domain_v1" "test" {} +data "flexibleengine_availability_zones" "test" {} +`, testVpc(name)) +} + +func testProtectionGroup_basic(name string) string { + return fmt.Sprintf(` +%[1]s + +resource "flexibleengine_sdrs_protectiongroup_v1" "test" { + name = "%[2]s" + source_availability_zone = data.flexibleengine_availability_zones.test.names[0] + target_availability_zone = data.flexibleengine_availability_zones.test.names[1] + domain_id = data.flexibleengine_sdrs_domain_v1.test.id + source_vpc_id = flexibleengine_vpc_v1.test.id + description = "test description" +} +`, testProtectionGroup_base(name), name) +} + +func testProtectionGroup_basic_update(name string) string { + return fmt.Sprintf(` +%[1]s + +resource "flexibleengine_sdrs_protectiongroup_v1" "test" { + name = "%[2]s_update" + source_availability_zone = data.flexibleengine_availability_zones.test.names[0] + target_availability_zone = data.flexibleengine_availability_zones.test.names[1] + domain_id = data.flexibleengine_sdrs_domain_v1.test.id + source_vpc_id = flexibleengine_vpc_v1.test.id + description = "test description" +} +`, testProtectionGroup_base(name), name) +} diff --git a/flexibleengine/acceptance/resource_flexibleengine_sdrs_replication_pair_v1_test.go b/flexibleengine/acceptance/resource_flexibleengine_sdrs_replication_pair_v1_test.go new file mode 100644 index 00000000..2ee7c1de --- /dev/null +++ b/flexibleengine/acceptance/resource_flexibleengine_sdrs_replication_pair_v1_test.go @@ -0,0 +1,129 @@ +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + "github.com/chnsz/golangsdk/openstack/sdrs/v1/replications" + + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" +) + +func getReplicationPairResourceFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) { + region := OS_REGION_NAME + client, err := cfg.SdrsV1Client(region) + if err != nil { + return nil, fmt.Errorf("error creating SDRS Client: %s", err) + } + return replications.Get(client, state.Primary.ID).Extract() +} + +func TestAccReplicationPair_basic(t *testing.T) { + var obj interface{} + + name := acceptance.RandomAccResourceName() + rName := "flexibleengine_sdrs_replication_pair_v1.test" + + rc := acceptance.InitResourceCheck( + rName, + &obj, + getReplicationPairResourceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testReplicationPair_basic(name), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(rName, "name", name), + resource.TestCheckResourceAttr(rName, "description", "test description"), + resource.TestCheckResourceAttr(rName, "delete_target_volume", "true"), + resource.TestCheckResourceAttrPair(rName, "group_id", "flexibleengine_sdrs_protectiongroup_v1.test", "id"), + resource.TestCheckResourceAttrPair(rName, "volume_id", "flexibleengine_blockstorage_volume_v2.test", "id"), + resource.TestCheckResourceAttrSet(rName, "replication_model"), + resource.TestCheckResourceAttrSet(rName, "status"), + resource.TestCheckResourceAttrSet(rName, "target_volume_id"), + ), + }, + { + Config: testReplicationPair_basic_update(name), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(rName, "name", fmt.Sprintf("%s_update", name)), + ), + }, + { + ResourceName: rName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "delete_target_volume", + }, + }, + }, + }) +} + +func testReplicationPair_base(name string) string { + return fmt.Sprintf(` +%[1]s + +data "flexibleengine_availability_zones" "test" {} +data "flexibleengine_sdrs_domain_v1" "test" {} + +resource "flexibleengine_sdrs_protectiongroup_v1" "test" { + name = "%[2]s" + source_availability_zone = data.flexibleengine_availability_zones.test.names[0] + target_availability_zone = data.flexibleengine_availability_zones.test.names[1] + domain_id = data.flexibleengine_sdrs_domain_v1.test.id + source_vpc_id = flexibleengine_vpc_v1.test.id + description = "test description" +} + +resource "flexibleengine_blockstorage_volume_v2" "test" { + name = "%[2]s" + description = "test volume for sdrs replication pair" + availability_zone = data.flexibleengine_availability_zones.test.names[0] + volume_type = "SSD" + size = 100 +} +`, testVpc(name), name) +} + +func testReplicationPair_basic(name string) string { + return fmt.Sprintf(` +%[1]s + +resource "flexibleengine_sdrs_replication_pair_v1" "test" { + name = "%[2]s" + group_id = flexibleengine_sdrs_protectiongroup_v1.test.id + volume_id = flexibleengine_blockstorage_volume_v2.test.id + description = "test description" + delete_target_volume = true +} +`, testReplicationPair_base(name), name) +} + +func testReplicationPair_basic_update(name string) string { + return fmt.Sprintf(` +%[1]s + +resource "flexibleengine_sdrs_replication_pair_v1" "test" { + name = "%[2]s_update" + group_id = flexibleengine_sdrs_protectiongroup_v1.test.id + volume_id = flexibleengine_blockstorage_volume_v2.test.id + description = "test description" + delete_target_volume = true +} +`, testReplicationPair_base(name), name) +} diff --git a/flexibleengine/provider.go b/flexibleengine/provider.go index 5a861c87..4e6a944a 100644 --- a/flexibleengine/provider.go +++ b/flexibleengine/provider.go @@ -43,6 +43,7 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/nat" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/obs" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/rds" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/sdrs" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/sfs" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/smn" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/sms" @@ -528,9 +529,7 @@ func Provider() *schema.Provider { "flexibleengine_dds_instance_v3": resourceDdsInstanceV3(), "flexibleengine_sdrs_drill_v1": resourceSdrsDrillV1(), - "flexibleengine_sdrs_protectiongroup_v1": resourceSdrsProtectiongroupV1(), "flexibleengine_sdrs_protectedinstance_v1": resourceSdrsProtectedInstanceV1(), - "flexibleengine_sdrs_replication_pair_v1": resourceSdrsReplicationPairV1(), "flexibleengine_sdrs_replication_attach_v1": resourceSdrsReplicationAttachV1(), "flexibleengine_vpcep_approval": resourceVPCEndpointApproval(), @@ -649,6 +648,9 @@ func Provider() *schema.Provider { "flexibleengine_rds_database_privilege": rds.ResourceMysqlDatabasePrivilege(), "flexibleengine_rds_sql_audit": rds.ResourceSQLAudit(), + "flexibleengine_sdrs_protectiongroup_v1": sdrs.ResourceProtectionGroup(), + "flexibleengine_sdrs_replication_pair_v1": sdrs.ResourceReplicationPair(), + "flexibleengine_sms_server_template": sms.ResourceServerTemplate(), "flexibleengine_sms_task": sms.ResourceMigrateTask(), "flexibleengine_swr_organization": swr.ResourceSWROrganization(),