HI Team,
I am trying to read and use the remote state from s3 bucket as below
data “terraform_remote_state” “green” {
backend = “s3”
config = {
bucket = test
key = green.tfstate
region = us-east-1
profile = “aas”
}
}
resource “aws_lb_target_group_attachment” “tg-green” {
count = length(data.terraform_remote_state.green) > 0 ? 1 : 0
target_group_arn = xxxxx
target_id = data.terraform_remote_state.green.outputs.instance_id
}
The problem in this is there are cases where there will be no remote state present in the s3 bucket for that I have set in the next block
count = length(data.terraform_remote_state.green) > 0 ? 1 : 0 so that will proceed only when file has data.
When I run terraform apply will fail stating the remote file is not found in s3 bucket.
I am looking to set defaults or ignore a remote state block if the state file is not found.
Please suggest me on this.