I have terraform with multiple bucket resources and wanted to create a single bucket policy resource with iam_policy_document which can add statements dynamically at certain condition flag gets verified. is there any possible method for this?
Asked
Active
Viewed 98 times
0
-
2What is your current tf code and what do you want to do with it? – Marcin Nov 30 '21 at 21:55
1 Answers
0
Without knowing what your code looks like it's very hard to give you an answer, but it vaguely sounds like you could do this with count
.
Something along the lines of:
data "aws_iam_policy_document" "example" {
count = var.create_policy? 1 : 0
statement {
sid = "1"
actions = [
"s3:ListAllMyBuckets",
"s3:GetBucketLocation",
]
}
The idea is that you set the create policy to True
or False
.
If it is set to True
then the policy will be created.
There is more info about conditional expressions here - https://www.terraform.io/docs/language/expressions/conditionals.html
Here is another question on a similar topic - Terraform: Conditional creation of a resource based on a variable in .tfvars

fraserc182
- 237
- 1
- 4
- 13