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

provider/aws: Support additional changes to RDS without forcing new #1382

Merged
merged 2 commits into from
Apr 6, 2015
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
81 changes: 58 additions & 23 deletions builtin/providers/aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func resourceAwsDbInstance() *schema.Resource {
"password": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"engine": &schema.Schema{
Expand All @@ -60,14 +59,12 @@ func resourceAwsDbInstance() *schema.Resource {
"allocated_storage": &schema.Schema{
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},

"storage_type": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

"identifier": &schema.Schema{
Expand All @@ -79,7 +76,6 @@ func resourceAwsDbInstance() *schema.Resource {
"instance_class": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"availability_zone": &schema.Schema{
Expand All @@ -92,28 +88,24 @@ func resourceAwsDbInstance() *schema.Resource {
"backup_retention_period": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Default: 1,
},

"backup_window": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

"iops": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},

"maintenance_window": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

"multi_az": &schema.Schema{
Expand Down Expand Up @@ -439,41 +431,84 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error
conn := meta.(*AWSClient).rdsconn

d.Partial(true)
// Change is used to determine if a ModifyDBInstanceMessage request actually
// gets sent.
change := false

req := &rds.ModifyDBInstanceMessage{
ApplyImmediately: aws.Boolean(d.Get("apply_immediately").(bool)),
DBInstanceIdentifier: aws.String(d.Id()),
}
d.SetPartial("apply_immediately")

if d.HasChange("allocated_storage") {
d.SetPartial("allocated_storage")
req.AllocatedStorage = aws.Integer(d.Get("allocated_storage").(int))
}
if d.HasChange("backup_retention_period") {
d.SetPartial("backup_retention_period")
req.BackupRetentionPeriod = aws.Integer(d.Get("backup_retention_period").(int))
}
if d.HasChange("instance_class") {
d.SetPartial("instance_class")
req.DBInstanceClass = aws.String(d.Get("instance_class").(string))
}
if d.HasChange("parameter_group_name") {
d.SetPartial("parameter_group_name")
req.DBParameterGroupName = aws.String(d.Get("parameter_group_name").(string))
}
if d.HasChange("engine_version") {
change = true
d.SetPartial("engine_version")
req.EngineVersion = aws.String(d.Get("engine_version").(string))
}

if d.HasChange("iops") {
d.SetPartial("iops")
req.IOPS = aws.Integer(d.Get("iops").(int))
}
if d.HasChange("backup_window") {
d.SetPartial("backup_window")
req.PreferredBackupWindow = aws.String(d.Get("backup_window").(string))
}
if d.HasChange("maintenance_window") {
d.SetPartial("maintenance_window")
req.PreferredMaintenanceWindow = aws.String(d.Get("maintenance_window").(string))
}
if d.HasChange("password") {
d.SetPartial("password")
req.MasterUserPassword = aws.String(d.Get("password").(string))
}
if d.HasChange("multi_az") {
change = true
d.SetPartial("multi_az")
req.MultiAZ = aws.Boolean(d.Get("multi_az").(bool))
}
if d.HasChange("storage_type") {
d.SetPartial("storage_type")
req.StorageType = aws.String(d.Get("storage_type").(string))
}

if d.HasChange("parameter_group_name") {
change = true
d.SetPartial("parameter_group_name")
req.DBParameterGroupName = aws.String(d.Get("parameter_group_name").(string))
if d.HasChange("vpc_security_group_ids") {
if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 {
var s []string
for _, v := range attr.List() {
s = append(s, v.(string))
}
req.VPCSecurityGroupIDs = s
}
}

if change {
log.Printf("[DEBUG] DB Instance Modification request: %#v", req)
_, err := conn.ModifyDBInstance(req)
if err != nil {
return fmt.Errorf("Error mofigying DB Instance %s: %s", d.Id(), err)
if d.HasChange("vpc_security_group_ids") {
if attr := d.Get("security_group_names").(*schema.Set); attr.Len() > 0 {
var s []string
for _, v := range attr.List() {
s = append(s, v.(string))
}
req.DBSecurityGroups = s
}
}

log.Printf("[DEBUG] DB Instance Modification request: %#v", req)
_, err := conn.ModifyDBInstance(req)
if err != nil {
return fmt.Errorf("Error modifying DB Instance %s: %s", d.Id(), err)
}

if arn, err := buildRDSARN(d, meta); err == nil {
if err := setTagsRDS(conn, d, arn); err != nil {
return err
Expand Down