provider/aws: Fix issue with AWS RDS DB instance which prevented disabling backups
This commit is contained in:
parent
5bbb83905e
commit
bb94eaa50d
|
@ -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 {
|
||||
|
|
|
@ -141,6 +141,8 @@ resource "aws_db_instance" "bar" {
|
|||
password = "barbarbarbar"
|
||||
username = "foo"
|
||||
|
||||
backup_retention_period = 0
|
||||
|
||||
parameter_group_name = "default.mysql5.6"
|
||||
}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue