Hi there,
Is there a way to trigger a null_resource on every terraform run?
For example:
resource "null_resource" "db_subnets" {
triggers {
db_subnet_ids = "${join(",", aws_subnet.db_subnet.*.id)}"
}
provisioner "local-exec" {
command = "echo ${join(",", aws_subnet.db_subnet.*.id)} >> subnets.txt"
}
}
This creates the subnets.txt file when the subnets are created. However, when I delete the subnets.txt file, it will not be recreated on the next TerraForm run.
It would like to recreate it on every run.
Hi @jeroenjacobs1205!
Probably the easiest way to do this would be to put something that doesn't stabilize in the triggers
map. The uuid()
function might do the trick, since it should generate a fresh uuid on each Terraform run.
Note that in Terraform 0.7 it will be possible for outputs to be lists as well as strings, so in that version it may work out better to export your list of subnets as an output and then use terraform output subnet_ids >subnets..txt
to obtain this value after Terraform has completed... that way, the list of subnets is persisted in Terraform's state file and you can easily reproduce it when needed without running terraform apply
again.
Answered above.
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Hi @jeroenjacobs1205!
Probably the easiest way to do this would be to put something that doesn't stabilize in the
triggers
map. Theuuid()
function might do the trick, since it should generate a fresh uuid on each Terraform run.Note that in Terraform 0.7 it will be possible for outputs to be lists as well as strings, so in that version it may work out better to export your list of subnets as an output and then use
terraform output subnet_ids >subnets..txt
to obtain this value after Terraform has completed... that way, the list of subnets is persisted in Terraform's state file and you can easily reproduce it when needed without runningterraform apply
again.