Skip to content

Commit

Permalink
resource/aws_rds_cluster: Refactor tagging to use keyvaluetags library (
Browse files Browse the repository at this point in the history
#10483)

Output from acceptance testing (testing failures unrelated):

```
--- PASS: TestAccAWSRDSClusterInstance_namePrefix (615.04s)
--- PASS: TestAccAWSRDSClusterInstance_CopyTagsToSnapshot (697.46s)
--- PASS: TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraPostgresql (732.32s)
--- PASS: TestAccAWSRDSClusterInstance_az (732.74s)
--- PASS: TestAccAWSRDSClusterInstance_disappears (736.33s)
--- PASS: TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraMysql1 (752.13s)
--- PASS: TestAccAWSRDSClusterInstance_kmsKey (781.41s)
--- PASS: TestAccAWSRDSClusterInstance_generatedName (784.35s)
--- PASS: TestAccAWSRDSClusterInstance_PerformanceInsightsKmsKeyId_AuroraMysql1 (792.55s)
--- PASS: TestAccAWSRDSClusterInstance_PerformanceInsightsKmsKeyId_AuroraMysql2_DefaultKeyToCustomKey (836.28s)
--- PASS: TestAccAWSRDSClusterInstance_PerformanceInsightsKmsKeyId_AuroraMysql2 (843.00s)
--- PASS: TestAccAWSRDSCluster_missingUserNameCausesError (3.37s)
--- PASS: TestAccAWSRDSCluster_basic (119.62s)
--- PASS: TestAccAWSRDSCluster_AvailabilityZones (120.42s)
--- PASS: TestAccAWSRDSClusterInstance_PerformanceInsightsKmsKeyId_AuroraMysql1_DefaultKeyToCustomKey (856.65s)
--- PASS: TestAccAWSRDSClusterInstance_PubliclyAccessible (858.62s)
--- PASS: TestAccAWSRDSClusterInstance_PerformanceInsightsEnabled_AuroraMysql2 (863.08s)
--- PASS: TestAccAWSRDSCluster_BacktrackWindow (144.43s)
--- PASS: TestAccAWSRDSCluster_ClusterIdentifierPrefix (129.29s)
--- PASS: TestAccAWSRDSCluster_DbSubnetGroupName (113.02s)
--- PASS: TestAccAWSRDSClusterInstance_MonitoringRoleArn_RemovedToEnabled (910.20s)
--- PASS: TestAccAWSRDSCluster_generatedName (129.29s)
--- PASS: TestAccAWSRDSCluster_Tags (109.66s)
--- PASS: TestAccAWSRDSCluster_takeFinalSnapshot (140.03s)
--- PASS: TestAccAWSRDSCluster_encrypted (119.31s)
--- PASS: TestAccAWSRDSCluster_kmsKey (138.51s)
--- PASS: TestAccAWSRDSClusterInstance_MonitoringRoleArn_EnabledToRemoved (1001.55s)
--- PASS: TestAccAWSRDSClusterInstance_MonitoringRoleArn_EnabledToDisabled (1014.31s)
--- PASS: TestAccAWSRDSCluster_updateIamRoles (166.13s)
--- PASS: TestAccAWSRDSCluster_iamAuth (129.62s)
--- PASS: TestAccAWSRDSCluster_backupsUpdate (144.39s)
--- PASS: TestAccAWSRDSCluster_copyTagsToSnapshot (180.30s)
--- PASS: TestAccAWSRDSCluster_DeletionProtection (134.65s)
--- PASS: TestAccAWSRDSCluster_EngineMode_Global (130.18s)
--- PASS: TestAccAWSRDSCluster_EngineMode_Multimaster (123.49s)
--- PASS: TestAccAWSRDSCluster_EngineVersion (131.61s)
--- PASS: TestAccAWSRDSCluster_EngineMode_ParallelQuery (149.45s)
--- PASS: TestAccAWSRDSCluster_EnabledCloudwatchLogsExports (316.41s)
--- SKIP: TestAccAWSRDSCluster_SnapshotIdentifier_EngineMode_Serverless (0.00s)
--- FAIL: TestAccAWSRDSCluster_EngineMode (269.83s)
--- PASS: TestAccAWSRDSClusterEndpoint_basic (1199.79s)
--- PASS: TestAccAWSRDSCluster_Port (245.86s)
--- PASS: TestAccAWSRDSClusterInstance_MonitoringInterval (1330.13s)
--- PASS: TestAccAWSRDSCluster_ScalingConfiguration (329.07s)
--- PASS: TestAccAWSRDSClusterInstance_basic (1394.46s)
--- PASS: TestAccAWSRDSCluster_SnapshotIdentifier (327.15s)
--- PASS: TestAccAWSRDSClusterInstance_PerformanceInsightsKmsKeyId_AuroraPostgresql_DefaultKeyToCustomKey (739.93s)
--- PASS: TestAccAWSRDSClusterInstance_PerformanceInsightsKmsKeyId_AuroraPostgresql (827.55s)
--- PASS: TestAccAWSRDSCluster_SnapshotIdentifier_EngineMode_Provisioned (347.17s)
--- PASS: TestAccAWSRDSCluster_SnapshotIdentifier_DeletionProtection (393.05s)
--- PASS: TestAccAWSRDSCluster_SnapshotIdentifier_EngineMode_ParallelQuery (407.94s)
--- PASS: TestAccAWSRDSCluster_SnapshotIdentifier_MasterPassword (337.06s)
--- PASS: TestAccAWSRDSCluster_SnapshotIdentifier_EngineVersion_Different (387.04s)
--- PASS: TestAccAWSRDSCluster_SnapshotIdentifier_EngineVersion_Equal (407.20s)
--- PASS: TestAccAWSRDSCluster_SnapshotIdentifier_MasterUsername (327.23s)
--- FAIL: TestAccAWSRDSCluster_SnapshotIdentifier_PreferredBackupWindow (303.76s)
--- PASS: TestAccAWSRDSCluster_SnapshotIdentifier_PreferredMaintenanceWindow (326.91s)
--- PASS: TestAccAWSRDSCluster_SnapshotIdentifier_Tags (347.21s)
--- PASS: TestAccAWSRDSCluster_SnapshotIdentifier_VpcSecurityGroupIds (328.19s)
--- PASS: TestAccAWSRDSCluster_SnapshotIdentifier_EncryptedRestore (317.03s)
--- PASS: TestAccAWSRDSCluster_SnapshotIdentifier_VpcSecurityGroupIds_Tags (348.14s)
--- PASS: TestAccAWSRDSCluster_EngineVersionWithPrimaryInstance (1094.88s)
--- FAIL: TestAccAWSRDSCluster_s3Restore (1491.68s)
--- PASS: TestAccAWSRDSCluster_EncryptedCrossRegionReplication (1474.46s)
--- FAIL: TestAccAWSRDSCluster_GlobalClusterIdentifier_Remove (2984.93s)
--- FAIL: TestAccAWSRDSCluster_GlobalClusterIdentifier (3146.46s)
--- FAIL: TestAccAWSRDSCluster_GlobalClusterIdentifier_Add (3152.06s)
--- FAIL: TestAccAWSRDSCluster_GlobalClusterIdentifier_Update (3219.22s)
```
  • Loading branch information
DrFaust92 authored and bflad committed Nov 4, 2019
1 parent c786323 commit af329f3
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func resourceAwsRDSCluster() *schema.Resource {
Expand Down Expand Up @@ -419,7 +420,7 @@ func resourceAwsRdsClusterImport(

func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).rdsconn
tags := tagsFromMapRDS(d.Get("tags").(map[string]interface{}))
tags := keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().RdsTags()

// Some API calls (e.g. RestoreDBClusterFromSnapshot do not support all
// parameters to correctly apply all settings in one pass. For missing
Expand Down Expand Up @@ -1032,9 +1033,12 @@ func resourceAwsRDSClusterRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error setting vpc_security_group_ids: %s", err)
}

// Fetch and save tags
if err := saveTagsRDS(conn, d, aws.StringValue(dbc.DBClusterArn)); err != nil {
log.Printf("[WARN] Failed to save tags for RDS Cluster (%s): %s", aws.StringValue(dbc.DBClusterIdentifier), err)
tags, err := keyvaluetags.RdsListTags(conn, aws.StringValue(dbc.DBClusterArn))
if err != nil {
return fmt.Errorf("error listing tags for RDS Cluster (%s): %s", aws.StringValue(dbc.DBClusterArn), err)
}
if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}

// Fetch and save Global Cluster if engine mode global
Expand Down Expand Up @@ -1223,8 +1227,10 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
}

if d.HasChange("tags") {
if err := setTagsRDS(conn, d, d.Get("arn").(string)); err != nil {
return err
o, n := d.GetChange("tags")

if err := keyvaluetags.RdsUpdateTags(conn, d.Get("arn").(string), o, n); err != nil {
return fmt.Errorf("error updating tags: %s", err)
} else {
d.SetPartial("tags")
}
Expand Down

0 comments on commit af329f3

Please sign in to comment.