Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDS - Throw error when name or username supplied on DB snapshot restore #17156

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,12 +898,21 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
// https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_RestoreDBInstanceFromDBSnapshot.html
switch strings.ToLower(d.Get("engine").(string)) {
case "mysql", "postgres", "mariadb":
// skip
// Throw an error if name attribute is provided when engine is mysql, postgres or mariadb when restoring from snapshot
// https://github.com/hashicorp/terraform-provider-aws/issues/17037
return fmt.Errorf("Error restoring database from AWS DB Snapshot: %s, name attribute is not supported when engine is %s", d.Get("snapshot_identifier").(string), d.Get("engine").(string))
default:
opts.DBName = aws.String(attr.(string))
}
}

if _, ok := d.GetOk("username"); ok {
// "Note: This parameter [username] doesn't apply when restoring from snapshot"
// https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_RestoreDBInstanceFromDBSnapshot.html
// https://github.com/hashicorp/terraform-provider-aws/issues/17037
return fmt.Errorf("Error restoring database from AWS DB Snapshot: %s, username attribute is not supported when restoring from snapshot", d.Get("snapshot_identifier").(string))
}

if attr, ok := d.GetOk("allocated_storage"); ok {
modifyDbInstanceInput.AllocatedStorage = aws.Int64(int64(attr.(int)))
requiresModifyDbInstance = true
Expand Down