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

New Resource: aws_dynamodb_global_table #2517

Merged
merged 4 commits into from
Jan 25, 2018

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Dec 2, 2017

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.

# Consistently after first implementing global table deletion

        * aws_dynamodb_table.us-east-1 (destroy): 1 error(s) occurred:

        * aws_dynamodb_table.us-east-1: ResourceInUseException: Attempt to change a resource which is still in use: Table is being deleted: tf-acc-test-k9l0s
            status code: 400, request id: E45O0ASHK3HNUP8KMU11L75D3FVV4KQNSO5AEMVJF66Q9ASUAAJG

# Consistently after fixing the above

        * aws_dynamodb_table.us-east-1 (destroy): 1 error(s) occurred:

        * aws_dynamodb_table.us-east-1: Error waiting for Dynamo DB Table update: ResourceNotFoundException: Requested resource not found: Table: tf-acc-test-khj7g not found
            status code: 400, request id: RRD7G8M109TJFBH3F8L6JFMHKRVV4KQNSO5AEMVJF66Q9ASUAAJG

Passes testing for me:

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 (92.97s)
=== RUN   TestAccAwsDynamoDbGlobalTable_import
--- PASS: TestAccAwsDynamoDbGlobalTable_import (55.70s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	148.715s

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 (71.61s)
=== RUN   TestAccAWSDynamoDbTable_importTags
--- PASS: TestAccAWSDynamoDbTable_importTags (76.10s)
=== RUN   TestAccAWSDynamoDbTable_basic
--- PASS: TestAccAWSDynamoDbTable_basic (287.11s)
=== RUN   TestAccAWSDynamoDbTable_streamSpecification
--- PASS: TestAccAWSDynamoDbTable_streamSpecification (72.92s)
=== RUN   TestAccAWSDynamoDbTable_tags
--- PASS: TestAccAWSDynamoDbTable_tags (69.01s)
=== RUN   TestAccAWSDynamoDbTable_gsiUpdate
--- PASS: TestAccAWSDynamoDbTable_gsiUpdate (182.58s)
=== RUN   TestAccAWSDynamoDbTable_ttl
--- PASS: TestAccAWSDynamoDbTable_ttl (91.00s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	850.376s

@Ninir Ninir added the enhancement Requests to existing resources that expand the functionality or scope. label Dec 4, 2017
@radeksimko radeksimko added new-resource Introduces a new resource. and removed enhancement Requests to existing resources that expand the functionality or scope. labels Dec 6, 2017
Copy link
Contributor

@Ninir Ninir left a 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,
Copy link
Contributor

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,
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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"]
Copy link
Contributor

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 {
Copy link
Contributor

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)

Copy link
Contributor Author

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,
Copy link
Contributor

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)?

Copy link
Contributor Author

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,
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you fix indentations?

Copy link
Contributor Author

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,
Copy link
Contributor

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?

Copy link
Contributor Author

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,
},
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@Ninir Ninir added the waiting-response Maintainers are waiting on response from community or contributor. label Dec 8, 2017
* Fix using schema.TimeoutCreate on create
* WARN messaging on read when not found and removing from state
* Fix testing indentations
@bflad
Copy link
Contributor Author

bflad commented Dec 9, 2017

PR is updated with:

  • Fix using schema.TimeoutCreate on create
  • WARN messaging on read when not found and removing from state
  • Fix testing indentations

Let me know how you would like to handle the Set hashing/StateChangeConf given my feedback. Thanks!

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 (76.49s)
=== RUN   TestAccAwsDynamoDbGlobalTable_import
--- PASS: TestAccAwsDynamoDbGlobalTable_import (60.13s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	136.652s

@radeksimko radeksimko removed the waiting-response Maintainers are waiting on response from community or contributor. label Dec 11, 2017
@CumpsD
Copy link

CumpsD commented Dec 25, 2017

Thanks @bflad for your work on this! Looking forward to the evolution of this PR into a release 👍

@radeksimko radeksimko requested a review from Ninir January 8, 2018 12:52
@unixengineer
Copy link

Would it be possible to know when this PR would be into the release

@bflad bflad changed the title New Resouce: aws_dynamodb_global_table New Resource: aws_dynamodb_global_table Jan 11, 2018
@bflad bflad added the service/dynamodb Issues and PRs that pertain to the dynamodb service. label Jan 11, 2018
@bflad bflad requested a review from radeksimko January 19, 2018 19:23
@grayaii
Copy link
Contributor

grayaii commented Jan 22, 2018

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
Copy link
Contributor

catsby commented Jan 24, 2018

@bflad / @Ninir is this ready for another review?

@bflad
Copy link
Contributor Author

bflad commented Jan 25, 2018

@catsby yes please!

@bflad
Copy link
Contributor Author

bflad commented Jan 25, 2018

@Ninir per your request I have removed the custom Set hashing 👍

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 (77.41s)
=== RUN   TestAccAwsDynamoDbGlobalTable_import
--- PASS: TestAccAwsDynamoDbGlobalTable_import (54.38s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	131.844s

Copy link
Contributor

@Ninir Ninir left a 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

@Ninir Ninir merged commit 61aa6fe into hashicorp:master Jan 25, 2018
Ninir added a commit that referenced this pull request Jan 25, 2018
@bflad bflad added this to the v1.8.0 milestone Jan 25, 2018
@bflad bflad deleted the aws_dynamodb_global_table branch January 25, 2018 17:32
@bflad
Copy link
Contributor Author

bflad commented Jan 25, 2018

Hi, everyone! This has landed in master and will ship with the v1.8.0 release of the provider, expected tomorrow. Happy Terraform'ing! 🎉

@eric-young-work
Copy link

Thanks, this is great! Sorry if newbish question: will corresponding documentation get released at the same time as the feature release?

@grayaii
Copy link
Contributor

grayaii commented Jan 26, 2018

@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.

@eric-young-work
Copy link

Great, thanks very much!

@bflad
Copy link
Contributor Author

bflad commented Jan 29, 2018

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.

@ghost
Copy link

ghost commented Apr 8, 2020

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!

@ghost ghost locked and limited conversation to collaborators Apr 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource. service/dynamodb Issues and PRs that pertain to the dynamodb service.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add DynamoDB Global Table Support
8 participants