Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copy_tags_to_snapshot attribute for aws_rds_cluster resource #8544

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ func resourceAwsRDSCluster() *schema.Resource {
Set: schema.HashString,
},

"copy_tags_to_snapshot": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"database_name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -428,6 +434,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error

if _, ok := d.GetOk("snapshot_identifier"); ok {
opts := rds.RestoreDBClusterFromSnapshotInput{
CopyTagsToSnapshot: aws.Bool(d.Get("copy_tags_to_snapshot").(bool)),
DBClusterIdentifier: aws.String(identifier),
DeletionProtection: aws.Bool(d.Get("deletion_protection").(bool)),
Engine: aws.String(d.Get("engine").(string)),
Expand Down Expand Up @@ -514,6 +521,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
}
} else if _, ok := d.GetOk("replication_source_identifier"); ok {
createOpts := &rds.CreateDBClusterInput{
CopyTagsToSnapshot: aws.Bool(d.Get("copy_tags_to_snapshot").(bool)),
DBClusterIdentifier: aws.String(identifier),
DeletionProtection: aws.Bool(d.Get("deletion_protection").(bool)),
Engine: aws.String(d.Get("engine").(string)),
Expand Down Expand Up @@ -609,6 +617,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
}
s3_bucket := v.([]interface{})[0].(map[string]interface{})
createOpts := &rds.RestoreDBClusterFromS3Input{
CopyTagsToSnapshot: aws.Bool(d.Get("copy_tags_to_snapshot").(bool)),
DBClusterIdentifier: aws.String(identifier),
DeletionProtection: aws.Bool(d.Get("deletion_protection").(bool)),
Engine: aws.String(d.Get("engine").(string)),
Expand Down Expand Up @@ -724,6 +733,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
}

createOpts := &rds.CreateDBClusterInput{
CopyTagsToSnapshot: aws.Bool(d.Get("copy_tags_to_snapshot").(bool)),
DBClusterIdentifier: aws.String(identifier),
DeletionProtection: aws.Bool(d.Get("deletion_protection").(bool)),
Engine: aws.String(d.Get("engine").(string)),
Expand Down Expand Up @@ -930,6 +940,7 @@ func resourceAwsRDSClusterRead(d *schema.ResourceData, meta interface{}) error {
d.Set("backtrack_window", int(aws.Int64Value(dbc.BacktrackWindow)))
d.Set("backup_retention_period", dbc.BackupRetentionPeriod)
d.Set("cluster_identifier", dbc.DBClusterIdentifier)
d.Set("copy_tags_to_snapshot", dbc.CopyTagsToSnapshot)

var cm []string
for _, m := range dbc.DBClusterMembers {
Expand Down Expand Up @@ -1031,6 +1042,11 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
requestUpdate = true
}

if d.HasChange("copy_tags_to_snapshot") {
req.CopyTagsToSnapshot = aws.Bool(d.Get("copy_tags_to_snapshot").(bool))
requestUpdate = true
}

if d.HasChange("master_password") {
req.MasterUserPassword = aws.String(d.Get("master_password").(string))
requestUpdate = true
Expand Down
50 changes: 50 additions & 0 deletions aws/resource_aws_rds_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func TestAccAWSRDSCluster_basic(t *testing.T) {
testAccCheckAWSClusterExists(resourceName, &dbCluster),
resource.TestMatchResourceAttr(resourceName, "arn", regexp.MustCompile(`^arn:[^:]+:rds:[^:]+:\d{12}:cluster:.+`)),
resource.TestCheckResourceAttr(resourceName, "backtrack_window", "0"),
resource.TestCheckResourceAttr(resourceName, "copy_tags_to_snapshot", "false"),
resource.TestCheckResourceAttr(resourceName, "storage_encrypted", "false"),
resource.TestCheckResourceAttr(resourceName, "db_cluster_parameter_group_name", "default.aurora5.6"),
resource.TestCheckResourceAttrSet(resourceName, "reader_endpoint"),
Expand Down Expand Up @@ -440,6 +441,41 @@ func TestAccAWSRDSCluster_encrypted(t *testing.T) {
})
}

func TestAccAWSRDSCluster_copyTagsToSnapshot(t *testing.T) {
var v rds.DBCluster
rInt := acctest.RandInt()
resourceName := "aws_rds_cluster.default"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSClusterConfigWithCopyTagsToSnapshot(rInt, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "copy_tags_to_snapshot", "true"),
),
},
{
Config: testAccAWSClusterConfigWithCopyTagsToSnapshot(rInt, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "copy_tags_to_snapshot", "false"),
),
},
{
Config: testAccAWSClusterConfigWithCopyTagsToSnapshot(rInt, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "copy_tags_to_snapshot", "true"),
),
},
},
})
}

func TestAccAWSRDSCluster_EncryptedCrossRegionReplication(t *testing.T) {
var primaryCluster rds.DBCluster
var replicaCluster rds.DBCluster
Expand Down Expand Up @@ -2661,3 +2697,17 @@ resource "aws_rds_cluster" "test" {
}
`, rName, rName, rName)
}

func testAccAWSClusterConfigWithCopyTagsToSnapshot(n int, f bool) string {
return fmt.Sprintf(`
resource "aws_rds_cluster" "default" {
cluster_identifier = "tf-aurora-cluster-%[1]d"
availability_zones = ["us-west-2a","us-west-2b","us-west-2c"]
database_name = "mydb"
master_username = "foo"
master_password = "mustbeeightcharaters"
db_cluster_parameter_group_name = "default.aurora5.6"
copy_tags_to_snapshot = %[2]t
skip_final_snapshot = true
}`, n, f)
}
1 change: 1 addition & 0 deletions website/docs/r/rds_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ The following arguments are supported:

* `cluster_identifier` - (Optional, Forces new resources) The cluster identifier. If omitted, Terraform will assign a random, unique identifier.
* `cluster_identifier_prefix` - (Optional, Forces new resource) Creates a unique cluster identifier beginning with the specified prefix. Conflicts with `cluster_identifier`.
* `copy_tags_to_snapshot` – (Optional, boolean) Copy all Cluster `tags` to snapshots. Default is `false`.
* `database_name` - (Optional) Name for an automatically created database on cluster creation. There are different naming restrictions per database engine: [RDS Naming Constraints][5]
* `deletion_protection` - (Optional) If the DB instance should have deletion protection enabled. The database can't be deleted when this value is set to `true`. The default is `false`.
* `master_password` - (Required unless a `snapshot_identifier` or `global_cluster_identifier` is provided) Password for the master DB user. Note that this may
Expand Down