Skip to content

Commit

Permalink
[DCS] improve import in opentelekomcloud_dcs_instance_v1 and refact…
Browse files Browse the repository at this point in the history
…oring `resource/opentelekomcloud_dcs_*` (#2005)

[DCS] improve import in `opentelekomcloud_dcs_instance_v1` and refactoring `resource/opentelekomcloud_dcs_*`

Summary of the Pull Request
PR Checklist

 Refers to: #1992
 Tests added/passed.
 Documentation updated.
 Schema updated.
 Release notes added.

Acceptance Steps Performed
=== RUN   TestAccDcsAZV1DataSource_basic
=== PAUSE TestAccDcsAZV1DataSource_basic
=== CONT  TestAccDcsAZV1DataSource_basic
--- PASS: TestAccDcsAZV1DataSource_basic (41.02s)
PASS


Process finished with the exit code 0

=== RUN   TestAccDcsMaintainWindowV1DataSource_basic
=== PAUSE TestAccDcsMaintainWindowV1DataSource_basic
=== CONT  TestAccDcsMaintainWindowV1DataSource_basic
--- PASS: TestAccDcsMaintainWindowV1DataSource_basic (38.57s)
PASS


Process finished with the exit code 0

=== RUN   TestAccDcsProductV1DataSource_basic
=== PAUSE TestAccDcsProductV1DataSource_basic
=== CONT  TestAccDcsProductV1DataSource_basic
--- PASS: TestAccDcsProductV1DataSource_basic (43.60s)
PASS


Process finished with the exit code 0

=== RUN   TestAccDcsInstancesV1_basic
=== PAUSE TestAccDcsInstancesV1_basic
=== CONT  TestAccDcsInstancesV1_basic
--- PASS: TestAccDcsInstancesV1_basic (165.16s)
=== RUN   TestAccDcsInstancesV1_basicSingleInstance
=== PAUSE TestAccDcsInstancesV1_basicSingleInstance
=== CONT  TestAccDcsInstancesV1_basicSingleInstance
--- PASS: TestAccDcsInstancesV1_basicSingleInstance (120.50s)
=== RUN   TestAccDcsInstancesV1_basicEngineV3Instance
=== PAUSE TestAccDcsInstancesV1_basicEngineV3Instance
=== CONT  TestAccDcsInstancesV1_basicEngineV3Instance
=== RUN   TestAccASV1Configuration_invalidSecurityGroup
=== PAUSE TestAccASV1Configuration_invalidSecurityGroup
=== CONT  TestAccASV1Configuration_invalidSecurityGroup
--- PASS: TestAccASV1Configuration_invalidSecurityGroup (53.49s)
=== RUN   TestAccASV1Configuration_invalidEngineVersion
=== PAUSE TestAccASV1Configuration_invalidEngineVersion

=== CONT  TestAccASV1Configuration_invalidEngineVersion
--- PASS: TestAccASV1Configuration_invalidEngineVersion (44.40s)
=== RUN   TestAccASV1Configuration_WhitelistValidation
=== PAUSE TestAccASV1Configuration_WhitelistValidation
=== CONT  TestAccASV1Configuration_WhitelistValidation
--- PASS: TestAccASV1Configuration_WhitelistValidation (45.35s)
=== RUN   TestAccDcsInstancesV1_Whitelist
=== PAUSE TestAccDcsInstancesV1_Whitelist
=== CONT  TestAccDcsInstancesV1_Whitelist

--- PASS: TestAccDcsInstancesV1_Whitelist (252.90s)
=== RUN   TestAccDCSInstanceV1_importBasic
--- PASS: TestAccDCSInstanceV1_importBasic (123.82s)
--- PASS: TestAccDcsInstancesV1_basicEngineV3Instance (439.09s)
PASS


Process finished with the exit code 0

Reviewed-by: Aloento
Reviewed-by: Artem Lifshits
  • Loading branch information
anton-sidelnikov committed Nov 25, 2022
1 parent 920f38b commit d34610a
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 68 deletions.
4 changes: 0 additions & 4 deletions docs/resources/dcs_instance_v1.md
Expand Up @@ -106,10 +106,6 @@ The following arguments are supported:
For a DCS Redis instance in cluster mode, the cache capacity can be `64`, `128`, `256`, `512` GB.
Changing this creates a new instance.

* `access_user` - (Optional) Username used for accessing a DCS instance after password
authentication. A username starts with a letter, consists of `1` to `64` characters,
and supports only letters, digits, and hyphens (-). Changing this creates a new instance.

* `password` - (Required) Indicates the password of an instance. An instance password
must meet the following complexity requirements: Must be 8 to 32 characters long.
Must contain at least 3 of the following character types: lowercase letters, uppercase
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -14,7 +14,7 @@ require (
github.com/jinzhu/copier v0.3.5
github.com/keybase/go-crypto v0.0.0-20200123153347-de78d2cb44f4
github.com/mitchellh/go-homedir v1.1.0
github.com/opentelekomcloud/gophertelekomcloud v0.5.25-0.20221116152509-1aaf58059b0c
github.com/opentelekomcloud/gophertelekomcloud v0.5.25
github.com/unknwon/com v1.0.1
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -209,6 +209,8 @@ github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/opentelekomcloud/gophertelekomcloud v0.5.25-0.20221116152509-1aaf58059b0c h1:qk3TTKMA3+GZ9kPwKEyOAWd9VPMRORpfo1gu5p35hE8=
github.com/opentelekomcloud/gophertelekomcloud v0.5.25-0.20221116152509-1aaf58059b0c/go.mod h1:/QD0ZIzm3zMdE0iBSAP3+Z9eCViU2PgnQqp4KGrpR/M=
github.com/opentelekomcloud/gophertelekomcloud v0.5.25 h1:U5ERa9/AFSE/JTPNx5B8kemtIWPjQcM8BAowFyV89nM=
github.com/opentelekomcloud/gophertelekomcloud v0.5.25/go.mod h1:/QD0ZIzm3zMdE0iBSAP3+Z9eCViU2PgnQqp4KGrpR/M=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/dcs/v1/instances"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/dcs/v1/lifecycle"

"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/env"
Expand All @@ -18,7 +18,7 @@ import (
const resourceInstanceName = "opentelekomcloud_dcs_instance_v1.instance_1"

func TestAccDcsInstancesV1_basic(t *testing.T) {
var instance instances.Instance
var instance lifecycle.Instance
var instanceName = fmt.Sprintf("dcs_instance_%s", acctest.RandString(5))

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -47,7 +47,7 @@ func TestAccDcsInstancesV1_basic(t *testing.T) {
}

func TestAccDcsInstancesV1_basicSingleInstance(t *testing.T) {
var instance instances.Instance
var instance lifecycle.Instance
var instanceName = fmt.Sprintf("dcs_instance_%s", acctest.RandString(5))

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -69,7 +69,7 @@ func TestAccDcsInstancesV1_basicSingleInstance(t *testing.T) {
}

func TestAccDcsInstancesV1_basicEngineV3Instance(t *testing.T) {
var instance instances.Instance
var instance lifecycle.Instance
var instanceName = fmt.Sprintf("dcs_instance_%s", acctest.RandString(5))

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestAccASV1Configuration_WhitelistValidation(t *testing.T) {
}

func TestAccDcsInstancesV1_Whitelist(t *testing.T) {
var instance instances.Instance
var instance lifecycle.Instance
var instanceName = fmt.Sprintf("dcs_instance_%s", acctest.RandString(5))

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -186,6 +186,29 @@ func TestAccDcsInstancesV1_Whitelist(t *testing.T) {
})
}

func TestAccDCSInstanceV1_importBasic(t *testing.T) {
var instanceName = fmt.Sprintf("dcs_instance_%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { common.TestAccPreCheck(t) },
ProviderFactories: common.TestAccProviderFactories,
CheckDestroy: testAccCheckDcsV1InstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccDcsV1InstanceBasic(instanceName),
},

{
ResourceName: resourceInstanceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"password", "configuration",
},
},
},
})
}

func testAccCheckDcsV1InstanceDestroy(s *terraform.State) error {
config := common.TestAccProvider.Meta().(*cfg.Config)
client, err := config.DcsV1Client(env.OS_REGION_NAME)
Expand All @@ -198,15 +221,15 @@ func testAccCheckDcsV1InstanceDestroy(s *terraform.State) error {
continue
}

_, err := instances.Get(client, rs.Primary.ID).Extract()
_, err := lifecycle.Get(client, rs.Primary.ID)
if err == nil {
return fmt.Errorf("DCS instance still exists")
}
}
return nil
}

