diff --git a/.changelog/22178.txt b/.changelog/22178.txt new file mode 100644 index 00000000000..4f90a78c96c --- /dev/null +++ b/.changelog/22178.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_db_instance: Fix error with reboot of replica +``` diff --git a/docs/contributing/contribution-checklists.md b/docs/contributing/contribution-checklists.md index 37d1bb35bb2..e2f3a17fb04 100644 --- a/docs/contributing/contribution-checklists.md +++ b/docs/contributing/contribution-checklists.md @@ -148,7 +148,7 @@ func TestAccServiceThing_nameGenerated(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckThingExists(resourceName, &thing), create.TestCheckResourceAttrNameGenerated(resourceName, "name"), - resource.TestCheckResourceAttr(resourceName, "name_prefix", "terraform-"), + resource.TestCheckResourceAttr(resourceName, "name_prefix", resource.UniqueIdPrefix), ), }, // If the resource supports import: diff --git a/internal/generate/namevaluesfilters/generators/servicefilters/main.go b/internal/generate/namevaluesfilters/generators/servicefilters/main.go index fd4ffb3d612..d6d18ce42c1 100644 --- a/internal/generate/namevaluesfilters/generators/servicefilters/main.go +++ b/internal/generate/namevaluesfilters/generators/servicefilters/main.go @@ -12,7 +12,7 @@ import ( "strings" "text/template" - "github.com/hashicorp/terraform-provider-aws/internal/namevaluesfilters" + "github.com/hashicorp/terraform-provider-aws/internal/generate/namevaluesfilters" ) const filename = `service_filters_gen.go` diff --git a/internal/service/rds/enum.go b/internal/service/rds/enum.go index 8e186e3b466..c31b4aa776e 100644 --- a/internal/service/rds/enum.go +++ b/internal/service/rds/enum.go @@ -6,6 +6,20 @@ const ( ClusterRoleStatusPending = "PENDING" ) +const ( + StorageTypeStandard = "standard" + StorageTypeGp2 = "gp2" + StorageTypeIo1 = "io1" +) + +func StorageType_Values() []string { + return []string{ + StorageTypeStandard, + StorageTypeGp2, + StorageTypeIo1, + } +} + // https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/accessing-monitoring.html#Overview.DBInstance.Status. const ( InstanceStatusAvailable = "available" @@ -15,6 +29,7 @@ const ( InstanceStatusCreating = "creating" InstanceStatusDeleting = "deleting" InstanceStatusIncompatibleParameters = "incompatible-parameters" + InstanceStatusIncompatibleRestore = "incompatible-restore" InstanceStatusModifying = "modifying" InstanceStatusStarting = "starting" InstanceStatusStopping = "stopping" diff --git a/internal/service/rds/instance.go b/internal/service/rds/instance.go index 8b80f5cc30c..54e6adcff03 100644 --- a/internal/service/rds/instance.go +++ b/internal/service/rds/instance.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/create" "github.com/hashicorp/terraform-provider-aws/internal/flex" tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -181,11 +182,13 @@ func ResourceInstance() *schema.Resource { value := v.(string) return strings.ToLower(value) }, + ConflictsWith: []string{"replicate_source_db"}, }, "engine_version": { - Type: schema.TypeString, - Optional: true, - Computed: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + ConflictsWith: []string{"replicate_source_db"}, }, "engine_version_actual": { Type: schema.TypeString, @@ -287,10 +290,11 @@ func ResourceInstance() *schema.Resource { Computed: true, }, "name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ConflictsWith: []string{"replicate_source_db"}, }, "nchar_character_set_name": { Type: schema.TypeString, @@ -342,6 +346,7 @@ func ResourceInstance() *schema.Resource { "replica_mode": { Type: schema.TypeString, Optional: true, + Computed: true, ValidateFunc: validation.StringInSlice(rds.ReplicaMode_Values(), false), }, "replicas": { @@ -459,9 +464,10 @@ func ResourceInstance() *schema.Resource { ForceNew: true, }, "storage_type": { - Type: schema.TypeString, - Optional: true, - Computed: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice(StorageType_Values(), false), }, "tags": tftags.TagsSchema(), "tags_all": tftags.TagsSchemaComputed(), @@ -472,10 +478,11 @@ func ResourceInstance() *schema.Resource { ForceNew: true, }, "username": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ConflictsWith: []string{"replicate_source_db"}, }, "vpc_security_group_ids": { Type: schema.TypeSet, @@ -511,18 +518,7 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { // we expect everything to be in sync before returning completion. var requiresRebootDbInstance bool - var identifier string - if v, ok := d.GetOk("identifier"); ok { - identifier = v.(string) - } else { - if v, ok := d.GetOk("identifier_prefix"); ok { - identifier = resource.PrefixedUniqueId(v.(string)) - } else { - identifier = resource.UniqueId() - } - - d.Set("identifier", identifier) - } + identifier := create.Name(d.Get("identifier").(string), d.Get("identifier_prefix").(string)) if v, ok := d.GetOk("replicate_source_db"); ok { opts := rds.CreateDBInstanceReadReplicaInput{ @@ -537,32 +533,16 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { } if _, ok := d.GetOk("allocated_storage"); ok { - log.Printf("[INFO] allocated_storage was ignored for DB Instance (%s) because a replica inherits the primary's allocated_storage and this cannot be changed at creation.", d.Id()) // RDS doesn't allow modifying the storage of a replica within the first 6h of creation. // allocated_storage is inherited from the primary so only the same value or no value is correct; a different value would fail the creation. // A different value is possible, granted: the value is higher than the current, there has been 6h between + log.Printf("[INFO] allocated_storage was ignored for DB Instance (%s) because a replica inherits the primary's allocated_storage and this cannot be changed at creation.", d.Id()) } if attr, ok := d.GetOk("availability_zone"); ok { opts.AvailabilityZone = aws.String(attr.(string)) } - if attr, ok := d.GetOk("allow_major_version_upgrade"); ok { - modifyDbInstanceInput.AllowMajorVersionUpgrade = aws.Bool(attr.(bool)) - // Having allowing_major_version_upgrade by itself should not trigger ModifyDBInstance - // InvalidParameterCombination: No modifications were requested - } - - if attr, ok := d.GetOk("backup_retention_period"); ok { - modifyDbInstanceInput.BackupRetentionPeriod = aws.Int64(int64(attr.(int))) - requiresModifyDbInstance = true - } - - if attr, ok := d.GetOk("backup_window"); ok { - modifyDbInstanceInput.PreferredBackupWindow = aws.String(attr.(string)) - requiresModifyDbInstance = true - } - if attr, ok := d.GetOk("db_subnet_group_name"); ok { opts.DBSubnetGroupName = aws.String(attr.(string)) } @@ -586,16 +566,6 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { } } - if attr, ok := d.GetOk("maintenance_window"); ok { - modifyDbInstanceInput.PreferredMaintenanceWindow = aws.String(attr.(string)) - requiresModifyDbInstance = true - } - - if attr, ok := d.GetOk("max_allocated_storage"); ok { - modifyDbInstanceInput.MaxAllocatedStorage = aws.Int64(int64(attr.(int))) - requiresModifyDbInstance = true - } - if attr, ok := d.GetOk("monitoring_interval"); ok { opts.MonitoringInterval = aws.Int64(int64(attr.(int))) } @@ -612,26 +582,10 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { opts.OptionGroupName = aws.String(attr.(string)) } - if attr, ok := d.GetOk("parameter_group_name"); ok { - modifyDbInstanceInput.DBParameterGroupName = aws.String(attr.(string)) - requiresModifyDbInstance = true - requiresRebootDbInstance = true - } - - if attr, ok := d.GetOk("password"); ok { - modifyDbInstanceInput.MasterUserPassword = aws.String(attr.(string)) - requiresModifyDbInstance = true - } - if attr, ok := d.GetOk("port"); ok { opts.Port = aws.Int64(int64(attr.(int))) } - if attr := d.Get("security_group_names").(*schema.Set); attr.Len() > 0 { - modifyDbInstanceInput.DBSecurityGroups = flex.ExpandStringSet(attr) - requiresModifyDbInstance = true - } - if attr, ok := d.GetOk("storage_type"); ok { opts.StorageType = aws.String(attr.(string)) } @@ -652,20 +606,91 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { opts.PerformanceInsightsRetentionPeriod = aws.Int64(int64(attr.(int))) } - if attr, ok := d.GetOk("ca_cert_identifier"); ok { - modifyDbInstanceInput.CACertificateIdentifier = aws.String(attr.(string)) - requiresModifyDbInstance = true - } - if attr, ok := d.GetOk("replica_mode"); ok { opts.ReplicaMode = aws.String(attr.(string)) requiresModifyDbInstance = true } - log.Printf("[DEBUG] DB Instance Replica create configuration: %#v", opts) - _, err := conn.CreateDBInstanceReadReplica(&opts) + output, err := conn.CreateDBInstanceReadReplica(&opts) if err != nil { - return fmt.Errorf("Error creating DB Instance: %s", err) + return fmt.Errorf("Error creating DB Instance: %w", err) + } + + if attr, ok := d.GetOk("allow_major_version_upgrade"); ok { + // Having allowing_major_version_upgrade by itself should not trigger ModifyDBInstance + // InvalidParameterCombination: No modifications were requested + modifyDbInstanceInput.AllowMajorVersionUpgrade = aws.Bool(attr.(bool)) + } + + if attr, ok := d.GetOk("backup_retention_period"); ok { + current := aws.Int64Value(output.DBInstance.BackupRetentionPeriod) + desired := int64(attr.(int)) + if current != desired { + modifyDbInstanceInput.BackupRetentionPeriod = aws.Int64(desired) + requiresModifyDbInstance = true + } + } + + if attr, ok := d.GetOk("backup_window"); ok { + current := aws.StringValue(output.DBInstance.PreferredBackupWindow) + desired := attr.(string) + if current != desired { + modifyDbInstanceInput.PreferredBackupWindow = aws.String(desired) + requiresModifyDbInstance = true + } + } + + if attr, ok := d.GetOk("ca_cert_identifier"); ok { + current := aws.StringValue(output.DBInstance.CACertificateIdentifier) + desired := attr.(string) + if current != desired { + modifyDbInstanceInput.CACertificateIdentifier = aws.String(desired) + requiresModifyDbInstance = true + } + } + + if attr, ok := d.GetOk("maintenance_window"); ok { + current := aws.StringValue(output.DBInstance.PreferredMaintenanceWindow) + desired := attr.(string) + if current != desired { + modifyDbInstanceInput.PreferredMaintenanceWindow = aws.String(desired) + requiresModifyDbInstance = true + } + } + + if attr, ok := d.GetOk("max_allocated_storage"); ok { + current := aws.Int64Value(output.DBInstance.MaxAllocatedStorage) + desired := int64(attr.(int)) + if current != desired { + modifyDbInstanceInput.MaxAllocatedStorage = aws.Int64(desired) + requiresModifyDbInstance = true + } + } + + if attr, ok := d.GetOk("parameter_group_name"); ok { + if len(output.DBInstance.DBParameterGroups) > 0 { + current := aws.StringValue(output.DBInstance.DBParameterGroups[0].DBParameterGroupName) + desired := attr.(string) + if current != desired { + modifyDbInstanceInput.DBParameterGroupName = aws.String(desired) + requiresModifyDbInstance = true + requiresRebootDbInstance = true + } + } + } + + if attr, ok := d.GetOk("password"); ok { + modifyDbInstanceInput.MasterUserPassword = aws.String(attr.(string)) + requiresModifyDbInstance = true + } + + if attr := d.Get("security_group_names").(*schema.Set); attr.Len() > 0 { + current := flattenDBSecurityGroups(output.DBInstance.DBSecurityGroups) + desired := attr + if !desired.Equal(current) { + modifyDbInstanceInput.DBSecurityGroups = flex.ExpandStringSet(attr) + requiresModifyDbInstance = true + } } } else if v, ok := d.GetOk("s3_import"); ok { @@ -689,7 +714,7 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { CopyTagsToSnapshot: aws.Bool(d.Get("copy_tags_to_snapshot").(bool)), DBName: aws.String(d.Get("name").(string)), DBInstanceClass: aws.String(d.Get("instance_class").(string)), - DBInstanceIdentifier: aws.String(d.Get("identifier").(string)), + DBInstanceIdentifier: aws.String(identifier), DeletionProtection: aws.Bool(d.Get("deletion_protection").(bool)), Engine: aws.String(d.Get("engine").(string)), EngineVersion: aws.String(d.Get("engine_version").(string)), @@ -820,15 +845,14 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { _, err = conn.RestoreDBInstanceFromS3(&opts) } if err != nil { - return fmt.Errorf("Error creating DB Instance: %s", err) + return fmt.Errorf("Error creating DB Instance: %w", err) } - d.SetId(d.Get("identifier").(string)) + d.SetId(identifier) log.Printf("[INFO] DB Instance ID: %s", d.Id()) - log.Println( - "[INFO] Waiting for DB Instance to be available") + log.Println("[INFO] Waiting for DB Instance to be available") stateConf := &resource.StateChangeConf{ Pending: resourceInstanceCreatePendingStates, @@ -851,7 +875,7 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { 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)), + DBInstanceIdentifier: aws.String(identifier), DBSnapshotIdentifier: aws.String(d.Get("snapshot_identifier").(string)), DeletionProtection: aws.Bool(d.Get("deletion_protection").(bool)), PubliclyAccessible: aws.Bool(d.Get("publicly_accessible").(bool)), @@ -1038,7 +1062,7 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { } if err != nil { - return fmt.Errorf("Error creating DB Instance: %s", err) + return fmt.Errorf("Error creating DB Instance: %w", err) } } else if v, ok := d.GetOk("restore_to_point_in_time"); ok { if input := expandRestoreToPointInTime(v.([]interface{})); input != nil { @@ -1048,7 +1072,7 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { input.DeletionProtection = aws.Bool(d.Get("deletion_protection").(bool)) input.PubliclyAccessible = aws.Bool(d.Get("publicly_accessible").(bool)) input.Tags = Tags(tags.IgnoreAWS()) - input.TargetDBInstanceIdentifier = aws.String(d.Get("identifier").(string)) + input.TargetDBInstanceIdentifier = aws.String(identifier) if v, ok := d.GetOk("availability_zone"); ok { input.AvailabilityZone = aws.String(v.(string)) @@ -1151,7 +1175,7 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { AllocatedStorage: aws.Int64(int64(d.Get("allocated_storage").(int))), DBName: aws.String(d.Get("name").(string)), DBInstanceClass: aws.String(d.Get("instance_class").(string)), - DBInstanceIdentifier: aws.String(d.Get("identifier").(string)), + DBInstanceIdentifier: aws.String(identifier), DeletionProtection: aws.Bool(d.Get("deletion_protection").(bool)), MasterUsername: aws.String(d.Get("username").(string)), MasterUserPassword: aws.String(d.Get("password").(string)), @@ -1166,6 +1190,7 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { attr := d.Get("backup_retention_period") opts.BackupRetentionPeriod = aws.Int64(int64(attr.(int))) + if attr, ok := d.GetOk("multi_az"); ok { opts.MultiAZ = aws.Bool(attr.(bool)) @@ -1297,9 +1322,9 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { if err != nil { if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "") { opts.MasterUserPassword = aws.String("********") - return fmt.Errorf("Error creating DB Instance: %s, %+v", err, opts) + return fmt.Errorf("Error creating DB Instance: %w, %+v", err, opts) } - return fmt.Errorf("Error creating DB Instance: %s", err) + return fmt.Errorf("Error creating DB Instance: %w", err) } // This is added here to avoid unnecessary modification when ca_cert_identifier is the default one if attr, ok := d.GetOk("ca_cert_identifier"); ok && attr.(string) != aws.StringValue(createdDBInstanceOutput.DBInstance.CACertificateIdentifier) { @@ -1308,7 +1333,7 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { } } - d.SetId(d.Get("identifier").(string)) + d.SetId(identifier) stateConf := &resource.StateChangeConf{ Pending: resourceInstanceCreatePendingStates, @@ -1331,13 +1356,13 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { log.Printf("[INFO] DB Instance (%s) configuration requires ModifyDBInstance: %s", d.Id(), modifyDbInstanceInput) _, err := conn.ModifyDBInstance(modifyDbInstanceInput) if err != nil { - return fmt.Errorf("error modifying DB Instance (%s): %s", d.Id(), err) + return fmt.Errorf("error modifying DB Instance (%s): %w", d.Id(), err) } log.Printf("[INFO] Waiting for DB Instance (%s) to be available", d.Id()) err = waitUntilDBInstanceAvailableAfterUpdate(d.Id(), conn, d.Timeout(schema.TimeoutUpdate)) if err != nil { - return fmt.Errorf("error waiting for DB Instance (%s) to be available: %s", d.Id(), err) + return fmt.Errorf("error waiting for DB Instance (%s) to be available: %w", d.Id(), err) } } @@ -1349,13 +1374,13 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error { log.Printf("[INFO] DB Instance (%s) configuration requires RebootDBInstance: %s", d.Id(), rebootDbInstanceInput) _, err := conn.RebootDBInstance(rebootDbInstanceInput) if err != nil { - return fmt.Errorf("error rebooting DB Instance (%s): %s", d.Id(), err) + return fmt.Errorf("error rebooting DB Instance (%s): %w", d.Id(), err) } log.Printf("[INFO] Waiting for DB Instance (%s) to be available", d.Id()) err = waitUntilDBInstanceAvailableAfterUpdate(d.Id(), conn, d.Timeout(schema.TimeoutUpdate)) if err != nil { - return fmt.Errorf("error waiting for DB Instance (%s) to be available: %s", d.Id(), err) + return fmt.Errorf("error waiting for DB Instance (%s) to be available: %w", d.Id(), err) } } @@ -1381,6 +1406,7 @@ func resourceInstanceRead(d *schema.ResourceData, meta interface{}) error { d.Set("name", v.DBName) d.Set("identifier", v.DBInstanceIdentifier) + d.Set("identifier_prefix", create.NamePrefixFromName(aws.StringValue(v.DBInstanceIdentifier))) d.Set("resource_id", v.DbiResourceId) d.Set("username", v.MasterUsername) d.Set("deletion_protection", v.DeletionProtection) @@ -1439,7 +1465,7 @@ func resourceInstanceRead(d *schema.ResourceData, meta interface{}) error { d.Set("monitoring_role_arn", v.MonitoringRoleArn) if err := d.Set("enabled_cloudwatch_logs_exports", flex.FlattenStringList(v.EnabledCloudwatchLogsExports)); err != nil { - return fmt.Errorf("error setting enabled_cloudwatch_logs_exports: %s", err) + return fmt.Errorf("error setting enabled_cloudwatch_logs_exports: %w", err) } d.Set("domain", "") @@ -1455,7 +1481,7 @@ func resourceInstanceRead(d *schema.ResourceData, meta interface{}) error { tags, err := ListTags(conn, d.Get("arn").(string)) if err != nil { - return fmt.Errorf("error listing tags for RDS DB Instance (%s): %s", d.Get("arn").(string), err) + return fmt.Errorf("error listing tags for RDS DB Instance (%s): %w", d.Get("arn").(string), err) } tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) @@ -1478,22 +1504,15 @@ func resourceInstanceRead(d *schema.ResourceData, meta interface{}) error { } d.Set("vpc_security_group_ids", ids) - // Create an empty schema.Set to hold all security group names - sgn := &schema.Set{ - F: schema.HashString, - } - for _, v := range v.DBSecurityGroups { - sgn.Add(*v.DBSecurityGroupName) - } - d.Set("security_group_names", sgn) - // replica things + d.Set("security_group_names", flattenDBSecurityGroups(v.DBSecurityGroups)) + // replica things var replicas []string for _, v := range v.ReadReplicaDBInstanceIdentifiers { replicas = append(replicas, *v) } if err := d.Set("replicas", replicas); err != nil { - return fmt.Errorf("Error setting replicas attribute: %#v, error: %#v", replicas, err) + return fmt.Errorf("Error setting replicas attribute: %#v, error: %w", replicas, err) } d.Set("replica_mode", v.ReplicaMode) @@ -1771,13 +1790,13 @@ func resourceInstanceUpdate(d *schema.ResourceData, meta interface{}) error { } if err != nil { - return fmt.Errorf("Error modifying DB Instance %s: %s", d.Id(), err) + return fmt.Errorf("Error modifying DB Instance %s: %w", d.Id(), err) } log.Printf("[DEBUG] Waiting for DB Instance (%s) to be available", d.Id()) err = waitUntilDBInstanceAvailableAfterUpdate(d.Id(), conn, d.Timeout(schema.TimeoutUpdate)) if err != nil { - return fmt.Errorf("error waiting for DB Instance (%s) to be available: %s", d.Id(), err) + return fmt.Errorf("error waiting for DB Instance (%s) to be available: %w", d.Id(), err) } } @@ -1795,7 +1814,7 @@ func resourceInstanceUpdate(d *schema.ResourceData, meta interface{}) error { } _, err := conn.PromoteReadReplica(&opts) if err != nil { - return fmt.Errorf("Error promoting database: %#v", err) + return fmt.Errorf("Error promoting database: %w", err) } d.Set("replicate_source_db", "") } else { @@ -1807,7 +1826,7 @@ func resourceInstanceUpdate(d *schema.ResourceData, meta interface{}) error { o, n := d.GetChange("tags_all") if err := UpdateTags(conn, d.Get("arn").(string), o, n); err != nil { - return fmt.Errorf("error updating RDS DB Instance (%s) tags: %s", d.Get("arn").(string), err) + return fmt.Errorf("error updating RDS DB Instance (%s) tags: %w", d.Get("arn").(string), err) } } @@ -1831,7 +1850,7 @@ func resourceInstanceRetrieve(id string, conn *rds.RDS) (*rds.DBInstance, error) if tfawserr.ErrMessageContains(err, rds.ErrCodeDBInstanceNotFoundFault, "") { return nil, nil } - return nil, fmt.Errorf("Error retrieving DB Instances: %s", err) + return nil, fmt.Errorf("Error retrieving DB Instances: %w", err) } if len(resp.DBInstances) != 1 || resp.DBInstances[0] == nil || aws.StringValue(resp.DBInstances[0].DBInstanceIdentifier) != id { @@ -1946,3 +1965,13 @@ func dbSetResourceDataEngineVersionFromInstance(d *schema.ResourceData, c *rds.D newVersion := aws.StringValue(c.EngineVersion) compareActualEngineVersion(d, oldVersion, newVersion) } + +func flattenDBSecurityGroups(groups []*rds.DBSecurityGroupMembership) *schema.Set { + result := &schema.Set{ + F: schema.HashString, + } + for _, v := range groups { + result.Add(aws.StringValue(v.DBSecurityGroupName)) + } + return result +} diff --git a/internal/service/rds/instance_test.go b/internal/service/rds/instance_test.go index 6fce6f419c2..63f0d87c889 100644 --- a/internal/service/rds/instance_test.go +++ b/internal/service/rds/instance_test.go @@ -16,13 +16,16 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/create" tfrds "github.com/hashicorp/terraform-provider-aws/internal/service/rds" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) func TestAccRDSInstance_basic(t *testing.T) { var dbInstance1 rds.DBInstance - resourceName := "aws_db_instance.bar" + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -31,10 +34,12 @@ func TestAccRDSInstance_basic(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceBasicConfig(), - Check: resource.ComposeTestCheckFunc( + Config: testAccInstanceBasicConfig(rName), + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(resourceName, &dbInstance1), testAccCheckInstanceAttributes(&dbInstance1), + resource.TestCheckResourceAttr(resourceName, "identifier", rName), + resource.TestCheckResourceAttr(resourceName, "identifier_prefix", ""), resource.TestCheckResourceAttr(resourceName, "allocated_storage", "10"), resource.TestCheckNoResourceAttr(resourceName, "allow_major_version_upgrade"), resource.TestCheckResourceAttr(resourceName, "auto_minor_version_upgrade", "true"), @@ -64,8 +69,9 @@ func TestAccRDSInstance_basic(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "resource_id"), resource.TestCheckResourceAttr(resourceName, "status", "available"), resource.TestCheckResourceAttr(resourceName, "storage_encrypted", "false"), + resource.TestCheckResourceAttr(resourceName, "storage_type", "gp2"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), - resource.TestCheckResourceAttr(resourceName, "username", "foo"), + resource.TestCheckResourceAttr(resourceName, "username", "test"), ), }, { @@ -120,6 +126,9 @@ func TestAccRDSInstance_onlyMajorVersion(t *testing.T) { func TestAccRDSInstance_namePrefix(t *testing.T) { var v rds.DBInstance + const identifierPrefix = "tf-acc-test-prefix-" + const resourceName = "aws_db_instance.test" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), @@ -127,21 +136,30 @@ func TestAccRDSInstance_namePrefix(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_namePrefix(), + Config: testAccInstanceConfig_namePrefix(identifierPrefix), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists("aws_db_instance.test", &v), - testAccCheckInstanceAttributes(&v), - resource.TestMatchResourceAttr( - "aws_db_instance.test", "identifier", regexp.MustCompile("^tf-test-")), + testAccCheckInstanceExists(resourceName, &v), + create.TestCheckResourceAttrNameFromPrefix(resourceName, "identifier", identifierPrefix), + resource.TestCheckResourceAttr(resourceName, "identifier_prefix", identifierPrefix), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", + }, + }, }, }) } -func TestAccRDSInstance_generatedName(t *testing.T) { +func TestAccRDSInstance_nameGenerated(t *testing.T) { var v rds.DBInstance + const resourceName = "aws_db_instance.test" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), @@ -149,12 +167,21 @@ func TestAccRDSInstance_generatedName(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_generatedName(), + Config: testAccInstanceConfig_nameGenerated(), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists("aws_db_instance.test", &v), - testAccCheckInstanceAttributes(&v), + testAccCheckInstanceExists(resourceName, &v), + create.TestCheckResourceAttrNameGenerated(resourceName, "identifier"), + resource.TestCheckResourceAttr(resourceName, "identifier_prefix", resource.UniqueIdPrefix), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", + }, + }, }, }) } @@ -599,7 +626,7 @@ func TestAccRDSInstance_password(t *testing.T) { }) } -func TestAccRDSInstance_replicateSourceDB(t *testing.T) { +func TestAccRDSInstance_replicateSourceDB_basic(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -613,8 +640,116 @@ func TestAccRDSInstance_replicateSourceDB(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_ReplicateSourceDB(rName), - Check: resource.ComposeTestCheckFunc( + Config: testAccInstanceConfig_ReplicateSourceDB_basic(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckInstanceExists(sourceResourceName, &sourceDbInstance), + testAccCheckInstanceExists(resourceName, &dbInstance), + resource.TestCheckResourceAttr(resourceName, "identifier", rName), + resource.TestCheckResourceAttr(resourceName, "identifier_prefix", ""), + testAccCheckInstanceReplicaAttributes(&sourceDbInstance, &dbInstance), + resource.TestCheckResourceAttrPair(resourceName, "name", sourceResourceName, "name"), + resource.TestCheckResourceAttrPair(resourceName, "username", sourceResourceName, "username"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", + }, + }, + }, + }) +} + +func TestAccRDSInstance_replicateSourceDB_namePrefix(t *testing.T) { + var v rds.DBInstance + + sourceName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + const identifierPrefix = "tf-acc-test-prefix-" + const resourceName = "aws_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInstanceConfig_ReplicateSourceDB_namePrefix(identifierPrefix, sourceName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckInstanceExists(resourceName, &v), + create.TestCheckResourceAttrNameFromPrefix(resourceName, "identifier", identifierPrefix), + resource.TestCheckResourceAttr(resourceName, "identifier_prefix", identifierPrefix), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", + }, + }, + }, + }) +} + +func TestAccRDSInstance_replicateSourceDB_nameGenerated(t *testing.T) { + var v rds.DBInstance + + sourceName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + const resourceName = "aws_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInstanceConfig_ReplicateSourceDB_nameGenerated(sourceName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckInstanceExists(resourceName, &v), + create.TestCheckResourceAttrNameGenerated(resourceName, "identifier"), + resource.TestCheckResourceAttr(resourceName, "identifier_prefix", resource.UniqueIdPrefix), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", + }, + }, + }, + }) +} + +func TestAccRDSInstance_replicateSourceDB_addLater(t *testing.T) { + var dbInstance, sourceDbInstance rds.DBInstance + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + sourceResourceName := "aws_db_instance.source" + resourceName := "aws_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInstanceConfig_ReplicateSourceDB_addLaterSetup(), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckInstanceExists(sourceResourceName, &sourceDbInstance), + ), + }, + { + Config: testAccInstanceConfig_ReplicateSourceDB_addLater(rName), + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(sourceResourceName, &sourceDbInstance), testAccCheckInstanceExists(resourceName, &dbInstance), testAccCheckInstanceReplicaAttributes(&sourceDbInstance, &dbInstance), @@ -1102,7 +1237,7 @@ func TestAccRDSInstance_ReplicateSourceDB_multiAZ(t *testing.T) { }) } -func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_sameSetOnBoth(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1116,20 +1251,22 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_ReplicateSourceDB_ParameterGroupName(rName), - Check: resource.ComposeTestCheckFunc( + Config: testAccInstanceConfig_ReplicateSourceDB_ParameterGroupName_sameSetOnBoth(rName), + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(sourceResourceName, &sourceDbInstance), testAccCheckInstanceExists(resourceName, &dbInstance), testAccCheckInstanceReplicaAttributes(&sourceDbInstance, &dbInstance), resource.TestCheckResourceAttr(resourceName, "parameter_group_name", rName), + resource.TestCheckResourceAttrPair(resourceName, "parameter_group_name", sourceResourceName, "parameter_group_name"), testAccCheckInstanceParameterApplyStatusInSync(&dbInstance), + testAccCheckInstanceParameterApplyStatusInSync(&sourceDbInstance), ), }, }, }) } -func TestAccRDSInstance_ReplicateSourceDB_port(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_differentSetOnBoth(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1143,19 +1280,22 @@ func TestAccRDSInstance_ReplicateSourceDB_port(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_ReplicateSourceDB_Port(rName, 9999), - Check: resource.ComposeTestCheckFunc( + Config: testAccInstanceConfig_ReplicateSourceDB_ParameterGroupName_differentSetOnBoth(rName), + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(sourceResourceName, &sourceDbInstance), + resource.TestCheckResourceAttr(sourceResourceName, "parameter_group_name", fmt.Sprintf("%s-source", rName)), testAccCheckInstanceExists(resourceName, &dbInstance), testAccCheckInstanceReplicaAttributes(&sourceDbInstance, &dbInstance), - resource.TestCheckResourceAttr(resourceName, "port", "9999"), + resource.TestCheckResourceAttr(resourceName, "parameter_group_name", rName), + testAccCheckInstanceParameterApplyStatusInSync(&dbInstance), + testAccCheckInstanceParameterApplyStatusInSync(&sourceDbInstance), ), }, }, }) } -func TestAccRDSInstance_ReplicateSourceDB_vpcSecurityGroupIDs(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_replicaCopiesValue(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1169,25 +1309,26 @@ func TestAccRDSInstance_ReplicateSourceDB_vpcSecurityGroupIDs(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_ReplicateSourceDB_VPCSecurityGroupIDs(rName), - Check: resource.ComposeTestCheckFunc( + Config: testAccInstanceConfig_ReplicateSourceDB_ParameterGroupName_replicaCopiesValue(rName), + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(sourceResourceName, &sourceDbInstance), testAccCheckInstanceExists(resourceName, &dbInstance), testAccCheckInstanceReplicaAttributes(&sourceDbInstance, &dbInstance), - resource.TestCheckResourceAttr(resourceName, "vpc_security_group_ids.#", "1"), + resource.TestCheckResourceAttr(resourceName, "parameter_group_name", rName), + resource.TestCheckResourceAttrPair(resourceName, "parameter_group_name", sourceResourceName, "parameter_group_name"), + testAccCheckInstanceParameterApplyStatusInSync(&dbInstance), ), }, }, }) } -func TestAccRDSInstance_ReplicateSourceDB_caCertificateIdentifier(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_setOnReplica(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) sourceResourceName := "aws_db_instance.source" resourceName := "aws_db_instance.test" - dataSourceName := "data.aws_rds_certificate.latest" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -1196,20 +1337,20 @@ func TestAccRDSInstance_ReplicateSourceDB_caCertificateIdentifier(t *testing.T) CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_ReplicateSourceDB_CACertificateIdentifier(rName), - Check: resource.ComposeTestCheckFunc( + Config: testAccInstanceConfig_ReplicateSourceDB_ParameterGroupName_setOnReplica(rName), + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(sourceResourceName, &sourceDbInstance), testAccCheckInstanceExists(resourceName, &dbInstance), testAccCheckInstanceReplicaAttributes(&sourceDbInstance, &dbInstance), - resource.TestCheckResourceAttrPair(sourceResourceName, "ca_cert_identifier", dataSourceName, "id"), - resource.TestCheckResourceAttrPair(resourceName, "ca_cert_identifier", dataSourceName, "id"), + resource.TestCheckResourceAttr(resourceName, "parameter_group_name", rName), + testAccCheckInstanceParameterApplyStatusInSync(&dbInstance), ), }, }, }) } -func TestAccRDSInstance_ReplicateSourceDB_replicaMode(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_port(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1223,23 +1364,24 @@ func TestAccRDSInstance_ReplicateSourceDB_replicaMode(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_ReplicateSourceDB_ReplicaMode(rName), + Config: testAccInstanceConfig_ReplicateSourceDB_Port(rName, 9999), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists(sourceResourceName, &sourceDbInstance), testAccCheckInstanceExists(resourceName, &dbInstance), testAccCheckInstanceReplicaAttributes(&sourceDbInstance, &dbInstance), - resource.TestCheckResourceAttr(resourceName, "replica_mode", "mounted"), + resource.TestCheckResourceAttr(resourceName, "port", "9999"), ), }, }, }) } -func TestAccRDSInstance_s3Import(t *testing.T) { - var snap rds.DBInstance - bucket := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - uniqueId := sdkacctest.RandomWithPrefix("tf-acc-s3-import-test") - bucketPrefix := sdkacctest.RandString(5) +func TestAccRDSInstance_ReplicateSourceDB_vpcSecurityGroupIDs(t *testing.T) { + var dbInstance, sourceDbInstance rds.DBInstance + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + sourceResourceName := "aws_db_instance.source" + resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -1248,23 +1390,25 @@ func TestAccRDSInstance_s3Import(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_S3Import(bucket, bucketPrefix, uniqueId), + Config: testAccInstanceConfig_ReplicateSourceDB_VPCSecurityGroupIDs(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists("aws_db_instance.s3", &snap), + testAccCheckInstanceExists(sourceResourceName, &sourceDbInstance), + testAccCheckInstanceExists(resourceName, &dbInstance), + testAccCheckInstanceReplicaAttributes(&sourceDbInstance, &dbInstance), + resource.TestCheckResourceAttr(resourceName, "vpc_security_group_ids.#", "1"), ), }, }, }) } -func TestAccRDSInstance_snapshotIdentifier(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_caCertificateIdentifier(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance - var dbSnapshot rds.DBSnapshot rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - sourceDbResourceName := "aws_db_instance.source" - snapshotResourceName := "aws_db_snapshot.test" + sourceResourceName := "aws_db_instance.source" resourceName := "aws_db_instance.test" + certifiateDataSourceName := "data.aws_rds_certificate.latest" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -1273,21 +1417,24 @@ func TestAccRDSInstance_snapshotIdentifier(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_SnapshotIdentifier(rName), + Config: testAccInstanceConfig_ReplicateSourceDB_CACertificateIdentifier(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists(sourceDbResourceName, &sourceDbInstance), - testAccCheckDbSnapshotExists(snapshotResourceName, &dbSnapshot), + testAccCheckInstanceExists(sourceResourceName, &sourceDbInstance), testAccCheckInstanceExists(resourceName, &dbInstance), + testAccCheckInstanceReplicaAttributes(&sourceDbInstance, &dbInstance), + resource.TestCheckResourceAttrPair(sourceResourceName, "ca_cert_identifier", certifiateDataSourceName, "id"), + resource.TestCheckResourceAttrPair(resourceName, "ca_cert_identifier", certifiateDataSourceName, "id"), ), }, }, }) } -func TestAccRDSInstance_snapshotIdentifierRemoved(t *testing.T) { - var dbInstance1, dbInstance2 rds.DBInstance +func TestAccRDSInstance_ReplicateSourceDB_replicaMode(t *testing.T) { + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + sourceResourceName := "aws_db_instance.source" resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -1297,30 +1444,30 @@ func TestAccRDSInstance_snapshotIdentifierRemoved(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_SnapshotIdentifier(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists(resourceName, &dbInstance1), - ), - }, - { - Config: testAccInstanceConfig_SnapshotIdentifierRemoved(rName), + Config: testAccInstanceConfig_ReplicateSourceDB_ReplicaMode(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists(resourceName, &dbInstance2), - testAccCheckInstanceNotRecreated(&dbInstance1, &dbInstance2), + testAccCheckInstanceExists(sourceResourceName, &sourceDbInstance), + testAccCheckInstanceExists(resourceName, &dbInstance), + testAccCheckInstanceReplicaAttributes(&sourceDbInstance, &dbInstance), + resource.TestCheckResourceAttr(resourceName, "replica_mode", "mounted"), ), }, }, }) } -func TestAccRDSInstance_SnapshotIdentifier_allocatedStorage(t *testing.T) { +// When an RDS Instance is added in a separate apply from the creation of the source instance, and the +// parameter group is changed on the replica, it can sometimes lead to the API trying to reboot the instance +// whenanother "management operation" is in progress: +// InvalidDBInstanceState: Instance cannot currently reboot due to an in-progress management operation +// https://github.com/hashicorp/terraform-provider-aws/issues/11905 +func TestAccRDSInstance_ReplicateSourceDB_parameterGroupTwoStep(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance - var dbSnapshot rds.DBSnapshot rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - sourceDbResourceName := "aws_db_instance.source" - snapshotResourceName := "aws_db_snapshot.test" resourceName := "aws_db_instance.test" + sourceResourceName := "aws_db_instance.source" + parameterGroupResourceName := "aws_db_parameter_group.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -1329,26 +1476,36 @@ func TestAccRDSInstance_SnapshotIdentifier_allocatedStorage(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_SnapshotIdentifier_AllocatedStorage(rName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists(sourceDbResourceName, &sourceDbInstance), - testAccCheckDbSnapshotExists(snapshotResourceName, &dbSnapshot), + Config: testAccInstanceConfig_ReplicateSourceDB_ParameterGroupTwoStep_Setup(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckInstanceExists(sourceResourceName, &sourceDbInstance), + resource.TestCheckResourceAttr(sourceResourceName, "parameter_group_name", "default.oracle-ee-19"), + testAccCheckInstanceParameterApplyStatusInSync(&sourceDbInstance), + ), + }, + { + Config: testAccInstanceConfig_ReplicateSourceDB_ParameterGroupTwoStep(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckInstanceExists(sourceResourceName, &sourceDbInstance), + resource.TestCheckResourceAttr(sourceResourceName, "parameter_group_name", "default.oracle-ee-19"), testAccCheckInstanceExists(resourceName, &dbInstance), - resource.TestCheckResourceAttr(resourceName, "allocated_storage", "10"), + resource.TestCheckResourceAttr(resourceName, "replica_mode", "open-read-only"), + resource.TestCheckResourceAttrPair(resourceName, "parameter_group_name", parameterGroupResourceName, "id"), + testAccCheckInstanceParameterApplyStatusInSync(&dbInstance), + testAccCheckInstanceParameterApplyStatusInSync(&sourceDbInstance), ), }, }, }) } -func TestAccRDSInstance_SnapshotIdentifier_io1Storage(t *testing.T) { - var dbInstance, sourceDbInstance rds.DBInstance - var dbSnapshot rds.DBSnapshot +func TestAccRDSInstance_s3Import_basic(t *testing.T) { + var snap rds.DBInstance + bucket := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + uniqueId := sdkacctest.RandomWithPrefix("tf-acc-s3-import-test") + bucketPrefix := sdkacctest.RandString(5) - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - sourceDbResourceName := "aws_db_instance.source" - snapshotResourceName := "aws_db_snapshot.test" - resourceName := "aws_db_instance.test" + const resourceName = "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -1357,26 +1514,32 @@ func TestAccRDSInstance_SnapshotIdentifier_io1Storage(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_SnapshotIdentifier_Io1Storage(rName, 1000), + Config: testAccInstanceConfig_S3Import_basic(bucket, bucketPrefix, uniqueId), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists(sourceDbResourceName, &sourceDbInstance), - testAccCheckDbSnapshotExists(snapshotResourceName, &dbSnapshot), - testAccCheckInstanceExists(resourceName, &dbInstance), - resource.TestCheckResourceAttr(resourceName, "iops", "1000"), + testAccCheckInstanceExists(resourceName, &snap), + resource.TestCheckResourceAttr(resourceName, "identifier", uniqueId), + resource.TestCheckResourceAttr(resourceName, "identifier_prefix", ""), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", + }, + }, }, }) } -func TestAccRDSInstance_SnapshotIdentifier_allowMajorVersionUpgrade(t *testing.T) { - var dbInstance, sourceDbInstance rds.DBInstance - var dbSnapshot rds.DBSnapshot +func TestAccRDSInstance_s3Import_namePrefix(t *testing.T) { + var snap rds.DBInstance + const identifierPrefix = "tf-acc-test-prefix-" + bucket := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + bucketPrefix := sdkacctest.RandString(5) - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - sourceDbResourceName := "aws_db_instance.source" - snapshotResourceName := "aws_db_snapshot.test" - resourceName := "aws_db_instance.test" + const resourceName = "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -1385,26 +1548,31 @@ func TestAccRDSInstance_SnapshotIdentifier_allowMajorVersionUpgrade(t *testing.T CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_SnapshotIdentifier_AllowMajorVersionUpgrade(rName, true), + Config: testAccInstanceConfig_S3Import_namePrefix(bucket, bucketPrefix, identifierPrefix), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists(sourceDbResourceName, &sourceDbInstance), - testAccCheckDbSnapshotExists(snapshotResourceName, &dbSnapshot), - testAccCheckInstanceExists(resourceName, &dbInstance), - resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "true"), + testAccCheckInstanceExists(resourceName, &snap), + create.TestCheckResourceAttrNameFromPrefix(resourceName, "identifier", identifierPrefix), + resource.TestCheckResourceAttr(resourceName, "identifier_prefix", identifierPrefix), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", + }, + }, }, }) } -func TestAccRDSInstance_SnapshotIdentifier_autoMinorVersionUpgrade(t *testing.T) { - var dbInstance, sourceDbInstance rds.DBInstance - var dbSnapshot rds.DBSnapshot +func TestAccRDSInstance_s3Import_nameGenerated(t *testing.T) { + var snap rds.DBInstance + bucket := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + bucketPrefix := sdkacctest.RandString(5) - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - sourceDbResourceName := "aws_db_instance.source" - snapshotResourceName := "aws_db_snapshot.test" - resourceName := "aws_db_instance.test" + const resourceName = "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -1413,9 +1581,267 @@ func TestAccRDSInstance_SnapshotIdentifier_autoMinorVersionUpgrade(t *testing.T) CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_SnapshotIdentifier_AutoMinorVersionUpgrade(rName, false), + Config: testAccInstanceConfig_S3Import_nameGenerated(bucket, bucketPrefix), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists(sourceDbResourceName, &sourceDbInstance), + testAccCheckInstanceExists(resourceName, &snap), + create.TestCheckResourceAttrNameGenerated(resourceName, "identifier"), + resource.TestCheckResourceAttr(resourceName, "identifier_prefix", resource.UniqueIdPrefix), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", + }, + }, + }, + }) +} + +func TestAccRDSInstance_SnapshotIdentifier_basic(t *testing.T) { + var dbInstance, sourceDbInstance rds.DBInstance + var dbSnapshot rds.DBSnapshot + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + sourceDbResourceName := "aws_db_instance.source" + snapshotResourceName := "aws_db_snapshot.test" + resourceName := "aws_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInstanceConfig_SnapshotIdentifier(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists(sourceDbResourceName, &sourceDbInstance), + testAccCheckDbSnapshotExists(snapshotResourceName, &dbSnapshot), + testAccCheckInstanceExists(resourceName, &dbInstance), + resource.TestCheckResourceAttr(resourceName, "identifier", rName), + resource.TestCheckResourceAttr(resourceName, "identifier_prefix", ""), + resource.TestCheckResourceAttrPair(resourceName, "instance_class", sourceDbResourceName, "instance_class"), + resource.TestCheckResourceAttrPair(resourceName, "allocated_storage", sourceDbResourceName, "allocated_storage"), + resource.TestCheckResourceAttrPair(resourceName, "engine", sourceDbResourceName, "engine"), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", sourceDbResourceName, "engine_version"), + resource.TestCheckResourceAttrPair(resourceName, "username", sourceDbResourceName, "username"), + resource.TestCheckResourceAttrPair(resourceName, "name", sourceDbResourceName, "name"), + resource.TestCheckResourceAttrPair(resourceName, "maintenance_window", sourceDbResourceName, "maintenance_window"), + resource.TestCheckResourceAttrPair(resourceName, "option_group_name", sourceDbResourceName, "option_group_name"), + resource.TestCheckResourceAttrPair(resourceName, "parameter_group_name", sourceDbResourceName, "parameter_group_name"), + resource.TestCheckResourceAttrPair(resourceName, "port", sourceDbResourceName, "port"), + ), + }, + }, + }) +} + +func TestAccRDSInstance_SnapshotIdentifier_namePrefix(t *testing.T) { + var v rds.DBInstance + + sourceName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + const identifierPrefix = "tf-acc-test-prefix-" + const resourceName = "aws_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInstanceConfig_SnapshotIdentifier_namePrefix(identifierPrefix, sourceName), + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists(resourceName, &v), + create.TestCheckResourceAttrNameFromPrefix(resourceName, "identifier", identifierPrefix), + resource.TestCheckResourceAttr(resourceName, "identifier_prefix", identifierPrefix), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", + "snapshot_identifier", + }, + }, + }, + }) +} + +func TestAccRDSInstance_SnapshotIdentifier_nameGenerated(t *testing.T) { + var v rds.DBInstance + + sourceName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + const resourceName = "aws_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInstanceConfig_SnapshotIdentifier_nameGenerated(sourceName), + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists(resourceName, &v), + create.TestCheckResourceAttrNameGenerated(resourceName, "identifier"), + resource.TestCheckResourceAttr(resourceName, "identifier_prefix", resource.UniqueIdPrefix), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", + "snapshot_identifier", + }, + }, + }, + }) +} + +func TestAccRDSInstance_SnapshotIdentifier_AssociationRemoved(t *testing.T) { + var dbInstance1, dbInstance2 rds.DBInstance + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + sourceDbResourceName := "aws_db_instance.source" + resourceName := "aws_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInstanceConfig_SnapshotIdentifier(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists(resourceName, &dbInstance1), + ), + }, + { + Config: testAccInstanceConfig_SnapshotIdentifier_AssociationRemoved(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists(resourceName, &dbInstance2), + testAccCheckInstanceNotRecreated(&dbInstance1, &dbInstance2), + resource.TestCheckResourceAttrPair(resourceName, "allocated_storage", sourceDbResourceName, "allocated_storage"), + resource.TestCheckResourceAttrPair(resourceName, "engine", sourceDbResourceName, "engine"), + resource.TestCheckResourceAttrPair(resourceName, "username", sourceDbResourceName, "username"), + ), + }, + }, + }) +} + +func TestAccRDSInstance_SnapshotIdentifier_allocatedStorage(t *testing.T) { + var dbInstance, sourceDbInstance rds.DBInstance + var dbSnapshot rds.DBSnapshot + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + sourceDbResourceName := "aws_db_instance.source" + snapshotResourceName := "aws_db_snapshot.test" + resourceName := "aws_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInstanceConfig_SnapshotIdentifier_AllocatedStorage(rName, 10), + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists(sourceDbResourceName, &sourceDbInstance), + testAccCheckDbSnapshotExists(snapshotResourceName, &dbSnapshot), + testAccCheckInstanceExists(resourceName, &dbInstance), + resource.TestCheckResourceAttr(resourceName, "allocated_storage", "10"), + ), + }, + }, + }) +} + +func TestAccRDSInstance_SnapshotIdentifier_io1Storage(t *testing.T) { + var dbInstance, sourceDbInstance rds.DBInstance + var dbSnapshot rds.DBSnapshot + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + sourceDbResourceName := "aws_db_instance.source" + snapshotResourceName := "aws_db_snapshot.test" + resourceName := "aws_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInstanceConfig_SnapshotIdentifier_Io1Storage(rName, 1000), + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists(sourceDbResourceName, &sourceDbInstance), + testAccCheckDbSnapshotExists(snapshotResourceName, &dbSnapshot), + testAccCheckInstanceExists(resourceName, &dbInstance), + resource.TestCheckResourceAttr(resourceName, "iops", "1000"), + ), + }, + }, + }) +} + +func TestAccRDSInstance_SnapshotIdentifier_allowMajorVersionUpgrade(t *testing.T) { + var dbInstance, sourceDbInstance rds.DBInstance + var dbSnapshot rds.DBSnapshot + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + sourceDbResourceName := "aws_db_instance.source" + snapshotResourceName := "aws_db_snapshot.test" + resourceName := "aws_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInstanceConfig_SnapshotIdentifier_AllowMajorVersionUpgrade(rName, true), + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists(sourceDbResourceName, &sourceDbInstance), + testAccCheckDbSnapshotExists(snapshotResourceName, &dbSnapshot), + testAccCheckInstanceExists(resourceName, &dbInstance), + resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "true"), + ), + }, + }, + }) +} + +func TestAccRDSInstance_SnapshotIdentifier_autoMinorVersionUpgrade(t *testing.T) { + var dbInstance, sourceDbInstance rds.DBInstance + var dbSnapshot rds.DBSnapshot + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + sourceDbResourceName := "aws_db_instance.source" + snapshotResourceName := "aws_db_snapshot.test" + resourceName := "aws_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInstanceConfig_SnapshotIdentifier_AutoMinorVersionUpgrade(rName, false), + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists(sourceDbResourceName, &sourceDbInstance), testAccCheckDbSnapshotExists(snapshotResourceName, &dbSnapshot), testAccCheckInstanceExists(resourceName, &dbInstance), resource.TestCheckResourceAttr(resourceName, "auto_minor_version_upgrade", "false"), @@ -1452,7 +1878,7 @@ func TestAccRDSInstance_SnapshotIdentifier_availabilityZone(t *testing.T) { }) } -func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriod(t *testing.T) { +func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriod_override(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -1480,7 +1906,7 @@ func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriod(t *testing.T) { }) } -func TestAccRDSInstance_SnapshotIdentifierBackupRetentionPeriod_unset(t *testing.T) { +func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriod_unset(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -1567,7 +1993,7 @@ func TestAccRDSInstance_SnapshotIdentifier_dbSubnetGroupName(t *testing.T) { }) } -func TestAccRDSInstance_SnapshotIdentifierDBSubnetGroupName_ramShared(t *testing.T) { +func TestAccRDSInstance_SnapshotIdentifier_DBSubnetGroupName_ramShared(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot var dbSubnetGroup rds.DBSubnetGroup @@ -1603,7 +2029,7 @@ func TestAccRDSInstance_SnapshotIdentifierDBSubnetGroupName_ramShared(t *testing }) } -func TestAccRDSInstance_SnapshotIdentifierDBSubnetGroupName_vpcSecurityGroupIDs(t *testing.T) { +func TestAccRDSInstance_SnapshotIdentifier_DBSubnetGroupName_vpcSecurityGroupIDs(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot var dbSubnetGroup rds.DBSubnetGroup @@ -1812,7 +2238,7 @@ func TestAccRDSInstance_SnapshotIdentifier_multiAZ(t *testing.T) { }) } -func TestAccRDSInstance_SnapshotIdentifierMultiAZ_sqlServer(t *testing.T) { +func TestAccRDSInstance_SnapshotIdentifier_multiAZ_sqlServer(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -1926,7 +2352,7 @@ func TestAccRDSInstance_SnapshotIdentifier_tags(t *testing.T) { }) } -func TestAccRDSInstance_SnapshotIdentifierTags_unset(t *testing.T) { +func TestAccRDSInstance_SnapshotIdentifier_Tags_Clear(t *testing.T) { acctest.Skip(t, "To be fixed: https://github.com/hashicorp/terraform-provider-aws/issues/5959") // --- FAIL: TestAccRDSInstance_SnapshotIdentifierTags_unset (1086.15s) // testing.go:527: Step 0 error: Check failed: Check 4/4 error: aws_db_instance.test: Attribute 'tags.%' expected "0", got "1" @@ -1946,7 +2372,7 @@ func TestAccRDSInstance_SnapshotIdentifierTags_unset(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_SnapshotIdentifier_Tags_Unset(rName), + Config: testAccInstanceConfig_SnapshotIdentifier_Tags_Clear(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists(sourceDbResourceName, &sourceDbInstance), testAccCheckDbSnapshotExists(snapshotResourceName, &dbSnapshot), @@ -1989,7 +2415,7 @@ func TestAccRDSInstance_SnapshotIdentifier_vpcSecurityGroupIDs(t *testing.T) { // This acceptance test explicitly tests when snapshot_identifier is set, // vpc_security_group_ids is set (which triggered the resource update function), // and tags is set which was missing its ARN used for tagging -func TestAccRDSInstance_SnapshotIdentifierVPCSecurityGroupIDs_tags(t *testing.T) { +func TestAccRDSInstance_SnapshotIdentifier_vpcSecurityGroupIDs_tags(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -3569,9 +3995,9 @@ func TestAccRDSInstance_license(t *testing.T) { func testAccInstanceConfig_orderableClass(engine, version, license string) string { return fmt.Sprintf(` data "aws_rds_orderable_db_instance" "test" { - engine = %q - engine_version = %q - license_model = %q + engine = %[1]q + engine_version = %[2]q + license_model = %[3]q storage_type = "standard" preferred_instance_classes = ["db.t3.micro", "db.t2.micro", "db.t2.medium"] @@ -3584,16 +4010,19 @@ func testAccInstanceConfig_orderableClassMySQL() string { } func testAccInstanceConfig_orderableClassMariadb() string { - return testAccInstanceConfig_orderableClass("mariadb", "10.2.15", "general-public-license") + return testAccInstanceConfig_orderableClass("mariadb", "10.5.12", "general-public-license") } func testAccInstanceConfig_orderableClassSQLServerEx() string { return testAccInstanceConfig_orderableClass("sqlserver-ex", "14.00.1000.169.v1", "license-included") } -func testAccInstanceBasicConfig() string { - return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMySQL(), ` -resource "aws_db_instance" "bar" { +func testAccInstanceBasicConfig(rName string) string { + return acctest.ConfigCompose( + testAccInstanceConfig_orderableClassMySQL(), + fmt.Sprintf(` +resource "aws_db_instance" "test" { + identifier = %[1]q allocated_storage = 10 backup_retention_period = 0 engine = data.aws_rds_orderable_db_instance.test.engine @@ -3603,14 +4032,14 @@ resource "aws_db_instance" "bar" { parameter_group_name = "default.mysql5.6" password = "barbarbarbar" skip_final_snapshot = true - username = "foo" + username = "test" # Maintenance Window is stored in lower case in the API, though not strictly # documented. Terraform will downcase this to match (as opposed to throw a # validation error). maintenance_window = "Fri:09:00-Fri:09:30" } -`) +`, rName)) } func testAccInstanceConfig_MajorVersionOnly(engine, engineVersion string) string { @@ -3639,23 +4068,26 @@ resource "aws_db_instance" "test" { `, engine, engineVersion)) } -func testAccInstanceConfig_namePrefix() string { - return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMySQL(), ` +func testAccInstanceConfig_namePrefix(identifierPrefix string) string { + return acctest.ConfigCompose( + testAccInstanceConfig_orderableClassMySQL(), + fmt.Sprintf(` resource "aws_db_instance" "test" { + identifier_prefix = %[1]q allocated_storage = 10 engine = data.aws_rds_orderable_db_instance.test.engine - identifier_prefix = "tf-test-" instance_class = data.aws_rds_orderable_db_instance.test.instance_class password = "password" publicly_accessible = true skip_final_snapshot = true username = "root" } -`) +`, identifierPrefix)) } -func testAccInstanceConfig_generatedName() string { - return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMySQL(), ` +func testAccInstanceConfig_nameGenerated() string { + return acctest.ConfigCompose( + testAccInstanceConfig_orderableClassMySQL(), ` resource "aws_db_instance" "test" { allocated_storage = 10 engine = data.aws_rds_orderable_db_instance.test.engine @@ -3829,8 +4261,10 @@ resource "aws_db_instance" "snapshot" { `, sdkacctest.RandInt())) } -func testAccInstanceConfig_S3Import(bucketName string, bucketPrefix string, uniqueId string) string { - return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` +func testAccInstanceConfig_S3Import_Base(rName, bucketPrefix string) string { + return acctest.ConfigCompose( + acctest.ConfigVpcWithSubnets(2), + fmt.Sprintf(` resource "aws_s3_bucket" "xtrabackup" { bucket = %[1]q } @@ -3845,7 +4279,7 @@ resource "aws_s3_object" "xtrabackup_db" { data "aws_partition" "current" {} resource "aws_iam_role" "rds_s3_access_role" { - name = "%[3]s-role" + name = "%[1]s-role" assume_role_policy = <