Skip to content

Commit

Permalink
Merge pull request #4144 from terraform-providers/b-aws_rds_cluster-p…
Browse files Browse the repository at this point in the history
…ort-forcenew

resource/aws_rds_cluster: Set port to force new resource
  • Loading branch information
bflad authored Apr 11, 2018
2 parents edf8bab + 89873ec commit 08ec94e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func resourceAwsRDSCluster() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
},

// apply_immediately is used to determine when the update modifications
Expand Down
57 changes: 57 additions & 0 deletions aws/resource_aws_rds_cluster_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aws

import (
"errors"
"fmt"
"log"
"regexp"
Expand Down Expand Up @@ -331,6 +332,35 @@ func TestAccAWSRDSCluster_EngineVersion(t *testing.T) {
})
}

func TestAccAWSRDSCluster_Port(t *testing.T) {
var dbCluster1, dbCluster2 rds.DBCluster
rInt := acctest.RandInt()
resourceName := "aws_rds_cluster.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSClusterConfig_Port(rInt, 5432),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster1),
resource.TestCheckResourceAttr(resourceName, "port", "5432"),
),
},
{
Config: testAccAWSClusterConfig_Port(rInt, 2345),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster2),
testAccCheckAWSClusterRecreated(&dbCluster1, &dbCluster2),
resource.TestCheckResourceAttr(resourceName, "port", "2345"),
),
},
},
})
}

func testAccCheckAWSClusterDestroy(s *terraform.State) error {
return testAccCheckAWSClusterDestroyWithProvider(s, testAccProvider)
}
Expand Down Expand Up @@ -456,6 +486,16 @@ func testAccCheckAWSClusterExistsWithProvider(n string, v *rds.DBCluster, provid
}
}

func testAccCheckAWSClusterRecreated(i, j *rds.DBCluster) resource.TestCheckFunc {
return func(s *terraform.State) error {
if aws.TimeValue(i.ClusterCreateTime) == aws.TimeValue(j.ClusterCreateTime) {
return errors.New("RDS Cluster was not recreated")
}

return nil
}
}

func testAccAWSClusterConfig(n int) string {
return fmt.Sprintf(`
resource "aws_rds_cluster" "default" {
Expand Down Expand Up @@ -709,6 +749,23 @@ resource "aws_rds_cluster" "test" {
}`, rInt, engine, engineVersion)
}

func testAccAWSClusterConfig_Port(rInt, port int) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {}
resource "aws_rds_cluster" "test" {
availability_zones = ["${data.aws_availability_zones.available.names}"]
cluster_identifier = "tf-acc-test-%d"
database_name = "mydb"
db_cluster_parameter_group_name = "default.aurora-postgresql9.6"
engine = "aurora-postgresql"
master_password = "mustbeeightcharaters"
master_username = "foo"
port = %d
skip_final_snapshot = true
}`, rInt, port)
}

func testAccAWSClusterConfigIncludingIamRoles(n int) string {
return fmt.Sprintf(`
resource "aws_iam_role" "rds_sample_role" {
Expand Down

0 comments on commit 08ec94e

Please sign in to comment.