diff --git a/.changelog/31232.txt b/.changelog/31232.txt new file mode 100644 index 00000000000..a21d403010a --- /dev/null +++ b/.changelog/31232.txt @@ -0,0 +1,35 @@ +```release-note:breaking-change +resource/aws_db_instance: Remove `name` - use `db_name` instead +``` + +```release-note:enhancement +resource/aws_db_instance: Updates to `identifier` and `identifier_prefix` will no longer cause the database instance to be destroyed and recreated +``` + +```release-note:breaking-change +resource/aws_db_instance: `id` is no longer the AWS database `identifier` - `id` is now the `dbi-resource-id`. Refer to `identifier` instead of `id` to use the database's identifier +``` + +```release-note:note +resource/aws_db_instance: The change of what `id` is, namely, a DBI Resource ID now versus DB Identifier previously, has far-reaching consequences. Configurations that refer to, for example, `aws_db_instance.example.id` will now have errors and must be changed to use `identifier` instead, for example, `aws_db_instance.example.identifier` +``` + +```release-note:note +resource/aws_db_snapshot: Configurations that define `db_instance_identifier` using the `id` attribute of `aws_db_instance` must be updated to use `identifier` instead - for example, `db_instance_identifier = aws_db_instance.example.id` must be updated to `db_instance_identifier = aws_db_instance.example.identifier` +``` + +```release-note:note +resource/aws_db_instance: Configurations that define `replicate_source_db` using the `id` attribute of `aws_db_instance` must be updated to use `identifier` instead - for example, `replicate_source_db = aws_db_instance.example.id` must be updated to `replicate_source_db = aws_db_instance.example.identifier` +``` + +```release-note:note +resource/aws_db_instance_role_association: Configurations that define `db_instance_identifier` using the `id` attribute of `aws_db_instance` must be updated to use `identifier` instead - for example, `db_instance_identifier = aws_db_instance.example.id` must be updated to `db_instance_identifier = aws_db_instance.example.identifier` +``` + +```release-note:note +resource/aws_db_proxy_target: Configurations that define `db_instance_identifier` using the `id` attribute of `aws_db_instance` must be updated to use `identifier` instead - for example, `db_instance_identifier = aws_db_instance.example.id` must be updated to `db_instance_identifier = aws_db_instance.example.identifier` +``` + +```release-note:note +resource/aws_db_event_subscription: Configurations that define `source_ids` using the `id` attribute of `aws_db_instance` must be updated to use `identifier` instead - for example, `source_ids = [aws_db_instance.example.id]` must be updated to `source_ids = [aws_db_instance.example.identifier]` +``` diff --git a/examples/rds/main.tf b/examples/rds/main.tf index 9781d5c0a69..09a5590732f 100644 --- a/examples/rds/main.tf +++ b/examples/rds/main.tf @@ -13,7 +13,7 @@ resource "aws_db_instance" "default" { engine = var.engine engine_version = var.engine_version[var.engine] instance_class = var.instance_class - name = var.db_name + db_name = var.db_name username = var.username password = var.password vpc_security_group_ids = [aws_security_group.default.id] diff --git a/examples/rds/outputs.tf b/examples/rds/outputs.tf index cf7712d12a6..e8f41d4bdc8 100644 --- a/examples/rds/outputs.tf +++ b/examples/rds/outputs.tf @@ -3,7 +3,7 @@ output "subnet_group" { } output "db_instance_id" { - value = aws_db_instance.default.id + value = aws_db_instance.default.identifier } output "db_instance_address" { diff --git a/internal/service/rds/blue_green.go b/internal/service/rds/blue_green.go index 50d64b1dc18..393971e1e81 100644 --- a/internal/service/rds/blue_green.go +++ b/internal/service/rds/blue_green.go @@ -97,7 +97,7 @@ func (h *instanceHandler) precondition(ctx context.Context, d *schema.ResourceDa needsPreConditions := false input := &rds_sdkv2.ModifyDBInstanceInput{ ApplyImmediately: true, - DBInstanceIdentifier: aws.String(d.Id()), + DBInstanceIdentifier: aws.String(d.Get("identifier").(string)), } // Backups must be enabled for Blue/Green Deployments. Enable them first. @@ -113,7 +113,7 @@ func (h *instanceHandler) precondition(ctx context.Context, d *schema.ResourceDa } if needsPreConditions { - err := dbInstanceModify(ctx, h.conn, input, d.Timeout(schema.TimeoutUpdate)) + err := dbInstanceModify(ctx, h.conn, d.Id(), input, d.Timeout(schema.TimeoutUpdate)) if err != nil { return fmt.Errorf("setting pre-conditions: %s", err) } @@ -123,7 +123,7 @@ func (h *instanceHandler) precondition(ctx context.Context, d *schema.ResourceDa func (h *instanceHandler) createBlueGreenInput(d *schema.ResourceData) *rds_sdkv2.CreateBlueGreenDeploymentInput { input := &rds_sdkv2.CreateBlueGreenDeploymentInput{ - BlueGreenDeploymentName: aws.String(d.Id()), + BlueGreenDeploymentName: aws.String(d.Get("identifier").(string)), Source: aws.String(d.Get("arn").(string)), } @@ -148,7 +148,7 @@ func (h *instanceHandler) modifyTarget(ctx context.Context, identifier string, d if needsModify { log.Printf("[DEBUG] %s: Updating Green environment", operation) - err := dbInstanceModify(ctx, h.conn, modifyInput, timeout) + err := dbInstanceModify(ctx, h.conn, d.Id(), modifyInput, timeout) if err != nil { return fmt.Errorf("updating Green environment: %s", err) } diff --git a/internal/service/rds/export_task_test.go b/internal/service/rds/export_task_test.go index 8c8563c2576..97daf136773 100644 --- a/internal/service/rds/export_task_test.go +++ b/internal/service/rds/export_task_test.go @@ -253,7 +253,7 @@ resource "aws_db_instance" "test" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.test.id + db_instance_identifier = aws_db_instance.test.identifier db_snapshot_identifier = %[1]q } `, rName) diff --git a/internal/service/rds/instance.go b/internal/service/rds/instance.go index fa8b182a92b..7fe87401603 100644 --- a/internal/service/rds/instance.go +++ b/internal/service/rds/instance.go @@ -34,6 +34,17 @@ import ( "golang.org/x/exp/slices" ) +// NOTE ON "ID", "IDENTIFIER": +// ID is overloaded and potentially confusing. Hopefully this clears it up. +// * ID, as in d.Id(), d.SetId(), is: +// - the same as AWS calls the "dbi-resource-id" a/k/a "database instance resource ID" +// - unchangeable/immutable +// - called either "id" or "resource_id" in schema/state (previously was only "resource_id") +// * "identifier" is: +// - user-defined identifier which AWS calls "identifier" +// - can be updated +// - called "identifier" in the schema/state (previously was also "id") + // @SDKResource("aws_db_instance", name="DB Instance") // @Tags(identifierAttribute="arn") func ResourceInstance() *schema.Resource { @@ -47,13 +58,18 @@ func ResourceInstance() *schema.Resource { StateContext: resourceInstanceImport, }, - SchemaVersion: 1, + SchemaVersion: 2, StateUpgraders: []schema.StateUpgrader{ { Type: resourceInstanceResourceV0().CoreConfigSchema().ImpliedType(), Upgrade: InstanceStateUpgradeV0, Version: 0, }, + { + Type: resourceInstanceResourceV1().CoreConfigSchema().ImpliedType(), + Upgrade: InstanceStateUpgradeV1, + Version: 1, + }, }, Timeouts: &schema.ResourceTimeout{ @@ -177,7 +193,6 @@ func ResourceInstance() *schema.Resource { Computed: true, ForceNew: true, ConflictsWith: []string{ - "name", "replicate_source_db", }, }, @@ -256,7 +271,6 @@ func ResourceInstance() *schema.Resource { Type: schema.TypeString, Optional: true, Computed: true, - ForceNew: true, ConflictsWith: []string{"identifier_prefix"}, ValidateFunc: validIdentifier, }, @@ -264,7 +278,6 @@ func ResourceInstance() *schema.Resource { Type: schema.TypeString, Optional: true, Computed: true, - ForceNew: true, ConflictsWith: []string{"identifier"}, ValidateFunc: validIdentifierPrefix, }, @@ -384,17 +397,6 @@ func ResourceInstance() *schema.Resource { Optional: true, Computed: true, }, - "name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - Deprecated: "Use db_name instead", - ForceNew: true, - ConflictsWith: []string{ - "db_name", - "replicate_source_db", - }, - }, "nchar_character_set_name": { Type: schema.TypeString, Optional: true, @@ -645,8 +647,11 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in // we expect everything to be in sync before returning completion. var requiresRebootDbInstance bool + // See discussion of IDs at the top of file - this is NOT d.Id() identifier := create.Name(d.Get("identifier").(string), d.Get("identifier_prefix").(string)) + var resourceID string // will be assigned depending on how it is created + if v, ok := d.GetOk("replicate_source_db"); ok { sourceDBInstanceID := v.(string) input := &rds.CreateDBInstanceReadReplicaInput{ @@ -664,7 +669,7 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in // 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 - diags = sdkdiag.AppendWarningf(diags, `"allocated_storage" was ignored for DB Instance (%s) because a replica inherits the primary's allocated_storage and cannot be changed at creation.`, d.Id()) + diags = sdkdiag.AppendWarningf(diags, `"allocated_storage" was ignored for DB Instance (%s) because a replica inherits the primary's allocated_storage and cannot be changed at creation.`, identifier) } if v, ok := d.GetOk("availability_zone"); ok { @@ -762,6 +767,8 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in output := outputRaw.(*rds.CreateDBInstanceReadReplicaOutput) + resourceID = aws.StringValue(output.DBInstance.DbiResourceId) + if v, ok := d.GetOk("allow_major_version_upgrade"); ok { // Having allowing_major_version_upgrade by itself should not trigger ModifyDBInstance // "InvalidParameterCombination: No modifications were requested". @@ -827,11 +834,6 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in requiresModifyDbInstance = true } } else if v, ok := d.GetOk("s3_import"); ok { - dbName := d.Get("db_name").(string) - if dbName == "" { - dbName = d.Get("name").(string) - } - if _, ok := d.GetOk("allocated_storage"); !ok { diags = sdkdiag.AppendErrorf(diags, `"allocated_storage": required field is not set`) } @@ -859,7 +861,7 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in CopyTagsToSnapshot: aws.Bool(d.Get("copy_tags_to_snapshot").(bool)), DBInstanceClass: aws.String(d.Get("instance_class").(string)), DBInstanceIdentifier: aws.String(identifier), - DBName: aws.String(dbName), + DBName: aws.String(d.Get("db_name").(string)), DeletionProtection: aws.Bool(d.Get("deletion_protection").(bool)), Engine: aws.String(d.Get("engine").(string)), EngineVersion: aws.String(d.Get("engine_version").(string)), @@ -970,7 +972,7 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in input.VpcSecurityGroupIds = flex.ExpandStringSet(v.(*schema.Set)) } - _, err := tfresource.RetryWhen(ctx, propagationTimeout, + outputRaw, err := tfresource.RetryWhen(ctx, propagationTimeout, func() (interface{}, error) { return conn.RestoreDBInstanceFromS3WithContext(ctx, input) }, @@ -995,6 +997,11 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in if err != nil { return sdkdiag.AppendErrorf(diags, "creating RDS DB Instance (restore from S3) (%s): %s", identifier, err) } + + if outputRaw != nil { + output := outputRaw.(*rds.RestoreDBInstanceFromS3Output) + resourceID = aws.StringValue(output.DBInstance.DbiResourceId) + } } else if v, ok := d.GetOk("snapshot_identifier"); ok { input := &rds.RestoreDBInstanceFromDBSnapshotInput{ AutoMinorVersionUpgrade: aws.Bool(d.Get("auto_minor_version_upgrade").(bool)), @@ -1017,15 +1024,6 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in default: input.DBName = aws.String(v.(string)) } - } else if v, ok := d.GetOk("name"); ok { - // "Note: This parameter [DBName] doesn't apply to the MySQL, PostgreSQL, or MariaDB engines." - // https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_RestoreDBInstanceFromDBSnapshot.html - switch engine { - case InstanceEngineMySQL, InstanceEnginePostgres, InstanceEngineMariaDB: - // skip - default: - input.DBName = aws.String(v.(string)) - } } if v, ok := d.GetOk("allocated_storage"); ok { @@ -1186,7 +1184,7 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in input.VpcSecurityGroupIds = flex.ExpandStringSet(v) } - _, err := tfresource.RetryWhen(ctx, propagationTimeout, + outputRaw, err := tfresource.RetryWhen(ctx, propagationTimeout, func() (interface{}, error) { return conn.RestoreDBInstanceFromDBSnapshotWithContext(ctx, input) }, @@ -1217,6 +1215,11 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in if err != nil { return sdkdiag.AppendErrorf(diags, "creating RDS DB Instance (restore from snapshot) (%s): %s", identifier, err) } + + if outputRaw != nil { + output := outputRaw.(*rds.RestoreDBInstanceFromDBSnapshotOutput) + resourceID = aws.StringValue(output.DBInstance.DbiResourceId) + } } else if v, ok := d.GetOk("restore_to_point_in_time"); ok { tfMap := v.([]interface{})[0].(map[string]interface{}) @@ -1266,8 +1269,6 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in if v, ok := d.GetOk("db_name"); ok { input.DBName = aws.String(v.(string)) - } else if v, ok := d.GetOk("name"); ok { - input.DBName = aws.String(v.(string)) } if v, ok := d.GetOk("db_subnet_group_name"); ok { @@ -1348,7 +1349,7 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in input.VpcSecurityGroupIds = flex.ExpandStringSet(v.(*schema.Set)) } - _, err := tfresource.RetryWhen(ctx, propagationTimeout, + outputRaw, err := tfresource.RetryWhen(ctx, propagationTimeout, func() (interface{}, error) { return conn.RestoreDBInstanceToPointInTimeWithContext(ctx, input) }, @@ -1363,12 +1364,12 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in if err != nil { return sdkdiag.AppendErrorf(diags, "creating RDS DB Instance (restore to point-in-time) (%s): %s", identifier, err) } - } else { - dbName := d.Get("db_name").(string) - if dbName == "" { - dbName = d.Get("name").(string) - } + if outputRaw != nil { + output := outputRaw.(*rds.RestoreDBInstanceToPointInTimeOutput) + resourceID = aws.StringValue(output.DBInstance.DbiResourceId) + } + } else { if _, ok := d.GetOk("allocated_storage"); !ok { diags = sdkdiag.AppendErrorf(diags, `"allocated_storage": required field is not set`) } @@ -1389,7 +1390,7 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in CopyTagsToSnapshot: aws.Bool(d.Get("copy_tags_to_snapshot").(bool)), DBInstanceClass: aws.String(d.Get("instance_class").(string)), DBInstanceIdentifier: aws.String(identifier), - DBName: aws.String(dbName), + DBName: aws.String(d.Get("db_name").(string)), DeletionProtection: aws.Bool(d.Get("deletion_protection").(bool)), Engine: aws.String(d.Get("engine").(string)), EngineVersion: aws.String(d.Get("engine_version").(string)), @@ -1551,6 +1552,7 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in } output := outputRaw.(*rds.CreateDBInstanceOutput) + resourceID = aws.StringValue(output.DBInstance.DbiResourceId) // This is added here to avoid unnecessary modification when ca_cert_identifier is the default one if v, ok := d.GetOk("ca_cert_identifier"); ok && v.(string) != aws.StringValue(output.DBInstance.CACertificateIdentifier) { @@ -1559,35 +1561,41 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in } } - d.SetId(identifier) + var instance *rds.DBInstance + var err error + if instance, err = waitDBInstanceAvailableSDKv1(ctx, conn, d.Get("identifier").(string), d.Timeout(schema.TimeoutCreate)); err != nil { + return sdkdiag.AppendErrorf(diags, "waiting for RDS DB Instance (%s) create: %s", identifier, err) + } - if _, err := waitDBInstanceAvailableSDKv1(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return sdkdiag.AppendErrorf(diags, "waiting for RDS DB Instance (%s) create: %s", d.Id(), err) + if resourceID == "" { + resourceID = aws.StringValue(instance.DbiResourceId) } + d.SetId(resourceID) + if requiresModifyDbInstance { - modifyDbInstanceInput.DBInstanceIdentifier = aws.String(d.Id()) + modifyDbInstanceInput.DBInstanceIdentifier = aws.String(identifier) _, err := conn.ModifyDBInstanceWithContext(ctx, modifyDbInstanceInput) if err != nil { - return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", identifier, err) } if _, err := waitDBInstanceAvailableSDKv1(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return sdkdiag.AppendErrorf(diags, "waiting for RDS DB Instance (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for RDS DB Instance (%s) update: %s", identifier, err) } } if requiresRebootDbInstance { _, err := conn.RebootDBInstanceWithContext(ctx, &rds.RebootDBInstanceInput{ - DBInstanceIdentifier: aws.String(d.Id()), + DBInstanceIdentifier: aws.String(identifier), }) if err != nil { - return sdkdiag.AppendErrorf(diags, "rebooting RDS DB Instance (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "rebooting RDS DB Instance (%s): %s", identifier, err) } if _, err := waitDBInstanceAvailableSDKv1(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return sdkdiag.AppendErrorf(diags, "waiting for RDS DB Instance (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for RDS DB Instance (%s) update: %s", identifier, err) } } @@ -1600,18 +1608,17 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta inte v, err := findDBInstanceByIDSDKv1(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { - log.Printf("[WARN] RDS DB Instance (%s) not found, removing from state", d.Id()) + log.Printf("[WARN] RDS DB Instance (%s) not found, removing from state", d.Get("identifier").(string)) d.SetId("") return nil } if err != nil { - return sdkdiag.AppendErrorf(diags, "reading RDS DB Instance (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading RDS DB Instance (%s): %s", d.Get("identifier").(string), err) } d.Set("allocated_storage", v.AllocatedStorage) - arn := aws.StringValue(v.DBInstanceArn) - d.Set("arn", arn) + d.Set("arn", v.DBInstanceArn) d.Set("auto_minor_version_upgrade", v.AutoMinorVersionUpgrade) d.Set("availability_zone", v.AvailabilityZone) d.Set("backup_retention_period", v.BackupRetentionPeriod) @@ -1671,7 +1678,6 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta inte d.Set("monitoring_interval", v.MonitoringInterval) d.Set("monitoring_role_arn", v.MonitoringRoleArn) d.Set("multi_az", v.MultiAZ) - d.Set("name", v.DBName) d.Set("nchar_character_set_name", v.NcharCharacterSetName) d.Set("network_type", v.NetworkType) if len(v.OptionGroupMemberships) > 0 && v.OptionGroupMemberships[0] != nil { @@ -1734,7 +1740,7 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta in if d.Get("replicate_source_db").(string) == "" { input := &rds_sdkv2.PromoteReadReplicaInput{ BackupRetentionPeriod: aws.Int32(int32(d.Get("backup_retention_period").(int))), - DBInstanceIdentifier: aws.String(d.Id()), + DBInstanceIdentifier: aws.String(d.Get("identifier").(string)), } if attr, ok := d.GetOk("backup_window"); ok { @@ -1743,11 +1749,11 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta in _, err := conn.PromoteReadReplica(ctx, input) if err != nil { - return sdkdiag.AppendErrorf(diags, "promoting RDS DB Instance (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "promoting RDS DB Instance (%s): %s", d.Get("identifier").(string), err) } if _, err := waitDBInstanceAvailableSDKv2(ctx, conn, d.Id(), deadline.Remaining()); err != nil { - return sdkdiag.AppendErrorf(diags, "promoting RDS DB Instance (%s): waiting for completion: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "promoting RDS DB Instance (%s): waiting for completion: %s", d.Get("identifier").(string), err) } } else { return sdkdiag.AppendErrorf(diags, "cannot elect new source database for replication") @@ -1785,23 +1791,24 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta in err := handler.precondition(ctx, d) if err != nil { - return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Get("identifier").(string), err) } createIn := handler.createBlueGreenInput(d) - log.Printf("[DEBUG] Updating RDS DB Instance (%s): Creating Blue/Green Deployment", d.Id()) + log.Printf("[DEBUG] Updating RDS DB Instance (%s): Creating Blue/Green Deployment", d.Get("identifier").(string)) dep, err := orchestrator.createDeployment(ctx, createIn) if err != nil { - return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Get("identifier").(string), err) } + deploymentIdentifier := dep.BlueGreenDeploymentIdentifier defer func() { - log.Printf("[DEBUG] Updating RDS DB Instance (%s): Deleting Blue/Green Deployment", d.Id()) + log.Printf("[DEBUG] Updating RDS DB Instance (%s): Deleting Blue/Green Deployment", d.Get("identifier").(string)) if dep == nil { - log.Printf("[DEBUG] Updating RDS DB Instance (%s): Deleting Blue/Green Deployment: deployment disappeared", d.Id()) + log.Printf("[DEBUG] Updating RDS DB Instance (%s): Deleting Blue/Green Deployment: deployment disappeared", d.Get("identifier").(string)) return } @@ -1814,49 +1821,58 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta in } _, err = conn.DeleteBlueGreenDeployment(ctx, input) if err != nil { - diags = sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): deleting Blue/Green Deployment: %s", d.Id(), err) + diags = sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): deleting Blue/Green Deployment: %s", d.Get("identifier").(string), err) return } cleaupWaiters = append(cleaupWaiters, func(optFns ...tfresource.OptionsFunc) { _, err = waitBlueGreenDeploymentDeleted(ctx, conn, aws.StringValue(deploymentIdentifier), deadline.Remaining(), optFns...) if err != nil { - diags = sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): deleting Blue/Green Deployment: waiting for completion: %s", d.Id(), err) + diags = sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): deleting Blue/Green Deployment: waiting for completion: %s", d.Get("identifier").(string), err) } }) }() dep, err = orchestrator.waitForDeploymentAvailable(ctx, aws.StringValue(dep.BlueGreenDeploymentIdentifier), deadline.Remaining()) if err != nil { - return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Get("identifier").(string), err) } targetARN, err := parseDBInstanceARN(aws.StringValue(dep.Target)) if err != nil { - return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): creating Blue/Green Deployment: waiting for Green environment: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): creating Blue/Green Deployment: waiting for Green environment: %s", d.Get("identifier").(string), err) } _, err = waitDBInstanceAvailableSDKv2(ctx, conn, targetARN.Identifier, deadline.Remaining()) if err != nil { - return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): creating Blue/Green Deployment: waiting for Green environment: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): creating Blue/Green Deployment: waiting for Green environment: %s", d.Get("identifier").(string), err) } - err = handler.modifyTarget(ctx, targetARN.Identifier, d, deadline.Remaining(), fmt.Sprintf("Updating RDS DB Instance (%s)", d.Id())) + err = handler.modifyTarget(ctx, targetARN.Identifier, d, deadline.Remaining(), fmt.Sprintf("Updating RDS DB Instance (%s)", d.Get("identifier").(string))) if err != nil { - return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Get("identifier").(string), err) } - log.Printf("[DEBUG] Updating RDS DB Instance (%s): Switching over Blue/Green Deployment", d.Id()) + log.Printf("[DEBUG] Updating RDS DB Instance (%s): Switching over Blue/Green Deployment", d.Get("identifier").(string)) dep, err = orchestrator.switchover(ctx, aws.StringValue(dep.BlueGreenDeploymentIdentifier), deadline.Remaining()) if err != nil { - return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Get("identifier").(string), err) + } + + target, err := findDBInstanceByIDSDKv2(ctx, conn, d.Get("identifier").(string)) + if err != nil { + return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Get("identifier").(string), err) } - log.Printf("[DEBUG] Updating RDS DB Instance (%s): Deleting Blue/Green Deployment source", d.Id()) + // id changes here + d.SetId(aws.StringValue(target.DbiResourceId)) + d.Set("resource_id", target.DbiResourceId) + + log.Printf("[DEBUG] Updating RDS DB Instance (%s): Deleting Blue/Green Deployment source", d.Get("identifier").(string)) sourceARN, err := parseDBInstanceARN(aws.StringValue(dep.Source)) if err != nil { - return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): deleting Blue/Green Deployment source: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): deleting Blue/Green Deployment source: %s", d.Get("identifier").(string), err) } if d.Get("deletion_protection").(bool) { input := &rds_sdkv2.ModifyDBInstanceInput{ @@ -1864,9 +1880,9 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta in DBInstanceIdentifier: aws.String(sourceARN.Identifier), DeletionProtection: aws.Bool(false), } - err := dbInstanceModify(ctx, conn, input, deadline.Remaining()) + err := dbInstanceModify(ctx, conn, d.Id(), input, deadline.Remaining()) if err != nil { - return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): deleting Blue/Green Deployment source: disabling deletion protection: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): deleting Blue/Green Deployment source: disabling deletion protection: %s", d.Get("identifier").(string), err) } } deleteInput := &rds_sdkv2.DeleteDBInstanceInput{ @@ -1892,13 +1908,13 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta in }, ) if err != nil { - return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): deleting Blue/Green Deployment source: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): deleting Blue/Green Deployment source: %s", d.Get("identifier").(string), err) } cleaupWaiters = append(cleaupWaiters, func(optFns ...tfresource.OptionsFunc) { _, err = waitDBInstanceDeleted(ctx, meta.(*conns.AWSClient).RDSConn(), sourceARN.Identifier, deadline.Remaining(), optFns...) if err != nil { - diags = sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): deleting Blue/Green Deployment source: waiting for completion: %s", d.Id(), err) + diags = sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): deleting Blue/Green Deployment source: waiting for completion: %s", d.Get("identifier").(string), err) } }) @@ -1906,9 +1922,14 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta in return } } else { + oldID := d.Get("identifier").(string) + if d.HasChange("identifier") { + o, _ := d.GetChange("identifier") + oldID = o.(string) + } input := &rds_sdkv2.ModifyDBInstanceInput{ ApplyImmediately: d.Get("apply_immediately").(bool), - DBInstanceIdentifier: aws.String(d.Id()), + DBInstanceIdentifier: aws.String(oldID), } if !input.ApplyImmediately { @@ -1929,9 +1950,9 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta in input.DBParameterGroupName = aws.String(d.Get("parameter_group_name").(string)) } - err := dbInstanceModify(ctx, conn, input, deadline.Remaining()) + err := dbInstanceModify(ctx, conn, d.Id(), input, deadline.Remaining()) if err != nil { - return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Get("identifier").(string), err) } } } @@ -2019,6 +2040,11 @@ func dbInstancePopulateModify(input *rds_sdkv2.ModifyDBInstanceInput, d *schema. input.EnableIAMDatabaseAuthentication = aws.Bool(d.Get("iam_database_authentication_enabled").(bool)) } + if d.HasChange("identifier") { + needsModify = true + input.NewDBInstanceIdentifier = aws.String(d.Get("identifier").(string)) + } + if d.HasChange("instance_class") { needsModify = true input.DBInstanceClass = aws.String(d.Get("instance_class").(string)) @@ -2147,7 +2173,7 @@ func dbInstancePopulateModify(input *rds_sdkv2.ModifyDBInstanceInput, d *schema. return needsModify } -func dbInstanceModify(ctx context.Context, conn *rds_sdkv2.Client, input *rds_sdkv2.ModifyDBInstanceInput, timeout time.Duration) error { +func dbInstanceModify(ctx context.Context, conn *rds_sdkv2.Client, resourceID string, input *rds_sdkv2.ModifyDBInstanceInput, timeout time.Duration) error { _, err := tfresource.RetryWhen(ctx, timeout, func() (interface{}, error) { return conn.ModifyDBInstance(ctx, input) @@ -2170,7 +2196,7 @@ func dbInstanceModify(ctx context.Context, conn *rds_sdkv2.Client, input *rds_sd return err } - if _, err := waitDBInstanceAvailableSDKv2(ctx, conn, aws.StringValue(input.DBInstanceIdentifier), timeout); err != nil { + if _, err := waitDBInstanceAvailableSDKv2(ctx, conn, resourceID, timeout); err != nil { return fmt.Errorf("waiting for completion: %w", err) } return nil @@ -2180,7 +2206,7 @@ func resourceInstanceDelete(ctx context.Context, d *schema.ResourceData, meta in conn := meta.(*conns.AWSClient).RDSConn() input := &rds.DeleteDBInstanceInput{ - DBInstanceIdentifier: aws.String(d.Id()), + DBInstanceIdentifier: aws.String(d.Get("identifier").(string)), DeleteAutomatedBackups: aws.Bool(d.Get("delete_automated_backups").(bool)), } @@ -2196,7 +2222,7 @@ func resourceInstanceDelete(ctx context.Context, d *schema.ResourceData, meta in } } - log.Printf("[DEBUG] Deleting RDS DB Instance: %s", d.Id()) + log.Printf("[DEBUG] Deleting RDS DB Instance: %s", d.Get("identifier").(string)) _, err := conn.DeleteDBInstanceWithContext(ctx, input) if tfawserr.ErrMessageContains(err, errCodeInvalidParameterCombination, "disable deletion pro") { @@ -2205,7 +2231,7 @@ func resourceInstanceDelete(ctx context.Context, d *schema.ResourceData, meta in func() (interface{}, error) { return conn.ModifyDBInstanceWithContext(ctx, &rds.ModifyDBInstanceInput{ ApplyImmediately: aws.Bool(true), - DBInstanceIdentifier: aws.String(d.Id()), + DBInstanceIdentifier: aws.String(d.Get("identifier").(string)), DeletionProtection: aws.Bool(false), }) }, @@ -2225,11 +2251,11 @@ func resourceInstanceDelete(ctx context.Context, d *schema.ResourceData, meta in ) if ierr != nil { - return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RDS DB Instance (%s): %s", d.Get("identifier").(string), err) } if _, ierr := waitDBInstanceAvailableSDKv1(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); ierr != nil { - return sdkdiag.AppendErrorf(diags, "waiting for RDS DB Instance (%s) update: %s", d.Id(), ierr) + return sdkdiag.AppendErrorf(diags, "waiting for RDS DB Instance (%s) update: %s", d.Get("identifier").(string), ierr) } _, err = conn.DeleteDBInstanceWithContext(ctx, input) @@ -2241,11 +2267,11 @@ func resourceInstanceDelete(ctx context.Context, d *schema.ResourceData, meta in } if err != nil && !tfawserr.ErrMessageContains(err, rds.ErrCodeInvalidDBInstanceStateFault, "is already being deleted") { - return sdkdiag.AppendErrorf(diags, "deleting RDS DB Instance (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting RDS DB Instance (%s): %s", d.Get("identifier").(string), err) } if _, err := waitDBInstanceDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return sdkdiag.AppendErrorf(diags, "waiting for RDS DB Instance (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for RDS DB Instance (%s) delete: %s", d.Get("identifier").(string), err) } return nil @@ -2311,12 +2337,33 @@ func parseDBInstanceARN(s string) (dbInstanceARN, error) { return result, nil } +// findDBInstanceByIDSDKv1 in general should be called with a DbiResourceId of the form +// "db-BE6UI2KLPQP3OVDYD74ZEV6NUM" rather than a DB identifier. However, in some cases only +// the identifier is available, and can be used. func findDBInstanceByIDSDKv1(ctx context.Context, conn *rds.RDS, id string) (*rds.DBInstance, error) { - input := &rds.DescribeDBInstancesInput{ - DBInstanceIdentifier: aws.String(id), + input := &rds.DescribeDBInstancesInput{} + + if regexp.MustCompile(`^db-[a-zA-Z0-9]{2,255}$`).MatchString(id) { + input.Filters = []*rds.Filter{ + { + Name: aws.String("dbi-resource-id"), + Values: aws.StringSlice([]string{id}), + }, + } + } else { + input.DBInstanceIdentifier = aws.String(id) } output, err := conn.DescribeDBInstancesWithContext(ctx, input) + + // in case a DB has an *identifier* starting with "db-"" + if regexp.MustCompile(`^db-[a-zA-Z0-9]{2,255}$`).MatchString(id) && (output == nil || len(output.DBInstances) == 0) { + input = &rds.DescribeDBInstancesInput{ + DBInstanceIdentifier: aws.String(id), + } + output, err = conn.DescribeDBInstancesWithContext(ctx, input) + } + if tfawserr.ErrCodeEquals(err, rds.ErrCodeDBInstanceNotFoundFault) { return nil, &retry.NotFoundError{ LastError: err, @@ -2336,12 +2383,33 @@ func findDBInstanceByIDSDKv1(ctx context.Context, conn *rds.RDS, id string) (*rd return dbInstance, nil } +// findDBInstanceByIDSDKv2 in general should be called with a DbiResourceId of the form +// "db-BE6UI2KLPQP3OVDYD74ZEV6NUM" rather than a DB identifier. However, in some cases only +// the identifier is available, and can be used. func findDBInstanceByIDSDKv2(ctx context.Context, conn *rds_sdkv2.Client, id string) (*types.DBInstance, error) { - input := &rds_sdkv2.DescribeDBInstancesInput{ - DBInstanceIdentifier: aws.String(id), + input := &rds_sdkv2.DescribeDBInstancesInput{} + + if regexp.MustCompile(`^db-[a-zA-Z0-9]{2,255}$`).MatchString(id) { + input.Filters = []types.Filter{ + { + Name: aws.String("dbi-resource-id"), + Values: []string{id}, + }, + } + } else { + input.DBInstanceIdentifier = aws.String(id) } output, err := conn.DescribeDBInstances(ctx, input) + + // in case a DB has an *identifier* starting with "db-"" + if regexp.MustCompile(`^db-[a-zA-Z0-9]{2,255}$`).MatchString(id) && (output == nil || len(output.DBInstances) == 0) { + input = &rds_sdkv2.DescribeDBInstancesInput{ + DBInstanceIdentifier: aws.String(id), + } + output, err = conn.DescribeDBInstances(ctx, input) + } + if errs.IsA[*types.DBInstanceNotFoundFault](err) { return nil, &retry.NotFoundError{ LastError: err, @@ -2391,7 +2459,7 @@ func statusDBInstanceSDKv2(ctx context.Context, conn *rds_sdkv2.Client, id strin } } -func waitDBInstanceAvailableSDKv1(ctx context.Context, conn *rds.RDS, id string, timeout time.Duration, optFns ...tfresource.OptionsFunc) (*rds.DBInstance, error) { //nolint:unparam +func waitDBInstanceAvailableSDKv1(ctx context.Context, conn *rds.RDS, id string, timeout time.Duration, optFns ...tfresource.OptionsFunc) (*rds.DBInstance, error) { options := tfresource.Options{ PollInterval: 10 * time.Second, Delay: 1 * time.Minute, diff --git a/internal/service/rds/instance_automated_backups_replication_test.go b/internal/service/rds/instance_automated_backups_replication_test.go index 41c94aee9ae..a06adcbb38b 100644 --- a/internal/service/rds/instance_automated_backups_replication_test.go +++ b/internal/service/rds/instance_automated_backups_replication_test.go @@ -171,7 +171,7 @@ resource "aws_db_instance" "test" { engine = "postgres" engine_version = "13.4" instance_class = "db.t3.micro" - name = "mydb" + db_name = "mydb" username = "masterusername" password = "mustbeeightcharacters" backup_retention_period = 7 diff --git a/internal/service/rds/instance_data_source_test.go b/internal/service/rds/instance_data_source_test.go index 3460a8de478..c40f7060150 100644 --- a/internal/service/rds/instance_data_source_test.go +++ b/internal/service/rds/instance_data_source_test.go @@ -113,7 +113,7 @@ resource "aws_db_instance" "test" { engine_version = data.aws_rds_engine_version.default.version identifier = %[1]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class - name = "test" + db_name = "test" password = "avoid-plaintext-passwords" skip_final_snapshot = true username = "tfacctest" @@ -148,7 +148,7 @@ resource "aws_db_instance" "test" { identifier = %[1]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class manage_master_user_password = true - name = "test" + db_name = "test" skip_final_snapshot = true username = "tfacctest" diff --git a/internal/service/rds/instance_migrate.go b/internal/service/rds/instance_migrate.go index a4e6eac49ae..d2551e34035 100644 --- a/internal/service/rds/instance_migrate.go +++ b/internal/service/rds/instance_migrate.go @@ -2,9 +2,17 @@ package rds import ( "context" + "fmt" + "regexp" + "strconv" + "strings" + "github.com/aws/aws-sdk-go/service/rds" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/verify" + "github.com/hashicorp/terraform-provider-aws/names" ) func resourceInstanceResourceV0() *schema.Resource { @@ -389,3 +397,539 @@ func InstanceStateUpgradeV0(_ context.Context, rawState map[string]interface{}, return rawState, nil } + +func resourceInstanceResourceV1() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "allocated_storage": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + mas := d.Get("max_allocated_storage").(int) + + newInt, err := strconv.Atoi(new) + if err != nil { + return false + } + + oldInt, err := strconv.Atoi(old) + if err != nil { + return false + } + + // Allocated is higher than the configuration + // and autoscaling is enabled + if oldInt > newInt && mas > newInt { + return true + } + + return false + }, + }, + "allow_major_version_upgrade": { + Type: schema.TypeBool, + Optional: true, + }, + // apply_immediately is used to determine when the update modifications + // take place. + // See http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.DBInstance.Modifying.html + "apply_immediately": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "arn": { + Type: schema.TypeString, + Computed: true, + }, + "auto_minor_version_upgrade": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "availability_zone": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "backup_retention_period": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + ValidateFunc: validation.IntBetween(0, 35), + }, + "backup_window": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: verify.ValidOnceADayWindowFormat, + }, + "blue_green_update": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "enabled": { + Type: schema.TypeBool, + Optional: true, + }, + }, + }, + }, + "ca_cert_identifier": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "character_set_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "copy_tags_to_snapshot": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "custom_iam_instance_profile": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringMatch(regexp.MustCompile(`^AWSRDSCustom.*$`), "must begin with AWSRDSCustom"), + }, + "customer_owned_ip_enabled": { + Type: schema.TypeBool, + Optional: true, + }, + "db_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ConflictsWith: []string{ + "replicate_source_db", + }, + }, + "db_subnet_group_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "delete_automated_backups": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "deletion_protection": { + Type: schema.TypeBool, + Optional: true, + }, + "domain": { + Type: schema.TypeString, + Optional: true, + }, + "domain_iam_role_name": { + Type: schema.TypeString, + Optional: true, + }, + "enabled_cloudwatch_logs_exports": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice(InstanceExportableLogType_Values(), false), + }, + }, + "endpoint": { + Type: schema.TypeString, + Computed: true, + }, + "engine": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + StateFunc: func(v interface{}) string { + value := v.(string) + return strings.ToLower(value) + }, + }, + "engine_version": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "engine_version_actual": { + Type: schema.TypeString, + Computed: true, + }, + "final_snapshot_identifier": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.All( + validation.StringMatch(regexp.MustCompile(`^[A-Za-z]`), "must begin with alphabetic character"), + validation.StringMatch(regexp.MustCompile(`^[0-9A-Za-z-]+$`), "must only contain alphanumeric characters and hyphens"), + validation.StringDoesNotMatch(regexp.MustCompile(`--`), "cannot contain two consecutive hyphens"), + validation.StringDoesNotMatch(regexp.MustCompile(`-$`), "cannot end in a hyphen"), + ), + }, + "hosted_zone_id": { + Type: schema.TypeString, + Computed: true, + }, + "iam_database_authentication_enabled": { + Type: schema.TypeBool, + Optional: true, + }, + "identifier": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ConflictsWith: []string{"identifier_prefix"}, + ValidateFunc: validIdentifier, + }, + "identifier_prefix": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ConflictsWith: []string{"identifier"}, + ValidateFunc: validIdentifierPrefix, + }, + "instance_class": { + Type: schema.TypeString, + Required: true, + }, + "iops": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "kms_key_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateFunc: verify.ValidARN, + }, + "latest_restorable_time": { + Type: schema.TypeString, + Computed: true, + }, + "license_model": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "listener_endpoint": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "hosted_zone_id": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "maintenance_window": { + Type: schema.TypeString, + Optional: true, + Computed: true, + StateFunc: func(v interface{}) string { + if v != nil { + value := v.(string) + return strings.ToLower(value) + } + return "" + }, + ValidateFunc: verify.ValidOnceAWeekWindowFormat, + }, + "manage_master_user_password": { + Type: schema.TypeBool, + Optional: true, + ConflictsWith: []string{"password"}, + }, + "master_user_secret": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kms_key_id": { + Type: schema.TypeString, + Computed: true, + }, + "secret_arn": { + Type: schema.TypeString, + Computed: true, + }, + "secret_status": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "master_user_secret_kms_key_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: verify.ValidKMSKeyID, + }, + "max_allocated_storage": { + Type: schema.TypeInt, + Optional: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + if old == "0" && new == fmt.Sprintf("%d", d.Get("allocated_storage").(int)) { + return true + } + return false + }, + }, + "monitoring_interval": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + ValidateFunc: validation.IntInSlice([]int{0, 1, 5, 10, 15, 30, 60}), + }, + "monitoring_role_arn": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: verify.ValidARN, + }, + "multi_az": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "nchar_character_set_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "network_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice(NetworkType_Values(), false), + }, + "option_group_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "parameter_group_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + ConflictsWith: []string{"manage_master_user_password"}, + }, + "performance_insights_enabled": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "performance_insights_kms_key_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: verify.ValidARN, + }, + "performance_insights_retention_period": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "publicly_accessible": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "replica_mode": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice(rds.ReplicaMode_Values(), false), + }, + "replicas": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "replicate_source_db": { + Type: schema.TypeString, + Optional: true, + }, + "resource_id": { + Type: schema.TypeString, + Computed: true, + }, + "restore_to_point_in_time": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + ForceNew: true, + ConflictsWith: []string{ + "s3_import", + "snapshot_identifier", + "replicate_source_db", + }, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "restore_time": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: verify.ValidUTCTimestamp, + ConflictsWith: []string{"restore_to_point_in_time.0.use_latest_restorable_time"}, + }, + "source_db_instance_automated_backups_arn": { + Type: schema.TypeString, + Optional: true, + }, + "source_db_instance_identifier": { + Type: schema.TypeString, + Optional: true, + }, + "source_dbi_resource_id": { + Type: schema.TypeString, + Optional: true, + }, + "use_latest_restorable_time": { + Type: schema.TypeBool, + Optional: true, + ConflictsWith: []string{"restore_to_point_in_time.0.restore_time"}, + }, + }, + }, + }, + "s3_import": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + ConflictsWith: []string{ + "snapshot_identifier", + "replicate_source_db", + }, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "bucket_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "bucket_prefix": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "ingestion_role": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "source_engine": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "source_engine_version": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + }, + }, + }, + "skip_final_snapshot": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "snapshot_identifier": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "storage_encrypted": { + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + }, + "storage_throughput": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "storage_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice(StorageType_Values(), false), + }, + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), + "timezone": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "username": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ConflictsWith: []string{"replicate_source_db"}, + }, + "vpc_security_group_ids": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + } +} + +func InstanceStateUpgradeV1(_ context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + if rawState == nil { + return nil, nil + } + + rawState["id"] = rawState["resource_id"] + + return rawState, nil +} diff --git a/internal/service/rds/instance_migrate_test.go b/internal/service/rds/instance_migrate_test.go index 50f534d154a..669448b980b 100644 --- a/internal/service/rds/instance_migrate_test.go +++ b/internal/service/rds/instance_migrate_test.go @@ -62,3 +62,61 @@ func TestInstanceStateUpgradeV0(t *testing.T) { }) } } + +func TestInstanceStateUpgradeV1(t *testing.T) { + ctx := acctest.Context(t) + t.Parallel() + + testCases := []struct { + Description string + InputState map[string]interface{} + ExpectedState map[string]interface{} + }{ + { + Description: "missing state", + InputState: nil, + ExpectedState: nil, + }, + { + Description: "change id to resource id", + InputState: map[string]interface{}{ + "allocated_storage": 10, + "engine": "mariadb", + "id": "my-test-instance", + "identifier": "my-test-instance", + "instance_class": "db.t2.micro", + "password": "avoid-plaintext-passwords", + "resource_id": "db-cnuap2ilnbmok4eunzklfvwjca", + "tags": map[string]interface{}{"key1": "value1"}, + "username": "tfacctest", + }, + ExpectedState: map[string]interface{}{ + "allocated_storage": 10, + "engine": "mariadb", + "id": "db-cnuap2ilnbmok4eunzklfvwjca", + "identifier": "my-test-instance", + "instance_class": "db.t2.micro", + "password": "avoid-plaintext-passwords", + "resource_id": "db-cnuap2ilnbmok4eunzklfvwjca", + "tags": map[string]interface{}{"key1": "value1"}, + "username": "tfacctest", + }, + }, + } + + for _, testCase := range testCases { + testCase := testCase + t.Run(testCase.Description, func(t *testing.T) { + t.Parallel() + + got, err := tfrds.InstanceStateUpgradeV1(ctx, testCase.InputState, nil) + if err != nil { + t.Fatalf("error migrating state: %s", err) + } + + if !reflect.DeepEqual(testCase.ExpectedState, got) { + t.Fatalf("\n\nexpected:\n\n%#v\n\ngot:\n\n%#v\n\n", testCase.ExpectedState, got) + } + }) + } +} diff --git a/internal/service/rds/instance_role_association_test.go b/internal/service/rds/instance_role_association_test.go index e7f14506df4..4e3aaac5bee 100644 --- a/internal/service/rds/instance_role_association_test.go +++ b/internal/service/rds/instance_role_association_test.go @@ -38,7 +38,7 @@ func TestAccRDSInstanceRoleAssociation_basic(t *testing.T) { Config: testAccInstanceRoleAssociationConfig_basic(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceRoleAssociationExists(ctx, resourceName, &dbInstanceRole1), - resource.TestCheckResourceAttrPair(resourceName, "db_instance_identifier", dbInstanceResourceName, "id"), + resource.TestCheckResourceAttrPair(resourceName, "db_instance_identifier", dbInstanceResourceName, "identifier"), resource.TestCheckResourceAttr(resourceName, "feature_name", "S3_INTEGRATION"), resource.TestCheckResourceAttrPair(resourceName, "role_arn", iamRoleResourceName, "arn"), ), @@ -167,7 +167,7 @@ func testAccCheckInstanceRoleAssociationDisappears(ctx context.Context, dbInstan func testAccInstanceRoleAssociationConfig_basic(rName string) string { return fmt.Sprintf(` resource "aws_db_instance_role_association" "test" { - db_instance_identifier = aws_db_instance.test.id + db_instance_identifier = aws_db_instance.test.identifier feature_name = "S3_INTEGRATION" role_arn = aws_iam_role.test.arn } diff --git a/internal/service/rds/instance_test.go b/internal/service/rds/instance_test.go index 70332e770c8..5c4b49ab0b3 100644 --- a/internal/service/rds/instance_test.go +++ b/internal/service/rds/instance_test.go @@ -69,7 +69,6 @@ func TestAccRDSInstance_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "listener_endpoint.#", "0"), resource.TestCheckResourceAttrSet(resourceName, "maintenance_window"), resource.TestCheckResourceAttr(resourceName, "max_allocated_storage", "0"), - resource.TestCheckResourceAttr(resourceName, "name", "test"), resource.TestMatchResourceAttr(resourceName, "option_group_name", regexp.MustCompile(`^default:mysql-\d`)), resource.TestMatchResourceAttr(resourceName, "parameter_group_name", regexp.MustCompile(`^default\.mysql\d`)), resource.TestCheckResourceAttr(resourceName, "port", "3306"), @@ -147,7 +146,6 @@ func TestAccRDSInstance_manage_password(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "maintenance_window"), resource.TestCheckResourceAttr(resourceName, "master_user_secret.#", "1"), resource.TestCheckResourceAttr(resourceName, "max_allocated_storage", "0"), - resource.TestCheckResourceAttr(resourceName, "name", "test"), resource.TestMatchResourceAttr(resourceName, "option_group_name", regexp.MustCompile(`^default:mysql-\d`)), resource.TestMatchResourceAttr(resourceName, "parameter_group_name", regexp.MustCompile(`^default\.mysql\d`)), resource.TestCheckResourceAttr(resourceName, "port", "3306"), @@ -335,46 +333,6 @@ func TestAccRDSInstance_tags(t *testing.T) { }) } -func TestAccRDSInstance_nameDeprecated(t *testing.T) { - ctx := acctest.Context(t) - if testing.Short() { - t.Skip("skipping long-running test in short mode") - } - - var v rds.DBInstance - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_db_instance.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckInstanceDestroy(ctx), - Steps: []resource.TestStep{ - { - Config: testAccInstanceConfig_nameDeprecated(rName), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckInstanceExists(ctx, resourceName, &v), - resource.TestCheckResourceAttr(resourceName, "db_name", "test"), - resource.TestCheckResourceAttr(resourceName, "name", "test"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "apply_immediately", - "final_snapshot_identifier", - "password", - "skip_final_snapshot", - "delete_automated_backups", - }, - }, - }, - }) -} - func TestAccRDSInstance_onlyMajorVersion(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { @@ -678,7 +636,7 @@ func TestAccRDSInstance_dbSubnetGroupName(t *testing.T) { Config: testAccInstanceConfig_dbSubnetGroupName(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbInstance), - testAccCheckSubnetGroupExists(ctx, resourceName, &dbSubnetGroup), + testAccCheckSubnetGroupExists(ctx, dbSubnetGroupResourceName, &dbSubnetGroup), resource.TestCheckResourceAttrPair(resourceName, "db_subnet_group_name", dbSubnetGroupResourceName, "name"), ), }, @@ -740,7 +698,7 @@ func TestAccRDSInstance_DBSubnetGroupName_vpcSecurityGroupIDs(t *testing.T) { Config: testAccInstanceConfig_DBSubnetGroupName_vpcSecurityGroupIDs(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbInstance), - testAccCheckSubnetGroupExists(ctx, resourceName, &dbSubnetGroup), + testAccCheckSubnetGroupExists(ctx, dbSubnetGroupResourceName, &dbSubnetGroup), resource.TestCheckResourceAttrPair(resourceName, "db_subnet_group_name", dbSubnetGroupResourceName, "name"), ), }, @@ -1149,7 +1107,7 @@ func TestAccRDSInstance_ReplicateSourceDB_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "identifier", rName), resource.TestCheckResourceAttr(resourceName, "identifier_prefix", ""), testAccCheckInstanceReplicaAttributes(&sourceDbInstance, &dbInstance), - resource.TestCheckResourceAttrPair(resourceName, "name", sourceResourceName, "name"), + resource.TestCheckResourceAttrPair(resourceName, "db_name", sourceResourceName, "db_name"), resource.TestCheckResourceAttrPair(resourceName, "username", sourceResourceName, "username"), ), }, @@ -1169,7 +1127,7 @@ func TestAccRDSInstance_ReplicateSourceDB_basic(t *testing.T) { testAccCheckInstanceExists(ctx, resourceName, &dbInstance), resource.TestCheckResourceAttr(resourceName, "identifier", rName), resource.TestCheckResourceAttr(resourceName, "replicate_source_db", ""), - resource.TestCheckResourceAttrPair(resourceName, "name", sourceResourceName, "name"), + resource.TestCheckResourceAttrPair(resourceName, "db_name", sourceResourceName, "db_name"), resource.TestCheckResourceAttrPair(resourceName, "username", sourceResourceName, "username"), ), }, @@ -1572,7 +1530,7 @@ func TestAccRDSInstance_ReplicateSourceDB_dbSubnetGroupName(t *testing.T) { Config: testAccInstanceConfig_ReplicateSourceDB_dbSubnetGroupName(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbInstance), - testAccCheckSubnetGroupExists(ctx, resourceName, &dbSubnetGroup), + testAccCheckSubnetGroupExists(ctx, dbSubnetGroupResourceName, &dbSubnetGroup), resource.TestCheckResourceAttrPair(resourceName, "db_subnet_group_name", dbSubnetGroupResourceName, "name"), ), }, @@ -1642,7 +1600,7 @@ func TestAccRDSInstance_ReplicateSourceDBDBSubnetGroupName_vpcSecurityGroupIDs(t Config: testAccInstanceConfig_ReplicateSourceDB_DBSubnetGroupName_vpcSecurityGroupIDs(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbInstance), - testAccCheckSubnetGroupExists(ctx, resourceName, &dbSubnetGroup), + testAccCheckSubnetGroupExists(ctx, dbSubnetGroupResourceName, &dbSubnetGroup), resource.TestCheckResourceAttrPair(resourceName, "db_subnet_group_name", dbSubnetGroupResourceName, "name"), ), }, @@ -2323,7 +2281,7 @@ func TestAccRDSInstance_SnapshotIdentifier_basic(t *testing.T) { 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, "db_name", sourceDbResourceName, "db_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"), @@ -2742,7 +2700,7 @@ func TestAccRDSInstance_SnapshotIdentifier_dbSubnetGroupName(t *testing.T) { testAccCheckInstanceExists(ctx, sourceDbResourceName, &sourceDbInstance), testAccCheckDBSnapshotExists(ctx, snapshotResourceName, &dbSnapshot), testAccCheckInstanceExists(ctx, resourceName, &dbInstance), - testAccCheckSubnetGroupExists(ctx, resourceName, &dbSubnetGroup), + testAccCheckSubnetGroupExists(ctx, dbSubnetGroupResourceName, &dbSubnetGroup), resource.TestCheckResourceAttrPair(resourceName, "db_subnet_group_name", dbSubnetGroupResourceName, "name"), ), }, @@ -2818,7 +2776,7 @@ func TestAccRDSInstance_SnapshotIdentifier_dbSubnetGroupNameVPCSecurityGroupIDs( testAccCheckInstanceExists(ctx, sourceDbResourceName, &sourceDbInstance), testAccCheckDBSnapshotExists(ctx, snapshotResourceName, &dbSnapshot), testAccCheckInstanceExists(ctx, resourceName, &dbInstance), - testAccCheckSubnetGroupExists(ctx, resourceName, &dbSubnetGroup), + testAccCheckSubnetGroupExists(ctx, dbSubnetGroupResourceName, &dbSubnetGroup), resource.TestCheckResourceAttrPair(resourceName, "db_subnet_group_name", dbSubnetGroupResourceName, "name"), ), }, @@ -3695,8 +3653,8 @@ func TestAccRDSInstance_MySQL_snapshotRestoreWithEngineVersion(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, restoreResourceName, &vRestoredInstance), testAccCheckInstanceExists(ctx, resourceName, &v), - // Hardcoded older version. Will to update when no longer compatible to upgrade from this to the default version. - resource.TestCheckResourceAttr(resourceName, "engine_version", "8.0.25"), + // Hardcoded older version. Will need to update when no longer compatible to upgrade from this to the default version. + resource.TestCheckResourceAttr(resourceName, "engine_version", "8.0.31"), resource.TestCheckResourceAttrPair(restoreResourceName, "engine_version", "data.aws_rds_engine_version.default", "version"), ), }, @@ -4929,11 +4887,12 @@ func TestAccRDSInstance_BlueGreenDeployment_updateAndPromoteReplica(t *testing.T ImportStateVerify: true, ImportStateVerifyIgnore: []string{ "apply_immediately", + "blue_green_update", + "delete_automated_backups", "final_snapshot_identifier", + "latest_restorable_time", "password", "skip_final_snapshot", - "delete_automated_backups", - "blue_green_update", }, }, }, @@ -5394,6 +5353,47 @@ func TestAccRDSInstance_storageTypePostgres(t *testing.T) { }) } +func TestAccRDSInstance_newIdentifier(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var v1, v2 rds.DBInstance + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckInstanceDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccInstanceConfig_basic(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckInstanceExists(ctx, resourceName, &v1), + resource.TestCheckResourceAttr(resourceName, "identifier", rName), + ), + }, + { + Config: testAccInstanceConfig_basic(rName2), + PlanOnly: true, + ExpectNonEmptyPlan: true, // diff if apply_immediately = false + }, + { + Config: testAccInstanceConfig_basicApplyImmediately(rName2), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckInstanceExists(ctx, resourceName, &v2), + testAccCheckDBInstanceNotRecreated(&v1, &v2), + resource.TestCheckResourceAttr(resourceName, "identifier", rName2), + ), + }, + }, + }) +} + func testAccCheckInstanceAutomatedBackupsDelete(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).RDSConn() @@ -5405,17 +5405,17 @@ func testAccCheckInstanceAutomatedBackupsDelete(ctx context.Context) resource.Te log.Printf("[INFO] Trying to locate the DBInstance Automated Backup") describeOutput, err := conn.DescribeDBInstanceAutomatedBackupsWithContext(ctx, &rds.DescribeDBInstanceAutomatedBackupsInput{ - DBInstanceIdentifier: aws.String(rs.Primary.ID), + DBInstanceIdentifier: aws.String(rs.Primary.Attributes["identifier"]), }) if err != nil { return err } if describeOutput == nil || len(describeOutput.DBInstanceAutomatedBackups) == 0 { - return fmt.Errorf("Automated backup for %s not found", rs.Primary.ID) + return fmt.Errorf("Automated backup for %s not found", rs.Primary.Attributes["identifier"]) } - log.Printf("[INFO] Deleting automated backup for %s", rs.Primary.ID) + log.Printf("[INFO] Deleting automated backup for %s", rs.Primary.Attributes["identifier"]) _, err = conn.DeleteDBInstanceAutomatedBackupWithContext(ctx, &rds.DeleteDBInstanceAutomatedBackupInput{ DbiResourceId: describeOutput.DBInstanceAutomatedBackups[0].DbiResourceId, }) @@ -5437,7 +5437,7 @@ func testAccCheckInstanceDestroy(ctx context.Context) resource.TestCheckFunc { continue } - _, err := tfrds.FindDBInstanceByID(ctx, conn, rs.Primary.ID) + _, err := tfrds.FindDBInstanceByID(ctx, conn, rs.Primary.Attributes["identifier"]) if tfresource.NotFound(err) { continue @@ -5447,7 +5447,7 @@ func testAccCheckInstanceDestroy(ctx context.Context) resource.TestCheckFunc { return err } - return fmt.Errorf("RDS DB Instance %s still exists", rs.Primary.ID) + return fmt.Errorf("RDS DB Instance %s still exists", rs.Primary.Attributes["identifier"]) } return nil @@ -5567,7 +5567,7 @@ func testAccCheckInstanceDestroyWithFinalSnapshot(ctx context.Context) resource. return err } - _, err = tfrds.FindDBInstanceByID(ctx, conn, rs.Primary.ID) + _, err = tfrds.FindDBInstanceByID(ctx, conn, rs.Primary.Attributes["identifier"]) if tfresource.NotFound(err) { continue @@ -5577,7 +5577,7 @@ func testAccCheckInstanceDestroyWithFinalSnapshot(ctx context.Context) resource. return err } - return fmt.Errorf("RDS DB Instance %s still exists", rs.Primary.ID) + return fmt.Errorf("RDS DB Instance %s still exists", rs.Primary.Attributes["identifier"]) } return nil @@ -5607,7 +5607,7 @@ func testAccCheckInstanceDestroyWithoutFinalSnapshot(ctx context.Context) resour return fmt.Errorf("RDS DB Snapshot %s exists", finalSnapshotID) } - _, err = tfrds.FindDBInstanceByID(ctx, conn, rs.Primary.ID) + _, err = tfrds.FindDBInstanceByID(ctx, conn, rs.Primary.Attributes["identifier"]) if tfresource.NotFound(err) { continue @@ -5617,7 +5617,7 @@ func testAccCheckInstanceDestroyWithoutFinalSnapshot(ctx context.Context) resour return err } - return fmt.Errorf("RDS DB Instance %s still exists", rs.Primary.ID) + return fmt.Errorf("RDS DB Instance %s still exists", rs.Primary.Attributes["identifier"]) } return nil @@ -5657,7 +5657,7 @@ func testAccCheckInstanceExists(ctx context.Context, n string, v *rds.DBInstance return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { + if rs.Primary.Attributes["identifier"] == "" { return fmt.Errorf("No RDS DB Instance ID is set") } @@ -5752,6 +5752,32 @@ resource "aws_db_instance" "test" { `, rName)) } +func testAccInstanceConfig_basicApplyImmediately(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 + engine_version = data.aws_rds_orderable_db_instance.test.engine_version + instance_class = data.aws_rds_orderable_db_instance.test.instance_class + db_name = "test" + parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" + skip_final_snapshot = true + password = "avoid-plaintext-passwords" + username = "tfacctest" + apply_immediately = true + + # 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_manage_password(rName string) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMySQL(), @@ -5866,31 +5892,6 @@ resource "aws_db_instance" "test" { `, rName, tagKey1, tagValue1, tagKey2, tagValue2)) } -func testAccInstanceConfig_nameDeprecated(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 - engine_version = data.aws_rds_orderable_db_instance.test.engine_version - instance_class = data.aws_rds_orderable_db_instance.test.instance_class - name = "test" # deprecated - parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" - skip_final_snapshot = true - password = "avoid-plaintext-passwords" - username = "tfacctest" - - # 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(rName string) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMySQL(), @@ -6876,7 +6877,7 @@ resource "aws_db_instance" "origin" { } resource "aws_db_snapshot" "origin" { - db_instance_identifier = aws_db_instance.origin.id + db_instance_identifier = aws_db_instance.origin.identifier db_snapshot_identifier = %[1]q } @@ -6910,7 +6911,7 @@ func testAccInstanceConfig_mySQLSnapshotRestoreEngineVersion(rName string) strin resource "aws_db_instance" "test" { allocated_storage = 20 engine = data.aws_rds_engine_version.default.engine - engine_version = "8.0.25" # test is from older to newer version, update when restore from this to current default version is incompatible + engine_version = "8.0.31" # test is from older to newer version, update when restore from this to current default version is incompatible identifier = %[1]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class skip_final_snapshot = true @@ -6919,7 +6920,7 @@ resource "aws_db_instance" "test" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.test.id + db_instance_identifier = aws_db_instance.test.identifier db_snapshot_identifier = %[1]q } @@ -7471,7 +7472,7 @@ resource "aws_db_instance" "source" { resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName)) @@ -7518,7 +7519,7 @@ resource "aws_db_instance" "source" { resource "aws_db_instance" "test" { identifier_prefix = %[2]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, sourceName, identifierPrefix)) @@ -7541,7 +7542,7 @@ resource "aws_db_instance" "source" { resource "aws_db_instance" "test" { instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, sourceName)) @@ -7569,7 +7570,7 @@ func testAccInstanceConfig_ReplicateSourceDB_addLater(rName string) string { resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName)) @@ -7594,7 +7595,7 @@ resource "aws_db_instance" "test" { allocated_storage = %[2]d identifier = %[1]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName, allocatedStorage)) @@ -7618,7 +7619,7 @@ resource "aws_db_instance" "source" { resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true iops = %[2]d storage_type = "io1" @@ -7645,7 +7646,7 @@ resource "aws_db_instance" "test" { allocated_storage = %[2]d identifier = %[1]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true iops = %[3]d storage_type = "io1" @@ -7670,7 +7671,7 @@ resource "aws_db_instance" "test" { allow_major_version_upgrade = %[2]t identifier = %[1]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName, allowMajorVersionUpgrade)) @@ -7693,7 +7694,7 @@ resource "aws_db_instance" "test" { auto_minor_version_upgrade = %[2]t identifier = %[1]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName, autoMinorVersionUpgrade)) @@ -7719,7 +7720,7 @@ resource "aws_db_instance" "test" { availability_zone = data.aws_availability_zones.available.names[0] identifier = %[1]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName)) @@ -7742,7 +7743,7 @@ resource "aws_db_instance" "test" { backup_retention_period = %[2]d identifier = %[1]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName, backupRetentionPeriod)) @@ -7768,7 +7769,7 @@ resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class maintenance_window = %[3]q - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName, backupWindow, maintenanceWindow)) @@ -8199,7 +8200,7 @@ resource "aws_db_instance" "test" { deletion_protection = %[2]t identifier = %[1]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName, deletionProtection)) @@ -8222,7 +8223,7 @@ resource "aws_db_instance" "test" { iam_database_authentication_enabled = %[2]t identifier = %[1]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName, iamDatabaseAuthenticationEnabled)) @@ -8248,7 +8249,7 @@ resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class maintenance_window = %[3]q - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName, backupWindow, maintenanceWindow)) @@ -8272,7 +8273,7 @@ resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class max_allocated_storage = %[2]d - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName, maxAllocatedStorage)) @@ -8299,7 +8300,7 @@ resource "aws_db_instance" "test" { instance_class = aws_db_instance.source.instance_class monitoring_interval = %[2]d monitoring_role_arn = aws_iam_role.test.arn - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName, monitoringInterval)) @@ -8339,7 +8340,7 @@ resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class multi_az = %[2]t - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName, multiAz)) @@ -8371,7 +8372,7 @@ resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class network_type = %[2]q - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName, networkType)) @@ -8408,7 +8409,7 @@ resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class parameter_group_name = aws_db_parameter_group.test.id - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName)) @@ -8422,7 +8423,7 @@ resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class parameter_group_name = aws_db_parameter_group.test.id - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } @@ -8491,7 +8492,7 @@ resource "aws_db_instance" "source" { resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName)) @@ -8527,7 +8528,7 @@ resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class parameter_group_name = aws_db_parameter_group.test.id - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName)) @@ -8550,7 +8551,7 @@ resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class port = %[2]d - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName, port)) @@ -8581,7 +8582,7 @@ resource "aws_db_instance" "source" { resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true vpc_security_group_ids = [aws_security_group.test.id] } @@ -8611,7 +8612,7 @@ resource "aws_db_instance" "source" { resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier ca_cert_identifier = data.aws_rds_certificate.latest.id skip_final_snapshot = true } @@ -8650,7 +8651,7 @@ resource "aws_db_instance" "test" { identifier = %[2]q instance_class = aws_db_instance.source.instance_class replica_mode = %[3]q - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, oraclePreferredInstanceClasses, rName, replicaMode) @@ -8701,7 +8702,7 @@ func testAccInstanceConfig_ReplicateSourceDB_parameterGroupTwoStep(rName string) fmt.Sprintf(` resource "aws_db_instance" "test" { identifier = %[1]q - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier instance_class = data.aws_rds_orderable_db_instance.test.instance_class skip_final_snapshot = true @@ -8768,7 +8769,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -8796,7 +8797,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -8824,7 +8825,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -8851,7 +8852,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -8876,7 +8877,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -8894,7 +8895,7 @@ func testAccInstanceConfig_SnapshotID_io1Storage(rName string, iops int) string return fmt.Sprintf(` data "aws_rds_orderable_db_instance" "test" { engine = "mariadb" - engine_version = "10.5.12" + engine_version = "10.6.12" license_model = "general-public-license" storage_type = "io1" @@ -8912,7 +8913,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -8951,7 +8952,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -8989,7 +8990,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9019,7 +9020,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9046,7 +9047,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9074,7 +9075,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9103,7 +9104,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9134,7 +9135,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9235,7 +9236,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9275,7 +9276,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9303,7 +9304,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9330,7 +9331,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9359,7 +9360,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9387,7 +9388,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9442,7 +9443,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9470,7 +9471,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9500,7 +9501,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9542,7 +9543,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9571,7 +9572,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9604,7 +9605,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9640,7 +9641,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9677,7 +9678,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9713,7 +9714,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -9950,7 +9951,7 @@ resource "aws_db_instance" "test" { performance_insights_enabled = true performance_insights_kms_key_id = aws_kms_key.test.arn performance_insights_retention_period = 7 - replicate_source_db = aws_db_instance.source.id + replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } `, rName) @@ -10005,7 +10006,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.source.id + db_instance_identifier = aws_db_instance.source.identifier db_snapshot_identifier = %[1]q } @@ -10126,7 +10127,7 @@ resource "aws_db_instance" "restore" { func testAccInstanceConfig_CoIPEnabled_snapshotID(rName string, sourceCoipEnabled bool, targetCoipEnabled bool) string { return acctest.ConfigCompose(testAccInstanceConfig_Outpost_coIPEnabled(rName, sourceCoipEnabled, 1), fmt.Sprintf(` resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.test.id + db_instance_identifier = aws_db_instance.test.identifier db_snapshot_identifier = %[1]q } @@ -10220,7 +10221,7 @@ data "aws_rds_orderable_db_instance" "test" { data "aws_rds_engine_version" "initial" { engine = "mysql" - preferred_versions = ["8.0.27", "8.0.26", "8.0.25"] + preferred_versions = ["8.0.31", "8.0.30", "8.0.28"] } data "aws_rds_engine_version" "updated" { diff --git a/internal/service/rds/option_group_test.go b/internal/service/rds/option_group_test.go index ad2d02ee5a5..02676b9f0be 100644 --- a/internal/service/rds/option_group_test.go +++ b/internal/service/rds/option_group_test.go @@ -673,7 +673,7 @@ resource "aws_db_instance" "test" { engine = data.aws_rds_orderable_db_instance.test.engine engine_version = data.aws_rds_orderable_db_instance.test.engine_version instance_class = data.aws_rds_orderable_db_instance.test.instance_class - name = "baz" + db_name = "baz" password = "barbarbarbar" username = "foo" diff --git a/internal/service/rds/proxy_target_test.go b/internal/service/rds/proxy_target_test.go index 30b50489993..64ecaab07a4 100644 --- a/internal/service/rds/proxy_target_test.go +++ b/internal/service/rds/proxy_target_test.go @@ -303,7 +303,7 @@ func testAccProxyTargetConfig_instance(rName string) string { return acctest.ConfigCompose(testAccProxyTargetBaseConfig(rName), fmt.Sprintf(` data "aws_rds_engine_version" "test" { engine = "mysql" - preferred_versions = ["5.7.31", "5.7.30"] + preferred_versions = ["8.0.33", "8.0.32", "8.0.31"] } data "aws_rds_orderable_db_instance" "test" { @@ -330,7 +330,7 @@ resource "aws_db_instance" "test" { } resource "aws_db_proxy_target" "test" { - db_instance_identifier = aws_db_instance.test.id + db_instance_identifier = aws_db_instance.test.identifier db_proxy_name = aws_db_proxy.test.name target_group_name = "default" } diff --git a/internal/service/rds/snapshot_copy_test.go b/internal/service/rds/snapshot_copy_test.go index 0e382a05445..71aaea93c04 100644 --- a/internal/service/rds/snapshot_copy_test.go +++ b/internal/service/rds/snapshot_copy_test.go @@ -191,7 +191,7 @@ resource "aws_db_instance" "test" { engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version instance_class = data.aws_rds_orderable_db_instance.test.instance_class - name = "test" + db_name = "test" identifier = %[1]q password = "avoid-plaintext-passwords" username = "tfacctest" @@ -202,7 +202,7 @@ resource "aws_db_instance" "test" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.test.id + db_instance_identifier = aws_db_instance.test.identifier db_snapshot_identifier = "%[1]s-source" }`, rName) } diff --git a/internal/service/rds/snapshot_data_source_test.go b/internal/service/rds/snapshot_data_source_test.go index f20da960bb5..fc3d75d4d59 100644 --- a/internal/service/rds/snapshot_data_source_test.go +++ b/internal/service/rds/snapshot_data_source_test.go @@ -64,7 +64,7 @@ resource "aws_db_instance" "bar" { engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version instance_class = data.aws_rds_orderable_db_instance.test.instance_class - name = "baz" + db_name = "baz" password = "barbarbarbar" username = "foo" skip_final_snapshot = true @@ -85,7 +85,7 @@ data "aws_db_snapshot" "snapshot" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.bar.id + db_instance_identifier = aws_db_instance.bar.identifier db_snapshot_identifier = "testsnapshot%[2]d" } `, mySQLPreferredInstanceClasses, rInt) diff --git a/internal/service/rds/snapshot_test.go b/internal/service/rds/snapshot_test.go index 36aa99898c8..cecb7d5e8df 100644 --- a/internal/service/rds/snapshot_test.go +++ b/internal/service/rds/snapshot_test.go @@ -235,7 +235,7 @@ resource "aws_db_instance" "test" { engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version instance_class = data.aws_rds_orderable_db_instance.test.instance_class - name = "test" + db_name = "test" identifier = %[1]q password = "avoid-plaintext-passwords" username = "tfacctest" @@ -249,7 +249,7 @@ resource "aws_db_instance" "test" { func testAccSnapshotConfig_basic(rName string) string { return acctest.ConfigCompose(testAccSnapshotConfig_base(rName), fmt.Sprintf(` resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.test.id + db_instance_identifier = aws_db_instance.test.identifier db_snapshot_identifier = %[1]q } `, rName)) @@ -258,7 +258,7 @@ resource "aws_db_snapshot" "test" { func testAccSnapshotConfig_tags1(rName, tag1Key, tag1Value string) string { return acctest.ConfigCompose(testAccSnapshotConfig_base(rName), fmt.Sprintf(` resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.test.id + db_instance_identifier = aws_db_instance.test.identifier db_snapshot_identifier = %[1]q tags = { @@ -271,7 +271,7 @@ resource "aws_db_snapshot" "test" { func testAccSnapshotConfig_tags2(rName, tag1Key, tag1Value, tag2Key, tag2Value string) string { return acctest.ConfigCompose(testAccSnapshotConfig_base(rName), fmt.Sprintf(` resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.test.id + db_instance_identifier = aws_db_instance.test.identifier db_snapshot_identifier = %[1]q tags = { @@ -285,7 +285,7 @@ resource "aws_db_snapshot" "test" { func testAccSnapshotConfig_share(rName string) string { return acctest.ConfigCompose(testAccSnapshotConfig_base(rName), fmt.Sprintf(` resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.test.id + db_instance_identifier = aws_db_instance.test.identifier db_snapshot_identifier = %[1]q shared_accounts = ["all"] } diff --git a/internal/service/rds/sweep.go b/internal/service/rds/sweep.go index 469da99b07a..18b115cfb30 100644 --- a/internal/service/rds/sweep.go +++ b/internal/service/rds/sweep.go @@ -379,10 +379,11 @@ func sweepInstances(region string) error { for _, v := range page.DBInstances { r := ResourceInstance() d := r.Data(nil) - d.SetId(aws.StringValue(v.DBInstanceIdentifier)) + d.SetId(aws.StringValue(v.DbiResourceId)) d.Set("apply_immediately", true) d.Set("delete_automated_backups", true) d.Set("deletion_protection", false) + d.Set("identifier", v.DBInstanceIdentifier) d.Set("skip_final_snapshot", true) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) diff --git a/website/docs/d/db_snapshot.html.markdown b/website/docs/d/db_snapshot.html.markdown index 1705002f3fc..bd133abe2c6 100644 --- a/website/docs/d/db_snapshot.html.markdown +++ b/website/docs/d/db_snapshot.html.markdown @@ -21,7 +21,7 @@ resource "aws_db_instance" "prod" { engine = "mysql" engine_version = "5.6.17" instance_class = "db.t2.micro" - name = "mydb" + db_name = "mydb" username = "foo" password = "bar" db_subnet_group_name = "my_database_subnet_group" @@ -29,14 +29,14 @@ resource "aws_db_instance" "prod" { } data "aws_db_snapshot" "latest_prod_snapshot" { - db_instance_identifier = aws_db_instance.prod.id + db_instance_identifier = aws_db_instance.prod.identifier most_recent = true } # Use the latest production snapshot to create a dev instance. resource "aws_db_instance" "dev" { instance_class = "db.t2.micro" - name = "mydbdev" + db_name = "mydbdev" snapshot_identifier = data.aws_db_snapshot.latest_prod_snapshot.id lifecycle { diff --git a/website/docs/r/db_event_subscription.html.markdown b/website/docs/r/db_event_subscription.html.markdown index 485437b0fcd..ff18234bc3a 100644 --- a/website/docs/r/db_event_subscription.html.markdown +++ b/website/docs/r/db_event_subscription.html.markdown @@ -18,7 +18,7 @@ resource "aws_db_instance" "default" { engine = "mysql" engine_version = "5.6.17" instance_class = "db.t2.micro" - name = "mydb" + db_name = "mydb" username = "foo" password = "bar" db_subnet_group_name = "my_database_subnet_group" @@ -34,7 +34,7 @@ resource "aws_db_event_subscription" "default" { sns_topic = aws_sns_topic.default.arn source_type = "db-instance" - source_ids = [aws_db_instance.default.id] + source_ids = [aws_db_instance.default.identifier] event_categories = [ "availability", diff --git a/website/docs/r/db_instance.html.markdown b/website/docs/r/db_instance.html.markdown index b96a614a934..9338493459d 100644 --- a/website/docs/r/db_instance.html.markdown +++ b/website/docs/r/db_instance.html.markdown @@ -401,7 +401,7 @@ DB instance. * `engine_version_actual` - The running version of the database. * `hosted_zone_id` - The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record). -* `id` - The RDS instance ID. +* `id` - RDS DBI resource ID. * `instance_class`- The RDS instance class. * `latest_restorable_time` - The latest time, in UTC [RFC3339 format](https://tools.ietf.org/html/rfc3339#section-5.8), to which a database can be restored with point-in-time restore. * `listener_endpoint` - Specifies the listener connection endpoint for SQL Server Always On. See [endpoint](#endpoint) below. diff --git a/website/docs/r/db_instance_automated_backups_replication.markdown b/website/docs/r/db_instance_automated_backups_replication.markdown index f24e3d2b626..9c042bd5c79 100644 --- a/website/docs/r/db_instance_automated_backups_replication.markdown +++ b/website/docs/r/db_instance_automated_backups_replication.markdown @@ -50,7 +50,7 @@ resource "aws_db_instance" "default" { engine = "postgres" engine_version = "13.4" instance_class = "db.t3.micro" - name = "mydb" + db_name = "mydb" username = "masterusername" password = "mustbeeightcharacters" backup_retention_period = 7 diff --git a/website/docs/r/db_instance_role_association.html.markdown b/website/docs/r/db_instance_role_association.html.markdown index 654e94630c4..d4808ab0a41 100644 --- a/website/docs/r/db_instance_role_association.html.markdown +++ b/website/docs/r/db_instance_role_association.html.markdown @@ -19,7 +19,7 @@ Manages an RDS DB Instance association with an IAM Role. Example use cases: ```terraform resource "aws_db_instance_role_association" "example" { - db_instance_identifier = aws_db_instance.example.id + db_instance_identifier = aws_db_instance.example.identifier feature_name = "S3_INTEGRATION" role_arn = aws_iam_role.example.arn } diff --git a/website/docs/r/db_proxy_target.html.markdown b/website/docs/r/db_proxy_target.html.markdown index 942cc9201b7..16fb4897136 100644 --- a/website/docs/r/db_proxy_target.html.markdown +++ b/website/docs/r/db_proxy_target.html.markdown @@ -49,7 +49,7 @@ resource "aws_db_proxy_default_target_group" "example" { } resource "aws_db_proxy_target" "example" { - db_instance_identifier = aws_db_instance.example.id + db_instance_identifier = aws_db_instance.example.identifier db_proxy_name = aws_db_proxy.example.name target_group_name = aws_db_proxy_default_target_group.example.name } diff --git a/website/docs/r/db_snapshot.html.markdown b/website/docs/r/db_snapshot.html.markdown index 560722f0705..6f5c1ce466e 100644 --- a/website/docs/r/db_snapshot.html.markdown +++ b/website/docs/r/db_snapshot.html.markdown @@ -18,7 +18,7 @@ resource "aws_db_instance" "bar" { engine = "mysql" engine_version = "5.6.21" instance_class = "db.t2.micro" - name = "baz" + db_name = "baz" password = "barbarbarbar" username = "foo" @@ -28,7 +28,7 @@ resource "aws_db_instance" "bar" { } resource "aws_db_snapshot" "test" { - db_instance_identifier = aws_db_instance.bar.id + db_instance_identifier = aws_db_instance.bar.identifier db_snapshot_identifier = "testsnapshot1234" } ``` diff --git a/website/docs/r/db_snapshot_copy.html.markdown b/website/docs/r/db_snapshot_copy.html.markdown index b0f2249cd31..c40712601ff 100644 --- a/website/docs/r/db_snapshot_copy.html.markdown +++ b/website/docs/r/db_snapshot_copy.html.markdown @@ -18,7 +18,7 @@ resource "aws_db_instance" "example" { engine = "mysql" engine_version = "5.6.21" instance_class = "db.t2.micro" - name = "baz" + db_name = "baz" password = "barbarbarbar" username = "foo" @@ -28,7 +28,7 @@ resource "aws_db_instance" "example" { } resource "aws_db_snapshot" "example" { - db_instance_identifier = aws_db_instance.example.id + db_instance_identifier = aws_db_instance.example.identifier db_snapshot_identifier = "testsnapshot1234" } diff --git a/website/docs/r/rds_export_task.html.markdown b/website/docs/r/rds_export_task.html.markdown index 15e2bf0b7c7..a775e6aafd8 100644 --- a/website/docs/r/rds_export_task.html.markdown +++ b/website/docs/r/rds_export_task.html.markdown @@ -113,7 +113,7 @@ resource "aws_db_instance" "example" { } resource "aws_db_snapshot" "example" { - db_instance_identifier = aws_db_instance.example.id + db_instance_identifier = aws_db_instance.example.identifier db_snapshot_identifier = "example" } diff --git a/website/docs/r/ssm_parameter.html.markdown b/website/docs/r/ssm_parameter.html.markdown index 1a3aaee19c7..0f995b42ece 100644 --- a/website/docs/r/ssm_parameter.html.markdown +++ b/website/docs/r/ssm_parameter.html.markdown @@ -33,7 +33,7 @@ resource "aws_db_instance" "default" { engine = "mysql" engine_version = "5.7.16" instance_class = "db.t2.micro" - name = "mydb" + db_name = "mydb" username = "foo" password = var.database_master_password db_subnet_group_name = "my_database_subnet_group"