Merge pull request #874 from bitglue/fix_rds

Fix aws_db_instance to not recreate each time
This commit is contained in:
Paul Hinze 2015-01-28 16:22:24 -06:00
commit 632fddd96d
3 changed files with 18 additions and 22 deletions

View File

@ -21,7 +21,7 @@ func resourceAwsDbInstance() *schema.Resource {
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": &schema.Schema{ "name": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Optional: true,
ForceNew: true, ForceNew: true,
}, },
@ -70,18 +70,21 @@ func resourceAwsDbInstance() *schema.Resource {
"availability_zone": &schema.Schema{ "availability_zone": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true,
ForceNew: true, ForceNew: true,
}, },
"backup_retention_period": &schema.Schema{ "backup_retention_period": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Computed: true,
ForceNew: true, ForceNew: true,
}, },
"backup_window": &schema.Schema{ "backup_window": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true,
ForceNew: true, ForceNew: true,
}, },
@ -94,18 +97,21 @@ func resourceAwsDbInstance() *schema.Resource {
"maintenance_window": &schema.Schema{ "maintenance_window": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true,
ForceNew: true, ForceNew: true,
}, },
"multi_az": &schema.Schema{ "multi_az": &schema.Schema{
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Computed: true,
ForceNew: true, ForceNew: true,
}, },
"port": &schema.Schema{ "port": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Computed: true,
ForceNew: true, ForceNew: true,
}, },
@ -133,12 +139,6 @@ func resourceAwsDbInstance() *schema.Resource {
}, },
}, },
"skip_final_snapshot": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"final_snapshot_identifier": &schema.Schema{ "final_snapshot_identifier": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
@ -154,6 +154,7 @@ func resourceAwsDbInstance() *schema.Resource {
"parameter_group_name": &schema.Schema{ "parameter_group_name": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true,
ForceNew: true, ForceNew: true,
}, },
@ -189,10 +190,6 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
EngineVersion: d.Get("engine_version").(string), EngineVersion: d.Get("engine_version").(string),
} }
// Special treatment for the password, as we don't want that
// saved into the state file
d.Set("password", "")
if attr, ok := d.GetOk("backup_retention_period"); ok { if attr, ok := d.GetOk("backup_retention_period"); ok {
opts.BackupRetentionPeriod = attr.(int) opts.BackupRetentionPeriod = attr.(int)
opts.SetBackupRetentionPeriod = true opts.SetBackupRetentionPeriod = true
@ -344,10 +341,11 @@ func resourceAwsDbInstanceDelete(d *schema.ResourceData, meta interface{}) error
opts := rds.DeleteDBInstance{DBInstanceIdentifier: d.Id()} opts := rds.DeleteDBInstance{DBInstanceIdentifier: d.Id()}
if d.Get("skip_final_snapshot").(bool) { finalSnapshot := d.Get("final_snapshot_identifier").(string)
if finalSnapshot == "" {
opts.SkipFinalSnapshot = true opts.SkipFinalSnapshot = true
} else { } else {
opts.FinalDBSnapshotIdentifier = d.Get("final_snapshot_identifier").(string) opts.FinalDBSnapshotIdentifier = finalSnapshot
} }
log.Printf("[DEBUG] DB Instance destroy configuration: %v", opts) log.Printf("[DEBUG] DB Instance destroy configuration: %v", opts)

View File

@ -39,8 +39,6 @@ func TestAccAWSDBInstance(t *testing.T) {
"aws_db_instance.bar", "password", ""), "aws_db_instance.bar", "password", ""),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_db_instance.bar", "username", "foo"), "aws_db_instance.bar", "username", "foo"),
resource.TestCheckResourceAttr(
"aws_db_instance.bar", "skip_final_snapshot", "true"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_db_instance.bar", "security_group_names.3322503515", "secfoobarbaz-test-terraform"), "aws_db_instance.bar", "security_group_names.3322503515", "secfoobarbaz-test-terraform"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -159,8 +157,6 @@ resource "aws_db_instance" "bar" {
password = "barbarbarbar" password = "barbarbarbar"
username = "foo" username = "foo"
skip_final_snapshot = true
security_group_names = ["${aws_db_security_group.bar.name}"] security_group_names = ["${aws_db_security_group.bar.name}"]
parameter_group_name = "default.mysql5.6" parameter_group_name = "default.mysql5.6"
} }

View File

@ -37,10 +37,13 @@ The following arguments are supported:
* `engine_version` - (Required) The engine version to use. * `engine_version` - (Required) The engine version to use.
* `identifier` - (Required) The name of the RDS instance * `identifier` - (Required) The name of the RDS instance
* `instance_class` - (Required) The instance type of the RDS instance. * `instance_class` - (Required) The instance type of the RDS instance.
* `final_snapshot_identifier` - (Optional) The name of your final DB snapshot. * `final_snapshot_identifier` - (Optional) The name of your final DB snapshot
* `name` - (Required) The DB name to create. when this DB instance is deleted. If omitted, no final snapshot will be
* `password` - (Required) Password for the master DB user. Note that this will be stored made.
in the state file. * `name` - (Optional) The DB name to create. If omitted, no database is created
initially.
* `password` - (Required) Password for the master DB user. Note that this may
show up in logs, and it will be stored in the state file.
* `username` - (Required) Username for the master DB user. * `username` - (Required) Username for the master DB user.
* `availability_zone` - (Optional) The AZ for the RDS instance. * `availability_zone` - (Optional) The AZ for the RDS instance.
* `backup_retention_period` - (Optional) The days to retain backups for. * `backup_retention_period` - (Optional) The days to retain backups for.
@ -51,7 +54,6 @@ The following arguments are supported:
* `port` - (Optional) The port on which the DB accepts connections. * `port` - (Optional) The port on which the DB accepts connections.
* `publicly_accessible` - (Optional) Bool to control if instance is publicly accessible. * `publicly_accessible` - (Optional) Bool to control if instance is publicly accessible.
* `vpc_security_group_ids` - (Optional) List of VPC security groups to associate. * `vpc_security_group_ids` - (Optional) List of VPC security groups to associate.
* `skip_final_snapshot` - (Optional) Enables skipping the final snapshot on deletion.
* `security_group_names` - (Optional) List of DB Security Groups to associate. * `security_group_names` - (Optional) List of DB Security Groups to associate.
* `db_subnet_group_name` - (Optional) Name of DB subnet group * `db_subnet_group_name` - (Optional) Name of DB subnet group
* `parameter_group_name` - (Optional) Name of the DB parameter group to associate. * `parameter_group_name` - (Optional) Name of the DB parameter group to associate.