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

Modify RDS Cluster after restoring from snapshot, if required #926

Merged
merged 1 commit into from
Jul 6, 2017
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
22 changes: 16 additions & 6 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,24 +291,34 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
opts.Port = aws.Int64(int64(attr.(int)))
}

var sgUpdate bool
// Check if any of the parameters that require a cluster modification after creation are set
var clusterUpdate bool
if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 {
sgUpdate = true
clusterUpdate = true
opts.VpcSecurityGroupIds = expandStringList(attr.List())
}

if _, ok := d.GetOk("db_cluster_parameter_group_name"); ok {
clusterUpdate = true
}

if _, ok := d.GetOk("backup_retention_period"); ok {
clusterUpdate = true
}

log.Printf("[DEBUG] RDS Cluster restore from snapshot configuration: %s", opts)
_, err := conn.RestoreDBClusterFromSnapshot(&opts)
if err != nil {
return fmt.Errorf("Error creating RDS Cluster: %s", err)
}

if sgUpdate {
log.Printf("[INFO] RDS Cluster is restoring from snapshot with default security, but custom security should be set, will now update after snapshot is restored!")
if clusterUpdate {
log.Printf("[INFO] RDS Cluster is restoring from snapshot with default db_cluster_parameter_group_name, backup_retention_period and vpc_security_group_ids" +
"but custom values should be set, will now update after snapshot is restored!")

d.SetId(d.Get("cluster_identifier").(string))

log.Printf("[INFO] RDS Cluster Instance ID: %s", d.Id())
log.Printf("[INFO] RDS Cluster ID: %s", d.Id())

log.Println("[INFO] Waiting for RDS Cluster to be available")

Expand All @@ -327,7 +337,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
return err
}

err = resourceAwsRDSClusterInstanceUpdate(d, meta)
err = resourceAwsRDSClusterUpdate(d, meta)
if err != nil {
return err
}
Expand Down