func testAccCheckDcsV1InstanceExists(n string, instance instances.Instance) resource.TestCheckFunc {
func testAccCheckDcsV1InstanceExists(n string, instance lifecycle.Instance) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
Expand All @@ -223,7 +246,7 @@ func testAccCheckDcsV1InstanceExists(n string, instance instances.Instance) reso
return fmt.Errorf("error creating DCSv1 client: %w", err)
}

v, err := instances.Get(dcsClient, rs.Primary.ID).Extract()
v, err := lifecycle.Get(dcsClient, rs.Primary.ID)
if err != nil {
return fmt.Errorf("error getting instance (%s): %w", rs.Primary.ID, err)
}
Expand Down
Expand Up @@ -7,8 +7,7 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/dcs/v1/availablezones"

"github.com/opentelekomcloud/gophertelekomcloud/openstack/dcs/v1/others"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/fmterr"
)
Expand Down Expand Up @@ -44,13 +43,13 @@ func dataSourceDcsAZV1Read(_ context.Context, d *schema.ResourceData, meta inter
return fmterr.Errorf("error creating dcs key client: %s", err)
}

v, err := availablezones.Get(DcsV1Client).Extract()
v, err := others.ListAvailableZones(DcsV1Client)
if err != nil {
return diag.FromErr(err)
}

