Reputation: 385
I have a aws resource that i only want to be built in the production environment. Usually i would use something like this:
count = var.environment == "production" ? 1 : 0
However, as per the terraform documentation, count is not supported when used in a module for versions of terraform lower than 13. ("Module support for count was added in Terraform 0.13, and previous versions can only use it with resources.")
I am using terraform 12 and the resource is coming from a module and so I would like a different conditional statement that will only build the resource in production but not sure what else there is other than the count function
Upvotes: 2
Views: 17583
Reputation: 17584
Here is more details on my comments:
Here is my test module "policies", code is something like:
variable "foo" {
type = number
}
resource "aws_iam_policy_attachment" "policy_abc" {
count = var.foo
...
}
resource "aws_iam_policy_attachment" "policy_def" {
count = var.foo
...
}
calling the module
module "bar" {
source = "../modules/policies"
foo = var.environment == "production" ? 1 : 0
...
}
Upvotes: 2