-
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
resource/aws_dynamodb_table: Refactoring #3136
Conversation
428dd94
to
f89850f
Compare
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.
Overall this is looking really good and is very needed. Most of my comments are nitpicks although I think the testing comments and the one about using delete()
are pretty valid.
Good news is that testing passes for me locally as well at the moment:
make testacc TEST=./aws TESTARGS='-run=TestAccAWSDynamoDb'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSDynamoDb -timeout 120m
=== RUN TestAccAWSDynamoDbTable_importBasic
--- PASS: TestAccAWSDynamoDbTable_importBasic (55.20s)
=== RUN TestAccAWSDynamoDbTable_importTags
--- PASS: TestAccAWSDynamoDbTable_importTags (53.65s)
=== RUN TestAccAWSDynamoDbTable_importTimeToLive
--- PASS: TestAccAWSDynamoDbTable_importTimeToLive (53.93s)
=== RUN TestAccAWSDynamoDbTable_basic
--- PASS: TestAccAWSDynamoDbTable_basic (380.55s)
=== RUN TestAccAWSDynamoDbTable_streamSpecification
--- PASS: TestAccAWSDynamoDbTable_streamSpecification (53.85s)
=== RUN TestAccAWSDynamoDbTable_tags
--- PASS: TestAccAWSDynamoDbTable_tags (53.34s)
=== RUN TestAccAWSDynamoDbTable_gsiUpdateCapacity
--- PASS: TestAccAWSDynamoDbTable_gsiUpdateCapacity (131.84s)
=== RUN TestAccAWSDynamoDbTable_gsiUpdateOtherAttributes
--- PASS: TestAccAWSDynamoDbTable_gsiUpdateOtherAttributes (675.47s)
=== RUN TestAccAWSDynamoDbTable_gsiUpdateNonKeyAttributes
--- PASS: TestAccAWSDynamoDbTable_gsiUpdateNonKeyAttributes (312.27s)
=== RUN TestAccAWSDynamoDbTable_ttl
--- PASS: TestAccAWSDynamoDbTable_ttl (61.38s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 1831.522s
) | ||
|
||
// Number of times to retry if a throttling-related exception occurs | ||
const DYNAMODB_MAX_THROTTLE_RETRIES = 5 |
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.
👋 bye bye
|
||
return resourceAwsDynamoDbTableRead(d, meta) | ||
} | ||
if err := waitForDynamoDbTableToBeActive(d.Id(), 10*time.Minute, conn); err != 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.
Nitpick: below for update we're using d.Timeout()
:
waitForDynamoDbTableToBeActive(d.Id(), d.Timeout(schema.TimeoutUpdate), conn)
Should we do the same here with schema.TimeoutCreate
?
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 had that in the original PR but removed it to keep the PR's scope minimal, ideally no-op. But agreed otherwise.
aws/resource_aws_dynamodb_table.go
Outdated
ProvisionedThroughput: throughput, | ||
KeySchema: keyschema, | ||
TableName: aws.String(d.Get("name").(string)), | ||
ProvisionedThroughput: &dynamodb.ProvisionedThroughput{ |
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: we have mixed usage of &dynamodb.ProvisionedThroughput{}
and expandDynamoDbProvisionedThroughput
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.
Good catch - I'll unify that all to expandDynamoDbProvisionedThroughput
👍
aws/resource_aws_dynamodb_table.go
Outdated
|
||
_, err := dynamodbconn.UpdateTable(req) | ||
|
||
ProvisionedThroughput: &dynamodb.ProvisionedThroughput{ |
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: we have mixed usage of &dynamodb.ProvisionedThroughput{}
and expandDynamoDbProvisionedThroughput
aws/resource_aws_dynamodb_table.go
Outdated
if op.Create != nil { | ||
idxName := *op.Create.IndexName | ||
if err := waitForDynamoDbGSIToBeActive(d.Id(), idxName, conn); err != nil { | ||
return fmt.Errorf("Error waiting for Dynamo DB GSI %q to be created: %s", idxName, err) |
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: I have bad OCD. 😢 DynamoDB
please
aws/structure.go
Outdated
return | ||
} | ||
|
||
func stripCapacityAttributes(in map[string]interface{}) map[string]interface{} { |
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 simplified with this and also make it more future proof? (not sure if you need to copy the map first)
delete(in, "read_capacity")
delete(in, "write_capacity")
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.
Yeah, I wanted to avoid copying it, but you're right - the name suggests the function does that, so we should do it. 👌
if ttlDesc.AttributeName != nil { | ||
m["attribute_name"] = *ttlDesc.AttributeName | ||
if ttlDesc.TimeToLiveStatus != nil { | ||
m["enabled"] = (*ttlDesc.TimeToLiveStatus == dynamodb.TimeToLiveStatusEnabled) |
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'm not sure if we need to consider setting this to false
for nil scenario
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.
Since the field is TypeBool
it's false
by default, so we shouldn't need to.
aws/structure.go
Outdated
d.Set("name", table.TableName) | ||
|
||
for _, attribute := range table.KeySchema { | ||
if *attribute.KeyType == "HASH" { |
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: dynamodb.KeyTypeHash
and dynamodb.KeyTypeRange
constants are available
aws/structure.go
Outdated
m := lsi.(map[string]interface{}) | ||
idxName := m["name"].(string) | ||
|
||
// TODO: Remove this (BC) |
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.
Please create an associated issue and add it to the comment if its important 😄
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.
#3176 Will add that to the comment.
aws/structure.go
Outdated
if v, ok := data["hash_key"]; ok && v != nil && v != "" { | ||
keySchema = append(keySchema, &dynamodb.KeySchemaElement{ | ||
AttributeName: aws.String(v.(string)), | ||
KeyType: aws.String("HASH"), |
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: Another reminder for dynamodb.KeyTypeHash
and dynamodb.KeyTypeRange
😄
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.
TC says its good to go, let's get this into the release. 👍
* commit '8937a3a4e9d77c8089cf147861b604e3a2d8cf7e': (47 commits) v1.8.0 Update CHANGELOG.md resource/aws_dynamodb_table: Refactoring (hashicorp#3136) Update CHANGELOG for hashicorp#3171 resource/aws_elastic_beanstalk_application: Prevent crash on reading missing application chore(vendor): bump aws-sdk-go to v1.12.70 typo guardduty import test Update CHANGELOG for hashicorp#3142 Removed empty strings test/aws_dynamodb_global_table: Use single region for basic and import testing resource/aws_sqs_queue: Retry creation on QueueDeletedRecently for additional 10 seconds docs/CONTRIBUTING: Use aws_cloudwatch_dashboard for acceptance test examples docs/CONTRIBUTING: New Region: don't add empty mappings Update CHANGELOG.md resource/aws_rds_cluster: Retry deletion on InvalidDBClusterStateFault docs/CONTRIBUTING: Remove pre-split provider directory references from testacc commands Add service account IDs docs/CONTRIBUTING: New Region Support AWS cn-northwest-1 Ningxia (fixes hashicorp#3053) Update CHANGELOG.md ... # Conflicts: # aws/validators.go
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! |
Firstly apologies for the big diff that can be hard to read 🙈
Why
Aka what lead me to refactor this resource:
aws/resource_aws_dynamodb_table.go
- reduced roughly by half (from 1155 to 657)global_secondary_index
inside CRUD. This was extracted intodiffDynamoDbGSI
+ is now tested thoroughly, which coincidentally resulted in fixing DynamoDB index non_key_attributes changes remain unrecognised #566 (acceptance test also attached to verify)time.Sleep
- replaced byresource.Retry
&resource.StateConf
per conventionsTest results
Fixes #566