From b0d2b25b2d0f3aa54cee0800dc442886ff5f00bb Mon Sep 17 00:00:00 2001 From: Adam Enger Date: Sun, 24 May 2015 16:51:35 -0500 Subject: [PATCH 1/3] Adding support for snapshot_identifier option which enables restoring a DB from a snapshot --- .../providers/aws/resource_aws_db_instance.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index c832c67bb6..e2e579c949 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -203,6 +203,13 @@ func resourceAwsDbInstance() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, }, + "snapshot_identifier": &schema.Schema{ + Type: schema.TypeString, + Computed: false, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "tags": tagsSchema(), }, } @@ -238,6 +245,18 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error if err != nil { return fmt.Errorf("Error creating DB Instance: %s", err) } + } else if _, ok := d.GetOk("snapshot_identifier"); ok { + opts := rds.RestoreDBInstanceFromDBSnapshotInput{ + AutoMinorVersionUpgrade: aws.Boolean(d.Get("auto_minor_version_upgrade").(bool)), + DBInstanceClass: aws.String(d.Get("instance_class").(string)), + DBInstanceIdentifier: aws.String(d.Get("identifier").(string)), + DBSnapshotIdentifier: aws.String(d.Get("snapshot_identifier").(string)), + Tags: tags, + } + _, err := conn.RestoreDBInstanceFromDBSnapshot(&opts) + if err != nil { + return fmt.Errorf("Error creating DB Instance: %s", err) + } } else { opts := rds.CreateDBInstanceInput{ AllocatedStorage: aws.Long(int64(d.Get("allocated_storage").(int))), From 679922575706bb42c7d695b70d8ae4bf19b02452 Mon Sep 17 00:00:00 2001 From: Adam Enger Date: Sun, 24 May 2015 20:18:36 -0500 Subject: [PATCH 2/3] adding all supproted options for db snapshot restore --- .../providers/aws/resource_aws_db_instance.go | 64 +++++++++++++++++-- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index e2e579c949..157d7132bc 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -210,6 +210,12 @@ func resourceAwsDbInstance() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, }, + "auto_minor_version_upgrade": &schema.Schema{ + Type: schema.TypeBool, + Computed: false, + Optional: true, + }, + "tags": tagsSchema(), }, } @@ -247,12 +253,60 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error } } else if _, ok := d.GetOk("snapshot_identifier"); ok { opts := rds.RestoreDBInstanceFromDBSnapshotInput{ - AutoMinorVersionUpgrade: aws.Boolean(d.Get("auto_minor_version_upgrade").(bool)), - DBInstanceClass: aws.String(d.Get("instance_class").(string)), - DBInstanceIdentifier: aws.String(d.Get("identifier").(string)), - DBSnapshotIdentifier: aws.String(d.Get("snapshot_identifier").(string)), - Tags: tags, + DBInstanceClass: aws.String(d.Get("instance_class").(string)), + DBInstanceIdentifier: aws.String(d.Get("identifier").(string)), + DBSnapshotIdentifier: aws.String(d.Get("snapshot_identifier").(string)), + Tags: tags, } + + if attr, ok := d.GetOk("auto_minor_version_upgrade"); ok { + opts.AutoMinorVersionUpgrade = aws.Boolean(attr.(bool)) + } + + if attr, ok := d.GetOk("availability_zone"); ok { + opts.AvailabilityZone = aws.String(attr.(string)) + } + + if attr, ok := d.GetOk("db_subnet_group_name"); ok { + opts.DBSubnetGroupName = aws.String(attr.(string)) + } + + if attr, ok := d.GetOk("engine"); ok { + opts.Engine = aws.String(attr.(string)) + } + + if attr, ok := d.GetOk("iops"); ok { + opts.IOPS = aws.Long(int64(attr.(int))) + } + + if attr, ok := d.GetOk("license_model"); ok { + opts.LicenseModel = aws.String(attr.(string)) + } + + if attr, ok := d.GetOk("multi_az"); ok { + opts.MultiAZ = aws.Boolean(attr.(bool)) + } + + if attr, ok := d.GetOk("option_group_name"); ok { + opts.OptionGroupName = aws.String(attr.(string)) + } + + if attr, ok := d.GetOk("port"); ok { + opts.Port = aws.Long(int64(attr.(int))) + } + + if attr, ok := d.GetOk("publicly_accessible"); ok { + opts.PubliclyAccessible = aws.Boolean(attr.(bool)) + } + + if attr, ok := d.GetOk("tde_credential_arn"); ok { + opts.TDECredentialARN = aws.String(attr.(string)) + } + + if attr, ok := d.GetOk("storage_type"); ok { + opts.StorageType = aws.String(attr.(string)) + } + _, err := conn.RestoreDBInstanceFromDBSnapshot(&opts) if err != nil { return fmt.Errorf("Error creating DB Instance: %s", err) From d206d6d5d8aad59eaa3332bd7c2dcdcfd5fb4ec7 Mon Sep 17 00:00:00 2001 From: Adam Enger Date: Tue, 30 Jun 2015 15:33:13 -0500 Subject: [PATCH 3/3] Adding snapshot_identifier to db_instance docs --- website/source/docs/providers/aws/r/db_instance.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 784ade6499..c2f0063f4c 100644 --- a/website/source/docs/providers/aws/r/db_instance.html.markdown +++ b/website/source/docs/providers/aws/r/db_instance.html.markdown @@ -77,7 +77,7 @@ database, and to use this value as the source database. This correlates to the [DB Instance Replication][1] and [Working with PostgreSQL and MySQL Read Replicas](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html) for more information on using Replication. - +* `snapshot_identifier` - (Optional) Specifies whether or not to create this database from a snapshot. This correlates to the snapshot ID you'd find in the RDS console, e.g: rds:production-2015-06-26-06-05. ~> **NOTE:** Removing the `replicate_source_db` attribute from an existing RDS Replicate database managed by Terraform will promote the database to a fully