Skip to content

Commit

Permalink
[RDS] Use client from ctx in rds_instance_v3 (#1873)
Browse files Browse the repository at this point in the history
[RDS] Use client from ctx in `rds_instance_v3`

Summary of the Pull Request
PR Checklist

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

Acceptance Steps Performed

=== RUN   TestAccRdsInstanceV3RestoreBackup
--- PASS: TestAccRdsInstanceV3RestoreBackup (1116.80s)
=== RUN   TestAccRdsInstanceV3ElasticIP
--- PASS: TestAccRdsInstanceV3ElasticIP (427.52s)
=== RUN   TestAccRdsInstanceV3OptionalParams
--- PASS: TestAccRdsInstanceV3OptionalParams (367.78s)
=== RUN   TestAccRdsInstanceV3Backup
--- PASS: TestAccRdsInstanceV3Backup (369.07s)
=== RUN   TestAccRdsInstanceV3TemplateConfig
--- PASS: TestAccRdsInstanceV3TemplateConfig (483.48s)
=== RUN   TestAccRdsInstanceV3InvalidDBVersion
--- PASS: TestAccRdsInstanceV3InvalidDBVersion (14.13s)
=== RUN   TestAccRdsInstanceV3InvalidFlavor
--- PASS: TestAccRdsInstanceV3InvalidFlavor (14.99s)
=== RUN   TestAccRdsInstanceV3_configurationParameters
--- PASS: TestAccRdsInstanceV3_configurationParameters (379.67s)
FAIL


Process finished with the exit code 0

Reviewed-by: Anton Kachurin <None>
Reviewed-by: Artem Lifshits <None>
Reviewed-by: Aloento <None>
  • Loading branch information
anton-sidelnikov committed Aug 15, 2022
1 parent 07bd99e commit e2ac6c2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Expand Up @@ -44,7 +44,7 @@ func TestAccRdsInstanceV3Basic(t *testing.T) {
{
Config: testAccRdsInstanceV3Update(postfix),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(instanceV3ResourceName, "flavor", "rds.pg.c2.large"),
resource.TestCheckResourceAttr(instanceV3ResourceName, "flavor", "rds.pg.c2.medium"),
resource.TestCheckResourceAttr(instanceV3ResourceName, "volume.0.size", "100"),
resource.TestCheckResourceAttr(instanceV3ResourceName, "tags.muh", "value-update"),
),
Expand Down Expand Up @@ -371,7 +371,7 @@ resource "opentelekomcloud_rds_instance_v3" "instance" {
type = "COMMON"
size = 100
}
flavor = "rds.pg.c2.large"
flavor = "rds.pg.c2.medium"
backup_strategy {
start_time = "08:00-09:00"
keep_days = 1
Expand Down
Expand Up @@ -349,7 +349,9 @@ func resourceRDSAvailabilityZones(d *schema.ResourceData) string {

func resourceRdsInstanceV3Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*cfg.Config)
client, err := config.RdsV3Client(config.GetRegion(d))
client, err := common.ClientFromCtx(ctx, keyClientV3, func() (*golangsdk.ServiceClient, error) {
return config.RdsV3Client(config.GetRegion(d))
})
if err != nil {
return fmterr.Errorf(errCreateClient, err)
}
Expand Down Expand Up @@ -596,11 +598,11 @@ func applyTemplate(d *schema.ResourceData, client *golangsdk.ServiceClient) (boo
return restartRequired, nil
}

func GetRdsInstance(rdsClient *golangsdk.ServiceClient, rdsId string) (*instances.RdsInstanceResponse, error) {
func GetRdsInstance(client *golangsdk.ServiceClient, rdsId string) (*instances.RdsInstanceResponse, error) {
listOpts := instances.ListRdsInstanceOpts{
Id: rdsId,
}
allPages, err := instances.List(rdsClient, listOpts).AllPages()
allPages, err := instances.List(client, listOpts).AllPages()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -713,7 +715,9 @@ func unAssignEipFromInstance(client *golangsdk.ServiceClient, oldPublicIP string

func resourceRdsInstanceV3Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*cfg.Config)
client, err := config.RdsV3Client(config.GetRegion(d))
client, err := common.ClientFromCtx(ctx, keyClientV3, func() (*golangsdk.ServiceClient, error) {
return config.RdsV3Client(config.GetRegion(d))
})
if err != nil {
return fmterr.Errorf(errCreateClient, err)
}
Expand Down Expand Up @@ -1086,9 +1090,11 @@ func resourceRdsInstanceV3Read(ctx context.Context, d *schema.ResourceData, meta
return nil
}

func resourceRdsInstanceV3Delete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func resourceRdsInstanceV3Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*cfg.Config)
client, err := config.RdsV3Client(config.GetRegion(d))
client, err := common.ClientFromCtx(ctx, keyClientV3, func() (*golangsdk.ServiceClient, error) {
return config.RdsV3Client(config.GetRegion(d))
})
if err != nil {
return fmterr.Errorf(errCreateClient, err)
}
Expand Down
@@ -0,0 +1,4 @@
---
enhancements:
- |
**[RDS]** Reduce amount of init client requests in ``resource/opentelekomcloud_rds_instance_v3`` (`#1873 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/1873>`_)

0 comments on commit e2ac6c2

Please sign in to comment.