Hello,
I’m having a circular issue with modules and a datasource, as the following:
# module.tf
resource "aws_iam_role_policy" "iam_role_policy" {
count = length(var.iam_policy_inline_json) > 0 ? 1 : 0
name = "iam-policy-inline-app"
policy = var.iam_policy_inline_json
}
# main.tf
module "mod" {
source = "../../../resources/module"
iam_policy_inline_json = data.aws_iam_policy_document.policy.json
depends_on = [
data.aws_iam_policy_document.policy
]
}
data "aws_iam_policy_document" "policy" {
statement {
effect = "Allow"
actions = [
"ses:SendRawEmail"
]
resources = ["*"]
}
}
It’s not refreshing the datasource, and presents this error on the plan:
Error: Invalid count argument
│
│ on …/…/…/resources/modules/module.tf line 34, in resource “aws_iam_role_policy” “iam_role_policy”:
│ 34: count = length(var.iam_policy_inline_json) > 0 ? 1 : 0
│
│ The “count” value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around
│ this, use the -target argument to first apply only the resources that the count depends on.
Can someone give some insight about this issue?