From 38ac748b887d9ac11a5569528db3a58739bf35d3 Mon Sep 17 00:00:00 2001 From: Linda Xu Date: Tue, 24 May 2016 21:45:55 -0700 Subject: [PATCH 1/3] support aurora instance's parameter group and modifyinstance --- .../aws/resource_aws_rds_cluster_instance.go | 74 ++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_rds_cluster_instance.go b/builtin/providers/aws/resource_aws_rds_cluster_instance.go index 59cf4c57c..d4133f656 100644 --- a/builtin/providers/aws/resource_aws_rds_cluster_instance.go +++ b/builtin/providers/aws/resource_aws_rds_cluster_instance.go @@ -58,13 +58,31 @@ func resourceAwsRDSClusterInstance() *schema.Resource { Type: schema.TypeBool, Optional: true, Default: false, - ForceNew: true, }, "instance_class": &schema.Schema{ Type: schema.TypeString, Required: true, - ForceNew: true, + }, + + "db_parameter_group_name": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + + "status": &schema.Schema{ + 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(), @@ -84,6 +102,10 @@ func resourceAwsRDSClusterInstanceCreate(d *schema.ResourceData, meta interface{ Tags: tags, } + if attr, ok := d.GetOk("db_parameter_group_name"); ok { + createOpts.DBParameterGroupName = aws.String(attr.(string)) + } + if v := d.Get("identifier").(string); v != "" { createOpts.DBInstanceIdentifier = aws.String(v) } else { @@ -169,6 +191,10 @@ func resourceAwsRDSClusterInstanceRead(d *schema.ResourceData, meta interface{}) d.Set("publicly_accessible", db.PubliclyAccessible) + if len(db.DBParameterGroups) > 0 { + d.Set("parameter_group_name", db.DBParameterGroups[0].DBParameterGroupName) + } + // Fetch and save tags arn, err := buildRDSARN(d.Id(), meta) if err != nil { @@ -184,6 +210,50 @@ func resourceAwsRDSClusterInstanceRead(d *schema.ResourceData, meta interface{}) func resourceAwsRDSClusterInstanceUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).rdsconn + requestUpdate := false + + req := &rds.ModifyDBInstanceInput{ + ApplyImmediately: aws.Bool(d.Get("apply_immediately").(bool)), + DBInstanceIdentifier: aws.String(d.Id()), + } + + if d.HasChange("db_parameter_group_name") { + req.DBParameterGroupName = aws.String(d.Get("db_parameter_group_name").(string)) + requestUpdate = true + + } + + if d.HasChange("instance_class") { + req.DBInstanceClass = aws.String(d.Get("instance_class").(string)) + requestUpdate = true + + } + + log.Printf("[DEBUG] Send DB Instance Modification request: %#v", requestUpdate) + if requestUpdate { + 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) + } + + // reuse db_instance refresh func + stateConf := &resource.StateChangeConf{ + Pending: []string{"creating", "backing-up", "modifying"}, + Target: []string{"available"}, + Refresh: resourceAwsDbInstanceStateRefreshFunc(d, meta), + Timeout: 40 * time.Minute, + MinTimeout: 10 * time.Second, + Delay: 10 * time.Second, + } + + // Wait, catching any errors + _, err = stateConf.WaitForState() + if err != nil { + return err + } + + } if arn, err := buildRDSARN(d.Id(), meta); err == nil { if err := setTagsRDS(conn, d, arn); err != nil { From 5ca5b1e3a192f4ad2af476fc7a6c549f1622edfb Mon Sep 17 00:00:00 2001 From: Linda Xu Date: Thu, 2 Jun 2016 20:37:36 -0700 Subject: [PATCH 2/3] remove status attribute --- builtin/providers/aws/resource_aws_rds_cluster_instance.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/builtin/providers/aws/resource_aws_rds_cluster_instance.go b/builtin/providers/aws/resource_aws_rds_cluster_instance.go index d4133f656..09580cc89 100644 --- a/builtin/providers/aws/resource_aws_rds_cluster_instance.go +++ b/builtin/providers/aws/resource_aws_rds_cluster_instance.go @@ -71,11 +71,6 @@ func resourceAwsRDSClusterInstance() *schema.Resource { Computed: true, }, - "status": &schema.Schema{ - 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 From 412d88e7684c91d77e0a6c2418bb6236401652c1 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Fri, 3 Jun 2016 13:46:01 -0500 Subject: [PATCH 3/3] provider/aws: Add db_param group to RDS Cluster Instance test --- .../resource_aws_rds_cluster_instance_test.go | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/resource_aws_rds_cluster_instance_test.go b/builtin/providers/aws/resource_aws_rds_cluster_instance_test.go index a3b2d3a35..b832f89b6 100644 --- a/builtin/providers/aws/resource_aws_rds_cluster_instance_test.go +++ b/builtin/providers/aws/resource_aws_rds_cluster_instance_test.go @@ -177,10 +177,25 @@ resource "aws_rds_cluster" "default" { } resource "aws_rds_cluster_instance" "cluster_instances" { - identifier = "tf-cluster-instance-%d" - cluster_identifier = "${aws_rds_cluster.default.id}" - instance_class = "db.r3.large" + identifier = "tf-cluster-instance-%d" + cluster_identifier = "${aws_rds_cluster.default.id}" + instance_class = "db.r3.large" + db_parameter_group_name = "${aws_db_parameter_group.bar.name}" } +resource "aws_db_parameter_group" "bar" { + name = "tfcluster-test-group" + family = "aurora5.6" + + parameter { + name = "back_log" + value = "32767" + apply_method = "pending-reboot" + } + + tags { + foo = "bar" + } +} `, n, n) }