-
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
New Resource: aws_dynamodb_global_table #2517
Conversation
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 @bflad
Thanks a lot for the awesome & clean work, really appreciated! :)
Just left a few comments to address, mostly nitpicks & comments to better understand :)
$ make testacc TEST=./aws TESTARGS='-run=TestAccAwsDynamoDbGlobalTable'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAwsDynamoDbGlobalTable -timeout 120m
=== RUN TestAccAwsDynamoDbGlobalTable_basic
--- PASS: TestAccAwsDynamoDbGlobalTable_basic (144.88s)
=== RUN TestAccAwsDynamoDbGlobalTable_import
--- PASS: TestAccAwsDynamoDbGlobalTable_import (51.27s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 196.195s
$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSDynamoDbTable'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSDynamoDbTable -timeout 120m
=== RUN TestAccAWSDynamoDbTable_importBasic
--- PASS: TestAccAWSDynamoDbTable_importBasic (105.07s)
=== RUN TestAccAWSDynamoDbTable_importTags
--- PASS: TestAccAWSDynamoDbTable_importTags (62.06s)
=== RUN TestAccAWSDynamoDbTable_basic
--- PASS: TestAccAWSDynamoDbTable_basic (346.33s)
=== RUN TestAccAWSDynamoDbTable_streamSpecification
--- PASS: TestAccAWSDynamoDbTable_streamSpecification (55.17s)
=== RUN TestAccAWSDynamoDbTable_tags
--- PASS: TestAccAWSDynamoDbTable_tags (55.60s)
=== RUN TestAccAWSDynamoDbTable_gsiUpdate
--- PASS: TestAccAWSDynamoDbTable_gsiUpdate (134.70s)
=== RUN TestAccAWSDynamoDbTable_ttl
--- PASS: TestAccAWSDynamoDbTable_ttl (65.53s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 824.510s
Pending: []string{ | ||
dynamodb.GlobalTableStatusCreating, | ||
dynamodb.GlobalTableStatusDeleting, | ||
dynamodb.GlobalTableStatusUpdating, |
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.
👍 for constants usage
}, | ||
}, | ||
}, | ||
Set: resourceAwsDynamoDbGlobalTableReplicaHash, |
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.
The logic managing hashes in the background already takes care of managing hashes so this shouldn't be needed
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 was prematurely optimizing here for if/when Amazon adds other attributes for replicas since region_name is what will always trigger the create/remove replica calls. I'll remove the currently extraneous configuration.
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.
Actually, I think this is required. 😄 We cannot use schema.HashString
here since this is a map element, not a set of just string
elements.
panic: interface conversion: interface {} is map[string]interface {}, not string
goroutine 693 [running]:
github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform/helper/schema.HashString(0x31eaac0, 0xc420576210, 0xc4205b4ef8)
} | ||
|
||
resource "aws_dynamodb_global_table" "myTable" { | ||
depends_on = ["aws_dynamodb_table.us-east-1", "aws_dynamodb_table.us-west-2"] |
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 fix indentations?
if err != nil { | ||
return err | ||
} | ||
if globalTableDescription == 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.
We should log log.Printf("[WARN] DynamoDB Global Table %q not found, removing from state", dashboardName)
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 will add this, thanks!
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{ | ||
dynamodb.GlobalTableStatusCreating, | ||
dynamodb.GlobalTableStatusDeleting, |
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.
Do we need to handle this status when creating a table (and the updating one also)?
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 added this as edge-case protection if we miss ACTIVE
between check intervals for an immediate update or something like deletion happens outside Terraform during the creation.
When StateChangeConf
sees an unexpected state, it will complain with an error that seems less friendly than our refresh function's error: Error on retrieving DynamoDB Global Table when waiting
or hitting a timeout.
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{ | ||
dynamodb.GlobalTableStatusCreating, | ||
dynamodb.GlobalTableStatusDeleting, |
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.
Do we need to handle this status or the one above when updating?
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.
Same logic as mentioned before, I added this purely for friendlier edge-case messaging. Maybe we could drop these, but leaving them could still handle the extremely weird case someone manages to delete and recreate a global table while updating (e.g. tainting one of two overlapping resources then Terraform running both in parallel).
return nil | ||
} | ||
|
||
return flattenAwsDynamoDbGlobalTable(d, globalTableDescription) |
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.
Is there a reason to have this as a separated function? I think it would be more consistent with other resources to keep setting attributes in the read function. What do you think?
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 is so we can reuse this code support a aws_dynamodb_global_table
data source in the future, if we would like.
%s | ||
|
||
resource "aws_dynamodb_global_table" "test" { | ||
depends_on = ["aws_dynamodb_table.us-east-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.
Can you fix indentations?
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 about that! VS Code thinks I want to continue with tabs to match the rest of the file instead of noticing its inside backticks 🙁
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{ | ||
dynamodb.TableStatusActive, | ||
dynamodb.TableStatusCreating, |
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.
Could this be a pending state when destroying?
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.
Same logic about edge-cases as mentioned before. Let me know if you think I'm overthinking this.
"arn": { | ||
Type: schema.TypeString, | ||
Computed: 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.
Do you think it is worth having ReplicationGroup
as an attribute also?
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 felt the extra attribute nesting to strictly follow the API would've made the resource needlessly complex here and opted for the Set of replica
. If you feel like it should be nested under a replication_group
, please let me know and I'll add that in.
* Fix using schema.TimeoutCreate on create * WARN messaging on read when not found and removing from state * Fix testing indentations
PR is updated with:
Let me know how you would like to handle the Set hashing/StateChangeConf given my feedback. Thanks!
|
Thanks @bflad for your work on this! Looking forward to the evolution of this PR into a release 👍 |
Would it be possible to know when this PR would be into the release |
I just wanted to say that I compiled the for darwin and linux and I have already started using this for our environments. No issues at all so far! The documentation is spot on. Thank you for doing the work to make this a reality! |
@catsby yes please! |
@Ninir per your request I have removed the custom Set hashing 👍
|
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.
Hey @bflad
Looks very good to me, thanks! 🤖 🚀
$ make testacc TEST=./aws TESTARGS='-run=\(TestAccAwsDynamoDbGlobalTable\|TestAccAWSDynamoDbTable\)'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=\(TestAccAwsDynamoDbGlobalTable\|TestAccAWSDynamoDbTable\) -timeout 120m
=== RUN TestAccAWSDynamoDbTable_importBasic
--- PASS: TestAccAWSDynamoDbTable_importBasic (73.49s)
=== RUN TestAccAWSDynamoDbTable_importTags
--- PASS: TestAccAWSDynamoDbTable_importTags (91.57s)
=== RUN TestAccAwsDynamoDbGlobalTable_basic
--- PASS: TestAccAwsDynamoDbGlobalTable_basic (128.93s)
=== RUN TestAccAwsDynamoDbGlobalTable_import
--- PASS: TestAccAwsDynamoDbGlobalTable_import (87.83s)
=== RUN TestAccAWSDynamoDbTable_basic
--- PASS: TestAccAWSDynamoDbTable_basic (265.44s)
=== RUN TestAccAWSDynamoDbTable_streamSpecification
--- PASS: TestAccAWSDynamoDbTable_streamSpecification (75.28s)
=== RUN TestAccAWSDynamoDbTable_tags
--- PASS: TestAccAWSDynamoDbTable_tags (104.93s)
=== RUN TestAccAWSDynamoDbTable_gsiUpdate
--- PASS: TestAccAWSDynamoDbTable_gsiUpdate (184.11s)
=== RUN TestAccAWSDynamoDbTable_ttl
--- PASS: TestAccAWSDynamoDbTable_ttl (89.09s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 1100.729s
Hi, everyone! This has landed in master and will ship with the v1.8.0 release of the provider, expected tomorrow. Happy Terraform'ing! 🎉 |
Thanks, this is great! Sorry if newbish question: will corresponding documentation get released at the same time as the feature release? |
@eric-young-work Yes, the PR contains the documentation. I used it myself to create my global tables and it works like a charm. If you click the "Files changed" at the link, you'll see the documentation changes. |
Great, thanks very much! |
This has been released in terraform-provider-aws version 1.8.0. 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! |
Closes #2482
Sorry for the additional changes inside
aws_dynamodb_table
, however I was receiving these errors and decided to clean up the deletion logic a little.Passes testing for me: