providers/aws: fix/improve RDS pointers handling
* d.Set has a pointer nil check we can lean on * need to be a bit more conservative about nil checks on nested structs; (this fixes the RDS acceptance tests) /cc @fanhaf
This commit is contained in:
parent
85c89c3ec6
commit
78963fc3d9
|
@ -304,33 +304,38 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.DBName != nil {
|
d.Set("name", v.DBName)
|
||||||
d.Set("name", *v.DBName)
|
d.Set("username", v.MasterUsername)
|
||||||
} else {
|
d.Set("engine", v.Engine)
|
||||||
d.Set("name", "")
|
d.Set("engine_version", v.EngineVersion)
|
||||||
|
d.Set("allocated_storage", v.AllocatedStorage)
|
||||||
|
d.Set("storage_type", v.StorageType)
|
||||||
|
d.Set("instance_class", v.DBInstanceClass)
|
||||||
|
d.Set("availability_zone", v.AvailabilityZone)
|
||||||
|
d.Set("backup_retention_period", v.BackupRetentionPeriod)
|
||||||
|
d.Set("backup_window", v.PreferredBackupWindow)
|
||||||
|
d.Set("maintenance_window", v.PreferredMaintenanceWindow)
|
||||||
|
d.Set("multi_az", v.MultiAZ)
|
||||||
|
if v.DBSubnetGroup != nil {
|
||||||
|
d.Set("db_subnet_group_name", v.DBSubnetGroup.DBSubnetGroupName)
|
||||||
}
|
}
|
||||||
d.Set("username", *v.MasterUsername)
|
|
||||||
d.Set("engine", *v.Engine)
|
|
||||||
d.Set("engine_version", *v.EngineVersion)
|
|
||||||
d.Set("allocated_storage", *v.AllocatedStorage)
|
|
||||||
d.Set("storage_type", *v.StorageType)
|
|
||||||
d.Set("instance_class", *v.DBInstanceClass)
|
|
||||||
d.Set("availability_zone", *v.AvailabilityZone)
|
|
||||||
d.Set("backup_retention_period", *v.BackupRetentionPeriod)
|
|
||||||
d.Set("backup_window", *v.PreferredBackupWindow)
|
|
||||||
d.Set("maintenance_window", *v.PreferredMaintenanceWindow)
|
|
||||||
d.Set("multi_az", *v.MultiAZ)
|
|
||||||
d.Set("port", *v.Endpoint.Port)
|
|
||||||
d.Set("db_subnet_group_name", *v.DBSubnetGroup.DBSubnetGroupName)
|
|
||||||
|
|
||||||
if len(v.DBParameterGroups) > 0 {
|
if len(v.DBParameterGroups) > 0 {
|
||||||
d.Set("parameter_group_name", *v.DBParameterGroups[0].DBParameterGroupName)
|
d.Set("parameter_group_name", v.DBParameterGroups[0].DBParameterGroupName)
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("address", *v.Endpoint.Address)
|
if v.Endpoint != nil {
|
||||||
d.Set("endpoint", fmt.Sprintf("%s:%d", *v.Endpoint.Address, *v.Endpoint.Port))
|
d.Set("port", v.Endpoint.Port)
|
||||||
d.Set("status", *v.DBInstanceStatus)
|
d.Set("address", v.Endpoint.Address)
|
||||||
d.Set("storage_encrypted", *v.StorageEncrypted)
|
|
||||||
|
if v.Endpoint.Address != nil && v.Endpoint.Port != nil {
|
||||||
|
d.Set("endpoint",
|
||||||
|
fmt.Sprintf("%s:%d", *v.Endpoint.Address, *v.Endpoint.Port))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Set("status", v.DBInstanceStatus)
|
||||||
|
d.Set("storage_encrypted", v.StorageEncrypted)
|
||||||
|
|
||||||
// Create an empty schema.Set to hold all vpc security group ids
|
// Create an empty schema.Set to hold all vpc security group ids
|
||||||
ids := &schema.Set{
|
ids := &schema.Set{
|
||||||
|
|
|
@ -2,7 +2,9 @@ package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
@ -24,8 +26,6 @@ func TestAccAWSDBInstance(t *testing.T) {
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
||||||
testAccCheckAWSDBInstanceAttributes(&v),
|
testAccCheckAWSDBInstanceAttributes(&v),
|
||||||
resource.TestCheckResourceAttr(
|
|
||||||
"aws_db_instance.bar", "identifier", "foobarbaz-test-terraform"),
|
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_db_instance.bar", "allocated_storage", "10"),
|
"aws_db_instance.bar", "allocated_storage", "10"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
|
@ -133,9 +133,12 @@ func testAccCheckAWSDBInstanceExists(n string, v *rds.DBInstance) resource.TestC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccAWSDBInstanceConfig = `
|
// Database names cannot collide, and deletion takes so long, that making the
|
||||||
|
// name a bit random helps so able we can kill a test that's just waiting for a
|
||||||
|
// delete and not be blocked on kicking off another one.
|
||||||
|
var testAccAWSDBInstanceConfig = fmt.Sprintf(`
|
||||||
resource "aws_db_instance" "bar" {
|
resource "aws_db_instance" "bar" {
|
||||||
identifier = "foobarbaz-test-terraform"
|
identifier = "foobarbaz-test-terraform-%d"
|
||||||
|
|
||||||
allocated_storage = 10
|
allocated_storage = 10
|
||||||
engine = "mysql"
|
engine = "mysql"
|
||||||
|
@ -148,5 +151,4 @@ resource "aws_db_instance" "bar" {
|
||||||
backup_retention_period = 0
|
backup_retention_period = 0
|
||||||
|
|
||||||
parameter_group_name = "default.mysql5.6"
|
parameter_group_name = "default.mysql5.6"
|
||||||
}
|
}`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())
|
||||||
`
|
|
||||||
|
|
Loading…
Reference in New Issue