provider/aws: added auto_minor_version_upgrade on aws_rds_cluster_instance (#10284)

This commit is contained in:
Ninir 2016-11-22 12:33:01 +01:00 committed by Paul Stack
parent f35d02cbee
commit b52813b639
3 changed files with 86 additions and 29 deletions

View File

@ -14,11 +14,11 @@ func TestAccAWSDBInstance_importBasic(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBInstanceDestroy, CheckDestroy: testAccCheckAWSDBInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSDBInstanceConfig, Config: testAccAWSDBInstanceConfig,
}, },
resource.TestStep{ {
ResourceName: resourceName, ResourceName: resourceName,
ImportState: true, ImportState: true,
ImportStateVerify: true, ImportStateVerify: true,

View File

@ -22,53 +22,53 @@ func resourceAwsRDSClusterInstance() *schema.Resource {
}, },
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"identifier": &schema.Schema{ "identifier": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
ValidateFunc: validateRdsId, ValidateFunc: validateRdsId,
}, },
"db_subnet_group_name": &schema.Schema{ "db_subnet_group_name": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
Computed: true, Computed: true,
}, },
"writer": &schema.Schema{ "writer": {
Type: schema.TypeBool, Type: schema.TypeBool,
Computed: true, Computed: true,
}, },
"cluster_identifier": &schema.Schema{ "cluster_identifier": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: true, ForceNew: true,
}, },
"endpoint": &schema.Schema{ "endpoint": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"port": &schema.Schema{ "port": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"publicly_accessible": &schema.Schema{ "publicly_accessible": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Default: false, Default: false,
}, },
"instance_class": &schema.Schema{ "instance_class": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
}, },
"db_parameter_group_name": &schema.Schema{ "db_parameter_group_name": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true, Computed: true,
@ -77,35 +77,41 @@ func resourceAwsRDSClusterInstance() *schema.Resource {
// apply_immediately is used to determine when the update modifications // apply_immediately is used to determine when the update modifications
// take place. // take place.
// See http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.DBInstance.Modifying.html // See http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.DBInstance.Modifying.html
"apply_immediately": &schema.Schema{ "apply_immediately": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Computed: true, Computed: true,
}, },
"kms_key_id": &schema.Schema{ "kms_key_id": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"storage_encrypted": &schema.Schema{ "storage_encrypted": {
Type: schema.TypeBool, Type: schema.TypeBool,
Computed: true, Computed: true,
}, },
"monitoring_role_arn": &schema.Schema{ "auto_minor_version_upgrade": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"monitoring_role_arn": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true, Computed: true,
}, },
"monitoring_interval": &schema.Schema{ "monitoring_interval": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Default: 0, Default: 0,
}, },
"promotion_tier": &schema.Schema{ "promotion_tier": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Default: 0, Default: 0,
@ -126,6 +132,7 @@ func resourceAwsRDSClusterInstanceCreate(d *schema.ResourceData, meta interface{
Engine: aws.String("aurora"), Engine: aws.String("aurora"),
PubliclyAccessible: aws.Bool(d.Get("publicly_accessible").(bool)), PubliclyAccessible: aws.Bool(d.Get("publicly_accessible").(bool)),
PromotionTier: aws.Int64(int64(d.Get("promotion_tier").(int))), PromotionTier: aws.Int64(int64(d.Get("promotion_tier").(int))),
AutoMinorVersionUpgrade: aws.Bool(d.Get("auto_minor_version_upgrade").(bool)),
Tags: tags, Tags: tags,
} }
@ -230,6 +237,7 @@ func resourceAwsRDSClusterInstanceRead(d *schema.ResourceData, meta interface{})
d.Set("identifier", db.DBInstanceIdentifier) d.Set("identifier", db.DBInstanceIdentifier)
d.Set("storage_encrypted", db.StorageEncrypted) d.Set("storage_encrypted", db.StorageEncrypted)
d.Set("kms_key_id", db.KmsKeyId) d.Set("kms_key_id", db.KmsKeyId)
d.Set("auto_minor_version_upgrade", db.AutoMinorVersionUpgrade)
d.Set("promotion_tier", db.PromotionTier) d.Set("promotion_tier", db.PromotionTier)
if db.MonitoringInterval != nil { if db.MonitoringInterval != nil {
@ -269,13 +277,11 @@ func resourceAwsRDSClusterInstanceUpdate(d *schema.ResourceData, meta interface{
if d.HasChange("db_parameter_group_name") { if d.HasChange("db_parameter_group_name") {
req.DBParameterGroupName = aws.String(d.Get("db_parameter_group_name").(string)) req.DBParameterGroupName = aws.String(d.Get("db_parameter_group_name").(string))
requestUpdate = true requestUpdate = true
} }
if d.HasChange("instance_class") { if d.HasChange("instance_class") {
req.DBInstanceClass = aws.String(d.Get("instance_class").(string)) req.DBInstanceClass = aws.String(d.Get("instance_class").(string))
requestUpdate = true requestUpdate = true
} }
if d.HasChange("monitoring_role_arn") { if d.HasChange("monitoring_role_arn") {
@ -290,6 +296,12 @@ func resourceAwsRDSClusterInstanceUpdate(d *schema.ResourceData, meta interface{
requestUpdate = true requestUpdate = true
} }
if d.HasChange("auto_minor_version_upgrade") {
d.SetPartial("auto_minor_version_upgrade")
req.AutoMinorVersionUpgrade = aws.Bool(d.Get("auto_minor_version_upgrade").(bool))
requestUpdate = true
}
if d.HasChange("promotion_tier") { if d.HasChange("promotion_tier") {
d.SetPartial("promotion_tier") d.SetPartial("promotion_tier")
req.PromotionTier = aws.Int64(int64(d.Get("promotion_tier").(int))) req.PromotionTier = aws.Int64(int64(d.Get("promotion_tier").(int)))

View File

@ -24,11 +24,20 @@ func TestAccAWSRDSClusterInstance_basic(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy, CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSClusterInstanceConfig(acctest.RandInt()), Config: testAccAWSClusterInstanceConfig(acctest.RandInt()),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &v), testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &v),
testAccCheckAWSDBClusterInstanceAttributes(&v), testAccCheckAWSDBClusterInstanceAttributes(&v),
resource.TestCheckResourceAttr("aws_rds_cluster_instance.cluster_instances", "auto_minor_version_upgrade", "true"),
),
},
{
Config: testAccAWSClusterInstanceConfigModified(acctest.RandInt()),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &v),
testAccCheckAWSDBClusterInstanceAttributes(&v),
resource.TestCheckResourceAttr("aws_rds_cluster_instance.cluster_instances", "auto_minor_version_upgrade", "false"),
), ),
}, },
}, },
@ -44,7 +53,7 @@ func TestAccAWSRDSClusterInstance_kmsKey(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy, CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSClusterInstanceConfigKmsKey(acctest.RandInt()), Config: testAccAWSClusterInstanceConfigKmsKey(acctest.RandInt()),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &v), testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &v),
@ -65,7 +74,7 @@ func TestAccAWSRDSClusterInstance_disappears(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy, CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSClusterInstanceConfig(acctest.RandInt()), Config: testAccAWSClusterInstanceConfig(acctest.RandInt()),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &v), testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &v),
@ -195,7 +204,7 @@ func TestAccAWSRDSClusterInstance_withInstanceEnhancedMonitor(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy, CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSClusterInstanceEnhancedMonitor(acctest.RandInt()), Config: testAccAWSClusterInstanceEnhancedMonitor(acctest.RandInt()),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &v), testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &v),
@ -242,6 +251,42 @@ resource "aws_db_parameter_group" "bar" {
`, n, n, n) `, n, n, n)
} }
func testAccAWSClusterInstanceConfigModified(n int) string {
return fmt.Sprintf(`
resource "aws_rds_cluster" "default" {
cluster_identifier = "tf-aurora-cluster-test-%d"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
database_name = "mydb"
master_username = "foo"
master_password = "mustbeeightcharaters"
}
resource "aws_rds_cluster_instance" "cluster_instances" {
identifier = "tf-cluster-instance-%d"
cluster_identifier = "${aws_rds_cluster.default.id}"
instance_class = "db.r3.large"
db_parameter_group_name = "${aws_db_parameter_group.bar.name}"
auto_minor_version_upgrade = false
promotion_tier = "3"
}
resource "aws_db_parameter_group" "bar" {
name = "tfcluster-test-group-%d"
family = "aurora5.6"
parameter {
name = "back_log"
value = "32767"
apply_method = "pending-reboot"
}
tags {
foo = "bar"
}
}
`, n, n, n)
}
func testAccAWSClusterInstanceConfigKmsKey(n int) string { func testAccAWSClusterInstanceConfigKmsKey(n int) string {
return fmt.Sprintf(` return fmt.Sprintf(`