Hi I have terraform plan where I am creating loadbalancers in aws, in this job I am running terraform plan then outputting the plan in json using terraform show -json terraform.plan
. As per Internals: JSON Output Format | Terraform by HashiCorp the output result should contain before = tgs in previous state and after = tgs in new state. When I am adding a new TG ideally it should be a update action but its always coming as create action.
Here’s sample code that we have:
# variable.tf
variable "target_groups" {
type = "list"
default = ["lb1", "lb2", "lb3"]
}
--------
#main.tf
data "aws_lb_target_group" "target_groups" {
for_each = var.target_groups
name = "${each.value}"
}
.
.
.
resource "null_resource" "do_something"{
............
}
Just mentioning about a null resource that we are using to check if its because of this?
Current Output
"output_changes": {
"msvcs-alb-target-groups": {
"actions": [
"create"
],
"before": null,
"after": ["lb1", "lb2", "lb3"],
"after_unknown": false
}
}
Expected Output when I rerun the same plan
"output_changes": {
"msvcs-alb-target-groups": {
"actions": [
"no-op"
],
"before": ["lb1", "lb2", "lb3"],
"after": ["lb1", "lb2", "lb3"],
"after_unknown": false
}
}
Expected Output when I add a new lb and run plan:
"output_changes": {
"msvcs-alb-target-groups": {
"actions": [
"update"
],
"before": ["lb1", "lb2", "lb3"],
"after": ["lb1", "lb2", "lb3", "lb4"],
"after_unknown": false
}
}