Skip to content

Instantly share code, notes, and snippets.

@sepulworld
Last active April 9, 2019 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sepulworld/6b994cf276259ca3bbe49b1d1fe9722d to your computer and use it in GitHub Desktop.
Save sepulworld/6b994cf276259ca3bbe49b1d1fe9722d to your computer and use it in GitHub Desktop.
dyanmodb_table_012.tf
// 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 = "produt"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment