Skip to content

Commit

Permalink
resource/aws_db_instance: Address #5378 PR feedback
Browse files Browse the repository at this point in the history
* Ensure d.Set() is always called for domain and domain_iam_role_name
* Remove extraneous d.IsNewResource() check in Update function
* Randomize IAM role naming for new domain acceptance tests
  • Loading branch information
bflad committed Sep 6, 2018
1 parent 49aeccf commit 5a55e2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
4 changes: 3 additions & 1 deletion aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,8 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error setting enabled_cloudwatch_logs_exports: %s", err)
}

d.Set("domain", "")
d.Set("domain_iam_role_name", "")
if len(v.DomainMemberships) > 0 && v.DomainMemberships[0] != nil {
d.Set("domain", v.DomainMemberships[0].Domain)
d.Set("domain_iam_role_name", v.DomainMemberships[0].IAMRoleName)
Expand Down Expand Up @@ -1443,7 +1445,7 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error
requestUpdate = true
}

if (d.HasChange("domain") || d.HasChange("domain_iam_role_name")) && !d.IsNewResource() {
if d.HasChange("domain") || d.HasChange("domain_iam_role_name") {
d.SetPartial("domain")
d.SetPartial("domain_iam_role_name")
req.Domain = aws.String(d.Get("domain").(string))
Expand Down
33 changes: 12 additions & 21 deletions aws/resource_aws_db_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2586,7 +2586,7 @@ resource "aws_directory_service_directory" "bar" {
}
resource "aws_iam_role" "role" {
name = "tf-acc-db-instance-mssql-domain-role"
name = "tf-acc-db-instance-mssql-domain-role-%d"
assume_role_policy = <<EOF
{
Expand All @@ -2609,7 +2609,7 @@ resource "aws_iam_role_policy_attachment" "attatch-policy" {
role = "${aws_iam_role.role.name}"
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSDirectoryServiceAccess"
}
`, rInt, rInt, rInt)
`, rInt, rInt, rInt, rInt)
}

func testAccAWSDBMSSQLUpdateDomain(rInt int) string {
Expand Down Expand Up @@ -2709,7 +2709,7 @@ resource "aws_directory_service_directory" "bar" {
}
resource "aws_iam_role" "role" {
name = "tf-acc-db-instance-mssql-domain-role"
name = "tf-acc-db-instance-mssql-domain-role-%d"
assume_role_policy = <<EOF
{
Expand All @@ -2732,7 +2732,7 @@ resource "aws_iam_role_policy_attachment" "attatch-policy" {
role = "${aws_iam_role.role.name}"
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSDirectoryServiceAccess"
}
`, rInt, rInt, rInt)
`, rInt, rInt, rInt, rInt)
}

func testAccAWSDBMSSQLDomainSnapshotRestore(rInt int) string {
Expand Down Expand Up @@ -2771,22 +2771,13 @@ resource "aws_subnet" "other" {
}
resource "aws_db_instance" "mssql" {
identifier = "tf-test-mssql-%d"
db_subnet_group_name = "${aws_db_subnet_group.rds_one.name}"
instance_class = "db.t2.micro"
allocated_storage = 20
username = "somecrazyusername"
password = "somecrazypassword"
engine = "sqlserver-ex"
backup_retention_period = 0
allocated_storage = 20
engine = "sqlserver-ex"
identifier = "tf-test-mssql-%d"
instance_class = "db.t2.micro"
password = "somecrazypassword"
skip_final_snapshot = true
domain = "${aws_directory_service_directory.foo.id}"
domain_iam_role_name = "${aws_iam_role.role.name}"
vpc_security_group_ids = ["${aws_security_group.rds-mssql.id}"]
username = "somecrazyusername"
}
resource "aws_db_snapshot" "mssql-snap" {
Expand Down Expand Up @@ -2845,7 +2836,7 @@ resource "aws_directory_service_directory" "foo" {
}
resource "aws_iam_role" "role" {
name = "tf-acc-db-instance-mssql-domain-role"
name = "tf-acc-db-instance-mssql-domain-role-%d"
assume_role_policy = <<EOF
{
Expand All @@ -2868,7 +2859,7 @@ resource "aws_iam_role_policy_attachment" "attatch-policy" {
role = "${aws_iam_role.role.name}"
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSDirectoryServiceAccess"
}
`, rInt, rInt, rInt, rInt)
`, rInt, rInt, rInt, rInt, rInt)
}

var testAccAWSDBInstanceConfigAutoMinorVersion = fmt.Sprintf(`
Expand Down

0 comments on commit 5a55e2d

Please sign in to comment.