Merge pull request #11369 from hashicorp/f-add-suppress-func-db-instance
provider/aws: Add diff suppress function for aws_db_instance
This commit is contained in:
commit
dc91285949
|
@ -1,6 +1,9 @@
|
||||||
package aws
|
package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/jen20/awspolicyequivalence"
|
"github.com/jen20/awspolicyequivalence"
|
||||||
)
|
)
|
||||||
|
@ -13,3 +16,18 @@ func suppressEquivalentAwsPolicyDiffs(k, old, new string, d *schema.ResourceData
|
||||||
|
|
||||||
return equivalent
|
return equivalent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Suppresses minor version changes to the db_instance engine_version attribute
|
||||||
|
func suppressAwsDbEngineVersionDiffs(k, old, new string, d *schema.ResourceData) bool {
|
||||||
|
if d.Get("auto_minor_version_upgrade").(bool) {
|
||||||
|
// If we're set to auto upgrade minor versions
|
||||||
|
// ignore a minor version diff between versions
|
||||||
|
if strings.HasPrefix(old, new) {
|
||||||
|
log.Printf("[DEBUG] Ignoring minor version diff")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Throw a diff by default
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
@ -66,6 +66,7 @@ func resourceAwsDbInstance() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
|
DiffSuppressFunc: suppressAwsDbEngineVersionDiffs,
|
||||||
},
|
},
|
||||||
|
|
||||||
"character_set_name": {
|
"character_set_name": {
|
||||||
|
|
|
@ -27,7 +27,7 @@ func TestAccAWSDBInstance_basic(t *testing.T) {
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSDBInstanceConfig,
|
Config: testAccAWSDBInstanceConfig,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
||||||
|
@ -65,7 +65,7 @@ func TestAccAWSDBInstance_kmsKey(t *testing.T) {
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: config,
|
Config: config,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
||||||
|
@ -115,7 +115,7 @@ func TestAccAWSDBInstance_optionGroup(t *testing.T) {
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSDBInstanceConfigWithOptionGroup,
|
Config: testAccAWSDBInstanceConfigWithOptionGroup,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
||||||
|
@ -136,7 +136,7 @@ func TestAccAWSDBInstanceReplica(t *testing.T) {
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccReplicaInstanceConfig(rand.New(rand.NewSource(time.Now().UnixNano())).Int()),
|
Config: testAccReplicaInstanceConfig(rand.New(rand.NewSource(time.Now().UnixNano())).Int()),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &s),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &s),
|
||||||
|
@ -158,7 +158,7 @@ func TestAccAWSDBInstanceSnapshot(t *testing.T) {
|
||||||
// created, and subequently deletes it
|
// created, and subequently deletes it
|
||||||
CheckDestroy: testAccCheckAWSDBInstanceSnapshot,
|
CheckDestroy: testAccCheckAWSDBInstanceSnapshot,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccSnapshotInstanceConfig(),
|
Config: testAccSnapshotInstanceConfig(),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.snapshot", &snap),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.snapshot", &snap),
|
||||||
|
@ -176,7 +176,7 @@ func TestAccAWSDBInstanceNoSnapshot(t *testing.T) {
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSDBInstanceNoSnapshot,
|
CheckDestroy: testAccCheckAWSDBInstanceNoSnapshot,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccNoSnapshotInstanceConfig(),
|
Config: testAccNoSnapshotInstanceConfig(),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.no_snapshot", &nosnap),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.no_snapshot", &nosnap),
|
||||||
|
@ -195,7 +195,7 @@ func TestAccAWSDBInstance_enhancedMonitoring(t *testing.T) {
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSDBInstanceNoSnapshot,
|
CheckDestroy: testAccCheckAWSDBInstanceNoSnapshot,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccSnapshotInstanceConfig_enhancedMonitoring(rName),
|
Config: testAccSnapshotInstanceConfig_enhancedMonitoring(rName),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.enhanced_monitoring", &dbInstance),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.enhanced_monitoring", &dbInstance),
|
||||||
|
@ -220,7 +220,7 @@ func TestAccAWS_separate_DBInstance_iops_update(t *testing.T) {
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccSnapshotInstanceConfig_iopsUpdate(rName, 1000),
|
Config: testAccSnapshotInstanceConfig_iopsUpdate(rName, 1000),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
||||||
|
@ -228,7 +228,7 @@ func TestAccAWS_separate_DBInstance_iops_update(t *testing.T) {
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccSnapshotInstanceConfig_iopsUpdate(rName, 2000),
|
Config: testAccSnapshotInstanceConfig_iopsUpdate(rName, 2000),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
||||||
|
@ -249,7 +249,7 @@ func TestAccAWSDBInstance_portUpdate(t *testing.T) {
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccSnapshotInstanceConfig_mysqlPort(rName),
|
Config: testAccSnapshotInstanceConfig_mysqlPort(rName),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
||||||
|
@ -258,7 +258,7 @@ func TestAccAWSDBInstance_portUpdate(t *testing.T) {
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccSnapshotInstanceConfig_updateMysqlPort(rName),
|
Config: testAccSnapshotInstanceConfig_updateMysqlPort(rName),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
||||||
|
@ -278,7 +278,7 @@ func TestAccAWSDBInstance_MSSQL_TZ(t *testing.T) {
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSDBMSSQL_timezone,
|
Config: testAccAWSDBMSSQL_timezone,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.mssql", &v),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.mssql", &v),
|
||||||
|
@ -290,7 +290,7 @@ func TestAccAWSDBInstance_MSSQL_TZ(t *testing.T) {
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSDBMSSQL_timezone_AKST,
|
Config: testAccAWSDBMSSQL_timezone_AKST,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.mssql", &v),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.mssql", &v),
|
||||||
|
@ -305,6 +305,24 @@ func TestAccAWSDBInstance_MSSQL_TZ(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAWSDBInstance_MinorVersion(t *testing.T) {
|
||||||
|
var v rds.DBInstance
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccAWSDBInstanceConfigAutoMinorVersion,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error {
|
func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
||||||
|
|
||||||
|
@ -1113,3 +1131,16 @@ resource "aws_security_group_rule" "rds-mssql-1" {
|
||||||
security_group_id = "${aws_security_group.rds-mssql.id}"
|
security_group_id = "${aws_security_group.rds-mssql.id}"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
var testAccAWSDBInstanceConfigAutoMinorVersion = fmt.Sprintf(`
|
||||||
|
resource "aws_db_instance" "bar" {
|
||||||
|
identifier = "foobarbaz-test-terraform-%d"
|
||||||
|
allocated_storage = 10
|
||||||
|
engine = "MySQL"
|
||||||
|
engine_version = "5.6"
|
||||||
|
instance_class = "db.t1.micro"
|
||||||
|
name = "baz"
|
||||||
|
password = "barbarbarbar"
|
||||||
|
username = "foo"
|
||||||
|
}
|
||||||
|
`, acctest.RandInt())
|
||||||
|
|
Loading…
Reference in New Issue