Skip to content

Commit

Permalink
resource/aws_db_instance: Prevent double apply for snapshot_identifie…
Browse files Browse the repository at this point in the history
…r with multiple other arguments

* backup_retention_period
* backup_window
* iam_database_authentication_enabled
* maintenance_window
* monitoring_interval
* monitoring_role_arn
* parameter_group_name

Previously:

```
--- FAIL: TestAccAWSDBInstance_SnapshotIdentifier_BackupRetentionPeriod (1154.50s)
	testing.go:527: Step 0 error: Check failed: Check 4/4 error: aws_db_instance.test: Attribute 'backup_retention_period' expected "1", got "0"
--- FAIL: TestAccAWSDBInstance_SnapshotIdentifier_BackupWindow (1195.82s)
	testing.go:527: Step 0 error: Check failed: Check 4/4 error: aws_db_instance.test: Attribute 'backup_window' expected "00:00-08:00", got "06:13-06:43"
--- FAIL: TestAccAWSDBInstance_SnapshotIdentifier_IamDatabaseAuthenticationEnabled (1113.22s)
	testing.go:527: Step 0 error: Check failed: Check 4/4 error: aws_db_instance.test: Attribute 'iam_database_authentication_enabled' expected "true", got "false"
--- FAIL: TestAccAWSDBInstance_SnapshotIdentifier_MaintenanceWindow (1259.26s)
	testing.go:527: Step 0 error: Check failed: Check 4/4 error: aws_db_instance.test: Attribute 'maintenance_window' expected "Sun:01:00-Sun:01:30", got "wed:10:33-wed:11:03"
--- FAIL: TestAccAWSDBInstance_SnapshotIdentifier_Monitoring (1214.60s)
	testing.go:527: Step 0 error: Check failed: Check 4/4 error: aws_db_instance.test: Attribute 'monitoring_interval' expected "5", got "0"
--- FAIL: TestAccAWSDBInstance_SnapshotIdentifier_ParameterGroupName (1134.54s)
	testing.go:527: Step 0 error: Check failed: Check 4/4 error: aws_db_instance.test: Attribute 'parameter_group_name' expected "tf-acc-test-4546585708384390733", got "default.mariadb10.2"
```
  • Loading branch information
bflad committed Aug 21, 2018
1 parent 10c65de commit 09be94f
Show file tree
Hide file tree
Showing 2 changed files with 391 additions and 2 deletions.
31 changes: 29 additions & 2 deletions aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,13 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
var requiresModifyDbInstance bool

opts := rds.RestoreDBInstanceFromDBSnapshotInput{
AutoMinorVersionUpgrade: aws.Bool(d.Get("auto_minor_version_upgrade").(bool)),
CopyTagsToSnapshot: aws.Bool(d.Get("copy_tags_to_snapshot").(bool)),
DBInstanceClass: aws.String(d.Get("instance_class").(string)),
DBInstanceIdentifier: aws.String(d.Get("identifier").(string)),
DBSnapshotIdentifier: aws.String(d.Get("snapshot_identifier").(string)),
AutoMinorVersionUpgrade: aws.Bool(d.Get("auto_minor_version_upgrade").(bool)),
PubliclyAccessible: aws.Bool(d.Get("publicly_accessible").(bool)),
Tags: tags,
CopyTagsToSnapshot: aws.Bool(d.Get("copy_tags_to_snapshot").(bool)),
}

if attr, ok := d.GetOk("name"); ok {
Expand All @@ -696,6 +696,14 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
opts.AvailabilityZone = aws.String(attr.(string))
}

if _, ok := d.GetOk("backup_retention_period"); ok {
requiresModifyDbInstance = true
}

if _, ok := d.GetOk("backup_window"); ok {
requiresModifyDbInstance = true
}

if attr, ok := d.GetOk("db_subnet_group_name"); ok {
opts.DBSubnetGroupName = aws.String(attr.(string))
}
Expand All @@ -708,6 +716,10 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
opts.Engine = aws.String(attr.(string))
}

if _, ok := d.GetOk("iam_database_authentication_enabled"); ok {
requiresModifyDbInstance = true
}

if attr, ok := d.GetOk("iops"); ok {
opts.Iops = aws.Int64(int64(attr.(int)))
}
Expand All @@ -716,6 +728,18 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
opts.LicenseModel = aws.String(attr.(string))
}

if _, ok := d.GetOk("maintenance_window"); ok {
requiresModifyDbInstance = true
}

if _, ok := d.GetOk("monitoring_interval"); ok {
requiresModifyDbInstance = true
}

if _, ok := d.GetOk("monitoring_role_arn"); ok {
requiresModifyDbInstance = true
}

if attr, ok := d.GetOk("multi_az"); ok {
// When using SQL Server engine with MultiAZ enabled, its not
// possible to immediately enable mirroring since
Expand All @@ -732,7 +756,10 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error

if attr, ok := d.GetOk("option_group_name"); ok {
opts.OptionGroupName = aws.String(attr.(string))
}

if _, ok := d.GetOk("parameter_group_name"); ok {
requiresModifyDbInstance = true
}

if _, ok := d.GetOk("password"); ok {
Expand Down
Loading

0 comments on commit 09be94f

Please sign in to comment.