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 support for tag-on-create for dynamodb tables #8469

Merged
merged 2 commits into from
May 14, 2019

Conversation

sunilkumarmohanty
Copy link
Contributor

Fixes #8442

Changes proposed in this pull request:

  • Add support for tag-on-create for dynamodb tables
  • Refactor dynamodb tags support files

Output from acceptance testing:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSDynamoDbTable_tags'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -parallel 20 -run=TestAccAWSDynamoDbTable_tags -timeout 120m
=== RUN   TestAccAWSDynamoDbTable_tags
=== PAUSE TestAccAWSDynamoDbTable_tags
=== CONT  TestAccAWSDynamoDbTable_tags
--- PASS: TestAccAWSDynamoDbTable_tags (156.25s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       156.294s

@ghost ghost added size/XL Managed by automation to categorize the size of a PR. service/dynamodb Issues and PRs that pertain to the dynamodb service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Apr 27, 2019
@bflad bflad added the enhancement Requests to existing resources that expand the functionality or scope. label May 14, 2019
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Thanks @sunilkumarmohanty! Looks good other than the adjustments required for AWS GovCloud (US) which will be handled on merge. 🚀

After the mentioned code changes:

Output from AWS Standard acceptance testing:

--- PASS: TestAccAWSDynamoDbTable_streamSpecificationValidation (5.74s)
--- PASS: TestAccAWSDynamoDbTable_attributeUpdateValidation (6.49s)
--- PASS: TestAccAWSDynamoDbTable_basic (25.94s)
--- PASS: TestAccAWSDynamoDbTable_streamSpecification (74.28s)
--- PASS: TestAccAWSDynamoDbTable_gsiUpdateCapacity (112.39s)
--- PASS: TestAccAWSDynamoDbTable_disappears (112.60s)
--- PASS: TestAccAWSDynamoDbTable_Ttl_Enabled (120.12s)
--- PASS: TestAccAWSDynamoDbTable_Ttl_Disabled (129.84s)
--- PASS: TestAccAWSDynamoDbTable_BillingMode_PayPerRequestToProvisioned (142.69s)
--- PASS: TestAccAWSDynamoDbTable_tags (144.83s)
--- PASS: TestAccAWSDynamoDbTable_BillingMode_GSI_PayPerRequestToProvisioned (173.16s)
--- PASS: TestAccAWSDynamoDbTable_importBasic (176.86s)
--- PASS: TestAccAWSDynamoDbTable_importTags (171.77s)
--- PASS: TestAccAWSDynamoDbTable_disappears_PayPerRequestWithGSI (182.13s)
--- PASS: TestAccAWSDynamoDbTable_encryption (234.29s)
--- PASS: TestAccAWSDynamoDbTable_enablePitr (371.32s)
--- PASS: TestAccAWSDynamoDbTable_gsiUpdateNonKeyAttributes (392.32s)
--- PASS: TestAccAWSDynamoDbTable_extended (399.61s)
--- PASS: TestAccAWSDynamoDbTable_BillingMode_GSI_ProvisionedToPayPerRequest (652.60s)
--- PASS: TestAccAWSDynamoDbTable_gsiUpdateOtherAttributes (709.56s)
--- PASS: TestAccAWSDynamoDbTable_attributeUpdate (710.63s)
--- PASS: TestAccAWSDynamoDbTable_BillingMode_ProvisionedToPayPerRequest (939.12s)

Output from AWS GovCloud (US) acceptance testing (test failures unrelated -- we really need a PreCheck for billing mode support):

--- PASS: TestAccAWSDynamoDbTable_streamSpecificationValidation (7.34s)
--- PASS: TestAccAWSDynamoDbTable_attributeUpdateValidation (8.56s)
--- FAIL: TestAccAWSDynamoDbTable_BillingMode_PayPerRequestToProvisioned (11.42s)
    testing.go:568: Step 0 error: errors during apply:

        Error: error creating DynamoDB Table: ValidationException: One or more parameter values were invalid: Missing required parameter in input: "ProvisionedThroughput"
...


--- FAIL: TestAccAWSDynamoDbTable_BillingMode_GSI_PayPerRequestToProvisioned (11.58s)
    testing.go:568: Step 0 error: errors during apply:

        Error: error creating DynamoDB Table: ValidationException: One or more parameter values were invalid: Missing required parameter in input: "ProvisionedThroughput"
...


--- FAIL: TestAccAWSDynamoDbTable_disappears_PayPerRequestWithGSI (8.16s)
    testing.go:568: Step 0 error: errors during apply:

        Error: error creating DynamoDB Table: ValidationException: One or more parameter values were invalid: Missing required parameter in input: "ProvisionedThroughput"
...


--- FAIL: TestAccAWSDynamoDbTable_BillingMode_GSI_ProvisionedToPayPerRequest (83.58s)
    testing.go:568: Step 1 error: errors during apply:

        Error: error updating DynamoDB Table (TerraformTestTable--1046408333877050005): ValidationException: One or more parameter values were invalid: Unsupported input parameter BillingMode
...


--- PASS: TestAccAWSDynamoDbTable_disappears (117.29s)
--- PASS: TestAccAWSDynamoDbTable_basic (122.23s)

--- FAIL: TestAccAWSDynamoDbTable_BillingMode_ProvisionedToPayPerRequest (128.19s)
    testing.go:568: Step 1 error: errors during apply:

        Error: error updating DynamoDB Table (TerraformTestTable--2469300233617270204): ValidationException: One or more parameter values were invalid: Unsupported input parameter BillingMode
...

--- PASS: TestAccAWSDynamoDbTable_Ttl_Enabled (128.48s)
--- PASS: TestAccAWSDynamoDbTable_tags (149.84s)
--- PASS: TestAccAWSDynamoDbTable_importBasic (153.64s)
--- PASS: TestAccAWSDynamoDbTable_streamSpecification (163.73s)

--- FAIL: TestAccAWSDynamoDbTable_extended (167.14s)
    testing.go:568: Step 1 error: errors during apply:

        Error: error updating DynamoDB Table (TerraformTestTable--9088649623966159339): ValidationException: One or more parameter values were invalid: Unsupported input parameter BillingMode
...


--- PASS: TestAccAWSDynamoDbTable_importTags (184.51s)

--- FAIL: TestAccAWSDynamoDbTable_gsiUpdateCapacity (187.35s)
    testing.go:568: Step 1 error: errors during apply:

        Error: error updating DynamoDB Table (tf-acc-test-9zdhg0lxlw): ValidationException: One or more parameter values were invalid: Unsupported input parameter BillingMode
...


--- PASS: TestAccAWSDynamoDbTable_encryption (251.59s)
--- PASS: TestAccAWSDynamoDbTable_Ttl_Disabled (287.78s)
--- PASS: TestAccAWSDynamoDbTable_gsiUpdateNonKeyAttributes (322.48s)
--- PASS: TestAccAWSDynamoDbTable_attributeUpdate (617.31s)
--- PASS: TestAccAWSDynamoDbTable_gsiUpdateOtherAttributes (619.70s)
--- PASS: TestAccAWSDynamoDbTable_enablePitr (968.79s)

if d.HasChange("tags") {
if err := setTagsDynamoDb(conn, d); err != nil {
return fmt.Errorf("error updating DynamoDB Table (%s) tags: %s", d.Id(), err)
if !d.IsNewResource() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It appears that the Create function returns the Read function instead of the Update function (as is best practice) so this check is extraneous. 👍

req := &dynamodb.CreateTableInput{
TableName: aws.String(d.Get("name").(string)),
BillingMode: aws.String(d.Get("billing_mode").(string)),
KeySchema: expandDynamoDbKeySchema(keySchemaMap),
Tags: tags,
Copy link
Contributor

Choose a reason for hiding this comment

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

It appears that AWS GovCloud (US) has unfortunately not been updated for tag-on-create support yet, returning the following error:

--- FAIL: TestAccAWSDynamoDbTable_basic (9.68s)
    testing.go:568: Step 0 error: errors during apply:

        Error: error creating DynamoDB Table: ValidationException: Unsupported input parameter Tags

To workaround this error while automatically supporting tag-on-create without code change in the future, we can catch this specific error during our resource.Retry() logic, set the parameter to nil, and perform a similar tagging API call after creation as it did previously. e.g.

	var requiresTagging bool
// ...
			// AWS GovCloud (US) and others may reply with the following until their API is updated:
			// ValidationException: Unsupported input parameter Tags
			if isAWSErr(err, "ValidationException", "Unsupported input parameter Tags") {
				req.Tags = nil
				requiresTagging = true
				return resource.RetryableError(err)
			}
// ...
	if requiresTagging {
		if err := setTagsDynamoDb(conn, d); err != nil {
			return fmt.Errorf("error adding DynamoDB Table (%s) tags: %s", d.Id(), err)
		}
	}

@bflad bflad added this to the v2.11.0 milestone May 14, 2019
@bflad bflad merged commit 96943bb into hashicorp:master May 14, 2019
bflad added a commit that referenced this pull request May 14, 2019
@bflad
Copy link
Contributor

bflad commented May 17, 2019

This has been released in version 2.11.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Mar 30, 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 Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/dynamodb Issues and PRs that pertain to the dynamodb service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

r/aws_dynamodb_table: Add support for tag-on-create
2 participants