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 storage_encrypted as an optional parameter to aws_rds_cluster #5520

Merged
merged 5 commits into from
Mar 9, 2016
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
9 changes: 9 additions & 0 deletions builtin/providers/aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ func resourceAwsRDSCluster() *schema.Resource {
Computed: true,
},

"storage_encrypted": &schema.Schema{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation update suggests that the default for this value is false - I think we need to actually have this in the schema as follows:

"storage_encrypted": &schema.Schema{
         Type:     schema.TypeBool,
    Optional: true,
        Default: false,
    ForceNew: true,
}

thoughts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default is false if the parameter is omitted from the request, so I see two options. I could either update the schema to include the default value, or I could only set the StorageEncrypted value on the CreateDBClusterInput object if a value is provided. Which do you think is best?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally, I would suggest to be explicit in the terraform schema. This will safeguard against changes in AWS behaviour :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! Fixed in b3864db

Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},

"final_snapshot_identifier": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -167,6 +174,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
Engine: aws.String("aurora"),
MasterUserPassword: aws.String(d.Get("master_password").(string)),
MasterUsername: aws.String(d.Get("master_username").(string)),
StorageEncrypted: aws.Bool(d.Get("storage_encrypted").(bool)),
}

if v := d.Get("database_name"); v.(string) != "" {
Expand Down Expand Up @@ -276,6 +284,7 @@ func resourceAwsRDSClusterRead(d *schema.ResourceData, meta interface{}) error {
d.Set("engine", dbc.Engine)
d.Set("master_username", dbc.MasterUsername)
d.Set("port", dbc.Port)
d.Set("storage_encrypted", dbc.StorageEncrypted)
d.Set("backup_retention_period", dbc.BackupRetentionPeriod)
d.Set("preferred_backup_window", dbc.PreferredBackupWindow)
d.Set("preferred_maintenance_window", dbc.PreferredMaintenanceWindow)
Expand Down
35 changes: 35 additions & 0 deletions builtin/providers/aws/resource_aws_rds_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@ func TestAccAWSRDSCluster_basic(t *testing.T) {
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists("aws_rds_cluster.default", &v),
resource.TestCheckResourceAttr(
"aws_rds_cluster.default", "storage_encrypted", "false"),
),
},
},
})
}

func TestAccAWSRDSCluster_encrypted(t *testing.T) {
var v rds.DBCluster

ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
encConfig := fmt.Sprintf(testAccAWSClusterConfig_encrypted, ri)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: encConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists("aws_rds_cluster.default", &v),
resource.TestCheckResourceAttr(
"aws_rds_cluster.default", "storage_encrypted", "true"),
),
},
},
Expand Down Expand Up @@ -150,6 +175,16 @@ resource "aws_rds_cluster" "default" {
master_password = "mustbeeightcharaters"
}`

var testAccAWSClusterConfig_encrypted = `
resource "aws_rds_cluster" "default" {
cluster_identifier = "tf-aurora-cluster-%d"
availability_zones = ["us-west-2a","us-west-2b","us-west-2c"]
database_name = "mydb"
master_username = "foo"
master_password = "mustbeeightcharaters"
storage_encrypted = true
}`

var testAccAWSClusterConfig_backups = `
resource "aws_rds_cluster" "default" {
cluster_identifier = "tf-aurora-cluster-%d"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Default: A 30-minute window selected at random from an 8-hour block of time per
* `port` - (Optional) The port on which the DB accepts connections
* `vpc_security_group_ids` - (Optional) List of VPC security groups to associate
with the Cluster
* `storage_encrypted` - (Optional) Specifies whether the DB cluster is encrypted. The default is `false` if not specified.
* `apply_immediately` - (Optional) Specifies whether any cluster modifications
are applied immediately, or during the next maintenance window. Default is
`false`. See [Amazon RDS Documentation for more information.](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.DBInstance.Modifying.html)
Expand All @@ -97,7 +98,7 @@ The following attributes are exported:
* `port` - The database port
* `status` - The RDS instance status
* `username` - The master username for the database
* `storage_encrypted` - Specifies whether the DB instance is encrypted
* `storage_encrypted` - Specifies whether the DB cluster is encrypted
* `preferred_backup_window` - The daily time range during which the backups happen

[1]: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.Replication.html
Expand Down