$ terraform -v
Terraform v0.12.0-beta1
// Testing this stand alone first. Ideally, this would go into our module (where dynamic contenct generation makes sense for us)
// This matches up with what I see in the docs, and here https://www.hashicorp.com/blog/hashicorp-terraform-0-12-preview-for-and-for-each
// However, I get the following errors on attributes that should exist for these content blocks
/*
Error: Unsupported attribute
on test.tf line 59, in resource "aws_dynamodb_table" "dynamodb_table":
59: projection_type = global_secondary_index.projection_type
This object does not have an attribute named "projection_type".
*/
variable "global_secondary_indexes" {
default = [
{
name = "index1"
hash_key = "foo1"
range_key = "bar1"
projection_type = "ALL"
key_type = "S"
},
{
name = "index2"
hash_key = "foo2"
range_key = "bar2"
projection_type = ""
key_type = "S"
}
]
}
resource "aws_dynamodb_table" "dynamodb_table" {
name = "zane-test-inno"
billing_mode = "PAY_PER_REQUEST"
hash_key = "rage"
dynamic "global_secondary_index" {
for_each = [for g in var.global_secondary_indexes: {
name = g.name
hash_key = g.hash_key
range_key = g.range_key
projection_type = g.projection_type
}]
content {
name = global_secondary_index.name
hash_key = global_secondary_index.hash_key
range_key = global_secondary_index.range_key
projection_type = global_secondary_index.projection_type
}
}
dynamic "attribute" {
for_each = [for g in var.global_secondary_indexes: {
name = g.name
type = g.key_type
}]
content {
name = attribute.name
type = attribute.type
}
}
attribute {
name = "rage"
type = "S"
}
ttl {
attribute_name = "ttl"
enabled = "true"
}
tags = {
Name = "foo"
Environment = "bar"
Team = "team"
Owner = "owner"
Product = "product"
}
}
none
I would expect these attributes to be valid for the dynamic / content for_each block. Unless my TF has a mistake in it. I am basing it off of the TF docs and blog
Series of errors stating the attribute names are not supported
Error: Unsupported attribute
on test.tf line 56, in resource "aws_dynamodb_table" "dynamodb_table":
56: name = global_secondary_index.name
This object does not have an attribute named "name".
Error: Unsupported attribute
on test.tf line 56, in resource "aws_dynamodb_table" "dynamodb_table":
56: name = global_secondary_index.name
This object does not have an attribute named "name".
Error: Unsupported attribute
on test.tf line 57, in resource "aws_dynamodb_table" "dynamodb_table":
57: hash_key = global_secondary_index.hash_key
This object does not have an attribute named "hash_key".
Error: Unsupported attribute
on test.tf line 57, in resource "aws_dynamodb_table" "dynamodb_table":
57: hash_key = global_secondary_index.hash_key
This object does not have an attribute named "hash_key".
Error: Unsupported attribute
on test.tf line 58, in resource "aws_dynamodb_table" "dynamodb_table":
58: range_key = global_secondary_index.range_key
This object does not have an attribute named "range_key".
Error: Unsupported attribute
on test.tf line 58, in resource "aws_dynamodb_table" "dynamodb_table":
58: range_key = global_secondary_index.range_key
This object does not have an attribute named "range_key".
Error: Unsupported attribute
on test.tf line 59, in resource "aws_dynamodb_table" "dynamodb_table":
59: projection_type = global_secondary_index.projection_type
This object does not have an attribute named "projection_type".
Error: Unsupported attribute
on test.tf line 59, in resource "aws_dynamodb_table" "dynamodb_table":
59: projection_type = global_secondary_index.projection_type
This object does not have an attribute named "projection_type".
Error: Unsupported attribute
on test.tf line 70, in resource "aws_dynamodb_table" "dynamodb_table":
70: name = attribute.name
This object does not have an attribute named "name".
Error: Unsupported attribute
on test.tf line 70, in resource "aws_dynamodb_table" "dynamodb_table":
70: name = attribute.name
This object does not have an attribute named "name".
Error: Unsupported attribute
on test.tf line 71, in resource "aws_dynamodb_table" "dynamodb_table":
71: type = attribute.type
This object does not have an attribute named "type".
Error: Unsupported attribute
on test.tf line 71, in resource "aws_dynamodb_table" "dynamodb_table":
71: type = attribute.type
This object does not have an attribute named "type".
Perform terraform apply -auto-approve on the provided test terraform above.
0.12-beta1
Ok, I think I figured this out. The docs seem to be out of date. There is now reference to key and values for complex data.
So this...
content {
name = global_secondary_index.name
hash_key = global_secondary_index.hash_key
range_key = global_secondary_index.range_key
projection_type = global_secondary_index.projection_type
}
should include "value" ....
```
content {
name = global_secondary_index.value.name
hash_key = global_secondary_index.value.hash_key
range_key = global_secondary_index.value.range_key
projection_type = global_secondary_index.value.projection_type
}
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!
Most helpful comment
Ok, I think I figured this out. The docs seem to be out of date. There is now reference to key and values for complex data.
So this...
should include "value" ....
```
content {
name = global_secondary_index.value.name
hash_key = global_secondary_index.value.hash_key
range_key = global_secondary_index.value.range_key
projection_type = global_secondary_index.value.projection_type
}