diff --git a/.changelog/17755.txt b/.changelog/17755.txt new file mode 100644 index 00000000000..4387e6b0301 --- /dev/null +++ b/.changelog/17755.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_db_instance: Fix conflicting argument validation error +``` diff --git a/aws/resource_aws_db_instance.go b/aws/resource_aws_db_instance.go index eb12a92c482..6022bd3afcc 100644 --- a/aws/resource_aws_db_instance.go +++ b/aws/resource_aws_db_instance.go @@ -1,7 +1,6 @@ package aws import ( - "context" "fmt" "log" "regexp" @@ -12,7 +11,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/rds" "github.com/hashicorp/aws-sdk-go-base/tfawserr" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -415,10 +413,9 @@ func resourceAwsDbInstance() *schema.Resource { }, "snapshot_identifier": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ConflictsWith: []string{"username"}, + Type: schema.TypeString, + Optional: true, + ForceNew: true, }, "auto_minor_version_upgrade": { @@ -532,20 +529,6 @@ func resourceAwsDbInstance() *schema.Resource { "tags": tagsSchema(), }, - - CustomizeDiff: customdiff.All( - func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { - if _, ok := diff.GetOk("snapshot_identifier"); ok { - switch strings.ToLower(diff.Get("engine").(string)) { - case "mysql", "postgres", "mariadb": - if _, ok := diff.GetOk("name"); ok { - return fmt.Errorf("name attribute is not supported with snapshot_identifier when engine is %s", diff.Get("engine").(string)) - } - } - } - return nil - }, - ), } } @@ -911,7 +894,14 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error } if attr, ok := d.GetOk("name"); ok { - opts.DBName = aws.String(attr.(string)) + // "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 strings.ToLower(d.Get("engine").(string)) { + case "mysql", "postgres", "mariadb": + // skip + default: + opts.DBName = aws.String(attr.(string)) + } } if attr, ok := d.GetOk("allocated_storage"); ok { diff --git a/aws/resource_aws_db_instance_test.go b/aws/resource_aws_db_instance_test.go index c12c8630f43..c0fde9fed54 100644 --- a/aws/resource_aws_db_instance_test.go +++ b/aws/resource_aws_db_instance_test.go @@ -4575,6 +4575,8 @@ resource "aws_db_instance" "mysql_restore" { instance_class = data.aws_rds_orderable_db_instance.test.instance_class allocated_storage = 20 + username = "root" + password = "password" engine = data.aws_rds_orderable_db_instance.test.engine engine_version = "5.6.41" backup_retention_period = 0