I am trying to define a list of aws_usage_plans, using a for_each.
I am passing in this variable data:
usage_plan_configs = {
"xsmall" = {"name" = "xsmall", "quota_limit" = 10000,
"quota_offset" = 0, "quota_period" = "DAY",
"throttle_burst" = 1, "throttle_rate" = 0.2 },
"small" = {"name" = "small", "quota_limit" = 5000000,
"quota_offset" = 0, "quota_period" = "DAY",
"throttle_burst" = 200, "throttle_rate" = 500 },
"medium" = {"name" = "medium", "quota_limit" = 10000000,
"quota_offset" = 0, "quota_period" = "DAY",
"throttle_burst" = 200, "throttle_rate" = 500 },
"large" = {"name" = "large", "quota_limit" = 30000000,
"quota_offset" = 0, "quota_period" = "DAY",
"throttle_burst" = 3000, "throttle_rate" = 5000 },
"unlimited" = {"name" = "unlimited", "quota_limit" = 300000000,
"quota_offset" = 0, "quota_period" = "DAY",
"throttle_burst" = 5000, "throttle_rate" = 10000 }
}
My for_each block is like this:
resource "aws_api_gateway_usage_plan" "plan" {
for_each = var.usage_plan_configs
name = each.value.name
quota_settings {
limit = each.value.quota_limit
offset = each.value.quota_offset
period = each.value.quota_period
}
throttle_settings {
burst_limit = each.value.throttle_burst
rate_limit = each.value.throttle_rate
}
}
but I am getting this error:
│ Error: Invalid for_each argument
│
│ on main.tf line 8, in resource "aws_api_gateway_usage_plan" "plan":
│ 8: for_each = var.usage_plan_configs
│ ├────────────────
│ │ var.usage_plan_configs is "{\"large\":{\"name\":\"large\",
\"quota_limit\":30000000,\"quota_offset\":0,\"quota_period\":\"DAY\",
\"throttle_burst\":3000,\"throttle_rate\":5000},\"medium\":{\"name\":\"medium\",
\"quota_limit\":10000000,\"quota_offset\":0,\"quota_period\":\"DAY\",
\"throttle_burst\":200,\"throttle_rate\":500},\"small\":{\"name\":\"small\",
\"quota_limit\":5000000,\"quota_offset\":0,\"quota_period\":\"DAY\",
\"throttle_burst\":200,\"throttle_rate\":500},\"unlimited\":{\"name\":\"unlimited\",
\"quota_limit\":300000000,\"quota_offset\":0,\"quota_period\":\"DAY\",
\"throttle_burst\":5000,\"throttle_rate\":10000},\"xsmall\":{\"name\":\"xsmall\",
\"quota_limit\":10000,\"quota_offset\":0,\"quota_period\":\"DAY\",\"throttle_burst\":1,
\"throttle_rate\":0.2}}"
│
│ The given "for_each" argument value is unsuitable: the "for_each" argument
│ must be a map, or set of strings, and you have provided a value of type
│ string.
This mimics a solution given here: How to for_each through a list(objects) in Terraform 0.12 I just can't seem to get it to work. I think my variable definition is key here.
How would one define a variable type such that this code works?