diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index c95847a7b..86c39f8c4 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -13,6 +13,12 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) +// Establish a sentinel value to allow Backup Rention to 0, disabling backups of +// the RDS Instance. This is needed to distinguish between a zero value in the +// configuration, or no value provided. The default on AWS is 1 (one day). +// See http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html +const backupRetentionPeriodUnset = -1 + func resourceAwsDbInstance() *schema.Resource { return &schema.Resource{ Create: resourceAwsDbInstanceCreate, @@ -87,6 +93,7 @@ func resourceAwsDbInstance() *schema.Resource { Optional: true, Computed: true, ForceNew: true, + Default: backupRetentionPeriodUnset, }, "backup_window": &schema.Schema{ @@ -201,8 +208,11 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error opts.StorageType = aws.String(attr.(string)) } - if attr, ok := d.GetOk("backup_retention_period"); ok { - opts.BackupRetentionPeriod = aws.Integer(attr.(int)) + // Compare the backup_retention_period value to the Default. This allows a + // zero value for backup_retention_period, disabling backups. + brp := d.Get("backup_retention_period") + if brp != backupRetentionPeriodUnset { + opts.BackupRetentionPeriod = aws.Integer(brp.(int)) } if attr, ok := d.GetOk("iops"); ok { diff --git a/builtin/providers/aws/resource_aws_db_instance_test.go b/builtin/providers/aws/resource_aws_db_instance_test.go index f44b67ade..831c929af 100644 --- a/builtin/providers/aws/resource_aws_db_instance_test.go +++ b/builtin/providers/aws/resource_aws_db_instance_test.go @@ -141,6 +141,8 @@ resource "aws_db_instance" "bar" { password = "barbarbarbar" username = "foo" + backup_retention_period = 0 + parameter_group_name = "default.mysql5.6" } `