log.Printf("[DEBUG] Dcs az : %+v", v)
var filteredAZs []availablezones.AvailableZone
var filteredAZs []others.AvailableZone
if v.RegionID == config.GetRegion(d) {
AZs := v.AvailableZones
for _, newAZ := range AZs {
Expand Down
Expand Up @@ -8,8 +8,7 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/dcs/v1/maintainwindows"

"github.com/opentelekomcloud/gophertelekomcloud/openstack/dcs/v1/others"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/fmterr"
)
Expand Down Expand Up @@ -50,14 +49,13 @@ func dataSourceDcsMaintainWindowV1Read(_ context.Context, d *schema.ResourceData
return fmterr.Errorf("error creating dcs key client: %s", err)
}

v, err := maintainwindows.Get(DcsV1Client).Extract()
v, err := others.ListMaintenanceWindows(DcsV1Client)
if err != nil {
return diag.FromErr(err)
}

maintainWindows := v.MaintainWindows
var filteredMVs []maintainwindows.MaintainWindow
for _, mv := range maintainWindows {
var filteredMVs []others.MaintainWindow
for _, mv := range v {
seq := d.Get("seq").(int)
if seq != 0 && mv.ID != seq {
continue
Expand Down
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/dcs/v1/products"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/dcs/v1/others"

"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/fmterr"
Expand All @@ -33,13 +33,13 @@ func dataSourceDcsProductV1Read(_ context.Context, d *schema.ResourceData, meta
return fmterr.Errorf("error get dcs product client: %s", err)
}

v, err := products.Get(DcsV1Client).Extract()
v, err := others.GetProducts(DcsV1Client)
if err != nil {
return diag.FromErr(err)
}
log.Printf("[DEBUG] Dcs get products : %+v", v)
var FilteredPd []products.Product
for _, pd := range v.Products {
var FilteredPd []others.Product
for _, pd := range v {
specCode := d.Get("spec_code").(string)
if specCode != "" && pd.SpecCode != specCode {
continue
Expand Down

0 comments on commit d34610a

Please sign in to comment.