Skip to content

Instantly share code, notes, and snippets.

@brikis98
Last active October 12, 2016 10:17
Show Gist options
  • Save brikis98/0af6b4f1a3467e5341c6569d2a878749 to your computer and use it in GitHub Desktop.
Save brikis98/0af6b4f1a3467e5341c6569d2a878749 to your computer and use it in GitHub Desktop.
Conditionals with inline attributes in Terraform
resource "aws_dynamodb_table" "one_attribute" {
count = "${replace(replace(var.num_attributes, "1", "1"), "/^[^1]$/", 0)}"
name = "${var.name}"
attribute {
name = "${var.first_attribute_name}"
type = "${var.first_attribute_type}"
}
}
resource "aws_dynamodb_table" "two_attributes" {
count = "${replace(replace(var.num_attributes, "2", "1"), "/^[^2]$/", 0)}"
name = "${var.name}"
attribute {
name = "${var.first_attribute_name}"
type = "${var.first_attribute_type}"
}
attribute {
name = "${var.second_attribute_name}"
type = "${var.second_attribute_type}"
}
}
resource "aws_dynamodb_table" "three_attributes" {
count = "${replace(replace(var.num_attributes, "3", "1"), "/^[^3]$/", 0)}"
name = "${var.name}"
attribute {
name = "${var.first_attribute_name}"
type = "${var.first_attribute_type}"
}
attribute {
name = "${var.second_attribute_name}"
type = "${var.second_attribute_type}"
}
attribute {
name = "${var.third_attribute_name}"
type = "${var.third_attribute_type}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment