-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Support encryption at rest for DynamoDB tables #3303
Conversation
What more needs to be done in order to get this in to a release? |
I'll try to give this a proper review this week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ewbankkit, excellent job! This is looking pretty decent but I left some comments below. Please let me know if you have any questions or don't have time to finish this up. Thanks!
Also this is kinda funny when I ran it (likely not your fault 😂 ):
=== RUN TestAccAWSDynamoDbTable_encryption
--- FAIL: TestAccAWSDynamoDbTable_encryption (108.17s)
testing.go:513: Step 0 error: Check failed: Check 2/2 error: Provisioned write capacity was 842352298560, not 2!
@@ -167,6 +167,20 @@ func dataSourceAwsDynamoDbTable() *schema.Resource { | |||
Type: schema.TypeInt, | |||
Computed: true, | |||
}, | |||
"encrypt_at_rest": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅 Sorry for this, but could you rename all these encrypt_at_rest
references to server_side_encryption
so they better match the DynamoDB API SSE
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
aws/resource_aws_dynamodb_table.go
Outdated
@@ -250,6 +265,16 @@ func resourceAwsDynamoDbTableCreate(d *schema.ResourceData, meta interface{}) er | |||
} | |||
} | |||
|
|||
if v, ok := d.GetOk("encrypt_at_rest"); ok { | |||
options := v.([]interface{}) | |||
if options[0] == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to check len(options) == 0
s := make([]interface{}, 0)
if s[0] == nil {
log.Println("All is well")
}
# panic: runtime error: index out of range
s := make([]interface{}, 0)
if len(s) == 0 {
log.Println("All is well")
}
# 2018/03/01 15:19:00 All is well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally speaking though, we forego error checking against our own schema.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't GetOk()
guard against len(options) == 0
?
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckInitialAWSDynamoDbTableExists("aws_dynamodb_table.basic-dynamodb-table", &conf), | ||
testAccCheckInitialAWSDynamoDbTableConf("aws_dynamodb_table.basic-dynamodb-table", true), | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please check the Terraform state here?
resource.TestCheckResourceAttr("aws_dynamodb_table.basic-dynamodb-table", "server_side_encryption.#", "1"),
resource.TestCheckResourceAttr("aws_dynamodb_table.basic-dynamodb-table", "server_side_encryption.0.enabled", "true"),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By doing this and removing the extraneous attributes I can now revert the modifications to testAccCheckInitialAWSDynamoDbTableConf
so as not to need the sse bool
parameter
return fmt.Sprintf(` | ||
resource "aws_dynamodb_table" "basic-dynamodb-table" { | ||
name = "%s" | ||
read_capacity = 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please set the test capacities to 1
? 💸
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
type = "S" | ||
} | ||
|
||
attribute { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please remove extraneous attributes/indexes here? We only really care about the encryption setting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
projection_type = "KEYS_ONLY" | ||
} | ||
|
||
encrypt_at_rest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Indentation got thrown off here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do, copy and paste flub
Re-ran acceptance tests:
|
@bflad I have made the changes you suggested (question about the I have noticed that if I create a table
and then change the code to
It looks like I'll need to add a |
Ended up using the |
@ewbankkit sounds like we should add an acceptance test for that case so its not made a regression in the future. I was able to get the existing testing in this PR passing with Maybe we should rework the test suite slightly:
If you don't have time to work on the above, definitely an above and beyond ask, please let us know and we can add commits after yours. 👍 |
@bflad I'll make those suggested changes to the acceptance tests; Should be able to get to them today. |
@bflad I made those changes to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fantastic, thanks for your great work! 🚀
20 tests passed (all tests)
=== RUN TestAccAWSDynamoDbTable_streamSpecificationValidation
--- PASS: TestAccAWSDynamoDbTable_streamSpecificationValidation (3.03s)
=== RUN TestAccAWSDynamoDbTable_basic
--- PASS: TestAccAWSDynamoDbTable_basic (16.83s)
=== RUN TestAccAWSDynamoDbTableItem_rangeKey
--- PASS: TestAccAWSDynamoDbTableItem_rangeKey (23.38s)
=== RUN TestAccAWSDynamoDbTableItem_withMultipleItems
--- PASS: TestAccAWSDynamoDbTableItem_withMultipleItems (23.70s)
=== RUN TestAccAWSDynamoDbTableItem_basic
--- PASS: TestAccAWSDynamoDbTableItem_basic (23.69s)
=== RUN TestAccAWSDynamoDbTableItem_update
--- PASS: TestAccAWSDynamoDbTableItem_update (28.04s)
=== RUN TestAccAWSDynamoDbTable_streamSpecification
--- PASS: TestAccAWSDynamoDbTable_streamSpecification (33.45s)
=== RUN TestAccAWSDynamoDbTable_encryption
--- PASS: TestAccAWSDynamoDbTable_encryption (45.27s)
=== RUN TestAccAWSDynamoDbGlobalTable_import
--- PASS: TestAccAWSDynamoDbGlobalTable_import (51.21s)
=== RUN TestAccAWSDynamoDbGlobalTable_basic
--- PASS: TestAccAWSDynamoDbGlobalTable_basic (59.28s)
=== RUN TestAccAWSDynamoDbTable_importTags
--- PASS: TestAccAWSDynamoDbTable_importTags (72.82s)
=== RUN TestAccAWSDynamoDbTable_tags
--- PASS: TestAccAWSDynamoDbTable_tags (73.55s)
=== RUN TestAccAWSDynamoDbGlobalTable_multipleRegions
--- PASS: TestAccAWSDynamoDbGlobalTable_multipleRegions (86.71s)
=== RUN TestAccAWSDynamoDbTable_ttl
--- PASS: TestAccAWSDynamoDbTable_ttl (102.01s)
=== RUN TestAccAWSDynamoDbTable_gsiUpdateCapacity
--- PASS: TestAccAWSDynamoDbTable_gsiUpdateCapacity (103.15s)
=== RUN TestAccAWSDynamoDbTable_importBasic
--- PASS: TestAccAWSDynamoDbTable_importBasic (110.20s)
=== RUN TestAccAWSDynamoDbTable_importTimeToLive
--- PASS: TestAccAWSDynamoDbTable_importTimeToLive (118.67s)
=== RUN TestAccAWSDynamoDbTable_gsiUpdateNonKeyAttributes
--- PASS: TestAccAWSDynamoDbTable_gsiUpdateNonKeyAttributes (158.37s)
=== RUN TestAccAWSDynamoDbTable_gsiUpdateOtherAttributes
--- PASS: TestAccAWSDynamoDbTable_gsiUpdateOtherAttributes (455.33s)
=== RUN TestAccAWSDynamoDbTable_extended
--- PASS: TestAccAWSDynamoDbTable_extended (470.47s)
This has been released in version 1.11.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Fixes #3298.
Added an
encrypt_at_rest
block toaws_dynamodb_table
resource and data source, similar toaws_elasticsearch_domain
.Acceptance tests: