From e485767694574174b316ad6834ade7489463a15d Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Tue, 31 Mar 2015 09:41:37 -0500 Subject: [PATCH] provider/aws: Add non-destructive updates to AWS RDS This introduces non-destructive, in-place upgrades to MultiAZ and Engine Version attributes of AWS RDS instances. --- .../providers/aws/resource_aws_db_instance.go | 41 ++++++++++++++++++- .../providers/aws/r/db_instance.html.markdown | 3 ++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index b690c9a1a..14deff732 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -49,7 +49,6 @@ func resourceAwsDbInstance() *schema.Resource { "engine_version": &schema.Schema{ Type: schema.TypeString, Required: true, - ForceNew: true, }, "storage_encrypted": &schema.Schema{ @@ -121,7 +120,6 @@ func resourceAwsDbInstance() *schema.Resource { Type: schema.TypeBool, Optional: true, Computed: true, - ForceNew: true, }, "port": &schema.Schema{ @@ -189,6 +187,16 @@ func resourceAwsDbInstance() *schema.Resource { Type: schema.TypeString, Computed: true, }, + + // apply_immediately is used to determine when the update modifications + // take place. + // See http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.DBInstance.Modifying.html + "apply_immediately": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "tags": tagsSchema(), }, } @@ -423,6 +431,35 @@ 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()), + } + + if d.HasChange("engine_version") { + change = true + d.SetPartial("engine_version") + req.EngineVersion = aws.String(d.Get("engine_version").(string)) + } + + if d.HasChange("multi_az") { + change = true + d.SetPartial("multi_az") + req.MultiAZ = aws.Boolean(d.Get("multi_az").(bool)) + } + + 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 arn, err := buildRDSARN(d, meta); err == nil { if err := setTagsRDS(conn, d, arn); err != nil { return err diff --git a/website/source/docs/providers/aws/r/db_instance.html.markdown b/website/source/docs/providers/aws/r/db_instance.html.markdown index 4b2253115..6b3b97552 100644 --- a/website/source/docs/providers/aws/r/db_instance.html.markdown +++ b/website/source/docs/providers/aws/r/db_instance.html.markdown @@ -62,6 +62,9 @@ The following arguments are supported: * `db_subnet_group_name` - (Optional) Name of DB subnet group * `parameter_group_name` - (Optional) Name of the DB parameter group to associate. * `storage_encrypted` - (Optional) Specifies whether the DB instance is encrypted. The Default is `false` if not specified. +* `apply_immediately` - (Optional) Specifies whether any database modifications + are applied immediately, or during the next maintenance window. Default is + `False`. See [Amazon RDS Documentation for more for more information.](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.DBInstance.Modifying.html) ## Attributes Reference