11package aws
22
33import (
4+ "context"
45 "fmt"
56 "log"
67 "regexp"
@@ -11,6 +12,7 @@ import (
1112 "github.com/aws/aws-sdk-go/aws"
1213 "github.com/aws/aws-sdk-go/service/rds"
1314 "github.com/hashicorp/aws-sdk-go-base/tfawserr"
15+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
1416 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1517 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1618 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
@@ -413,9 +415,10 @@ func resourceAwsDbInstance() *schema.Resource {
413415 },
414416
415417 "snapshot_identifier" : {
416- Type : schema .TypeString ,
417- Optional : true ,
418- ForceNew : true ,
418+ Type : schema .TypeString ,
419+ Optional : true ,
420+ ForceNew : true ,
421+ ConflictsWith : []string {"username" },
419422 },
420423
421424 "auto_minor_version_upgrade" : {
@@ -529,6 +532,20 @@ func resourceAwsDbInstance() *schema.Resource {
529532
530533 "tags" : tagsSchema (),
531534 },
535+
536+ CustomizeDiff : customdiff .All (
537+ func (_ context.Context , diff * schema.ResourceDiff , v interface {}) error {
538+ if _ , ok := diff .GetOk ("snapshot_identifier" ); ok {
539+ switch strings .ToLower (diff .Get ("engine" ).(string )) {
540+ case "mysql" , "postgres" , "mariadb" :
541+ if _ , ok := diff .GetOk ("name" ); ok {
542+ return fmt .Errorf ("name attribute is not supported with snapshot_identifier when engine is %s" , diff .Get ("engine" ).(string ))
543+ }
544+ }
545+ }
546+ return nil
547+ },
548+ ),
532549 }
533550}
534551
@@ -547,7 +564,7 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
547564 }
548565
549566 // Some ModifyDBInstance parameters (e.g. DBParameterGroupName) require
550- // a database instance reboot to take affect . During resource creation,
567+ // a database instance reboot to take effect . During resource creation,
551568 // we expect everything to be in sync before returning completion.
552569 var requiresRebootDbInstance bool
553570
@@ -894,14 +911,7 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
894911 }
895912
896913 if attr , ok := d .GetOk ("name" ); ok {
897- // "Note: This parameter [DBName] doesn't apply to the MySQL, PostgreSQL, or MariaDB engines."
898- // https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_RestoreDBInstanceFromDBSnapshot.html
899- switch strings .ToLower (d .Get ("engine" ).(string )) {
900- case "mysql" , "postgres" , "mariadb" :
901- // skip
902- default :
903- opts .DBName = aws .String (attr .(string ))
904- }
914+ opts .DBName = aws .String (attr .(string ))
905915 }
906916
907917 if attr , ok := d .GetOk ("allocated_storage" ); ok {
0 commit comments