I am getting error when the module has a count condition within that is checking an input value. And the input value is dependent on the resource that is being created along with module.
resource "aws_kms_key" "this" {
}
module "service_secret" {
source = "./secret"
name = "foo-bar"
kms_arn = aws_kms_key.this.arn
tags = {}
}
in module secret
:
resource "aws_secretsmanager_secret" "this" {
name = var.name
kms_key_id = var.kms_arn == "" ? aws_kms_key.this[0].arn : var.kms_arn
}
resource "aws_kms_key" "this" {
count = var.kms_arn != "" ? 0 : 1
}
Error:
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. count = var.kms_arn != "" ? 0 : 1