Open naveen-amzn opened 1 year ago
AWSCC handler for DynamoDB Table: https://github.com/hashicorp/terraform-provider-awscc/blob/ce1ad5105c8f463339880e0dd2d00395cd2f40a6/internal/aws/dynamodb/table_resource_gen.go#L472C1-L474C22
Notice how the element type is string
"key_schema": schema.MapAttribute{ /*START ATTRIBUTE*/
ElementType: types.StringType,
Required: true,
Perhaps this part of the Key Schema is causing confusion on the auto-generation because it declare either an array or an object.
Having this error too in latest version of provider (0.55.0)
resource "awscc_dynamodb_table" "main" {
table_name = "dynamodb_table_name"
key_schema = {
attribute_name = "UserId"
key_type = "HASH"
}
attribute_definitions = [{
attribute_name = "UserId"
attribute_type = "S"
}]
billing_mode = "PAY_PER_REQUEST"
}
rg "CloudControl DesiredState" output.log | jq '.value | fromjson'
{
"AttributeDefinitions": [
{
"AttributeName": "UserId",
"AttributeType": "S"
}
],
"BillingMode": "PAY_PER_REQUEST",
"KeySchema": {
"attribute_name": "UserId", # ⚠️
"key_type": "HASH" # ⚠️
},
"TableName": "dynamodb_table_name"
}
With key_schema
being treated as a map(string)
the translator does not translate the Terraform names back to CloudFormation names.
@wellsiau-aws The current working version of the schema is below. The original example has an incorrect sse_type of AWSKMS
.
key_schema
to match the attribute_definitions
which is from the expectation on the AWS::DynamoDB::Table
spec. This shouldn't be the case.resource "awscc_dynamodb_table" "main" {
table_name = "dynamodb_table_name"
key_schema = jsonencode([{
AttributeName = "UserId"
KeyType = "HASH"
}])
attribute_definitions = [{
attribute_name = "UserId"
attribute_type = "S"
}]
billing_mode = "PROVISIONED"
provisioned_throughput = {
read_capacity_units = 20
write_capacity_units = 20
}
deletion_protection_enabled = true
sse_specification = {
sse_enabled = true
sse_type = "KMS"
}
time_to_live_specification = {
attribute_name = "TimeToExist"
enabled = false
}
table_class = "STANDARD"
tags = [{
key = "Modified By"
value = "AWSCC"
}]
}
@kadrach @quixoticmonk thank you for your input!
I believe there are two separate problem here:
key_schema
attribute being treated as map(string) as described herekey_schema
attribute value to matches the attribute_definitions
as described here@quixoticmonk , I suggest to open a new issue to record your problem since that also another upstream AWS issue.
Community Note
Terraform CLI and Terraform AWS Cloud Control Provider Version
Terraform v1.2.9 on darwin_arm64 provider registry.terraform.io/hashicorp/awscc v0.52.0
Affected Resource(s)
Terraform Configuration Files
Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.
Debug Output
Panic Output
Expected Behavior
Amazon Dynamodb table should have been created.
Actual Behavior
After creating Terraform plan with above configuration it gave following output.
But when applying the changes, it failed with the below error
Steps to Reproduce
terraform apply
When I provided key_schema as list of map then awscc provided below error message
Important Factoids
References
AWSCC schema - https://github.com/hashicorp/terraform-provider-awscc/blob/main/internal/aws/dynamodb/table_resource_gen.go#L472-L490 Cloudformation schema - https://github.com/hashicorp/terraform-provider-awscc/blob/ce1ad5105c8f463339880e0[…]internal/service/cloudformation/schemas/AWS_DynamoDB_Table.jso
0000