How to define execution order without trigger option in terraform
18,770
I can only provide feedback on the code you provided but one way to ensure the test_status
command is run once the DB is ready is to use a depends_on
within a null_resource
resource "null_resource" "test_status" {
depends_on = ["module.db.id"] #or any output variable
provisioner "local-exec" {
command = "scripts/test_http_status.sh"
}
}
But as @JimB already mentioned terraform isn't procedural so ensuring order isn't possible.
Related videos on Youtube
Comments
-
negabaro almost 2 years
Does it make sense to understand that it runs in the order defined in main.tf of terraform?
I understand that it is necessary to describe the trigger option in order to define the order on terraform.
but if it could not be used trigger option like this data "external" , How can I define the execution order?
For example, I would like to run in order as follows.
get_my_public_ip -> ec2 -> db -> test_http_status
main.tf is as follows
data "external" "get_my_public_ip" { program = ["sh", "scripts/get_my_public_ip.sh"] } module "ec2" { ... } module "db" { ... } data "external" "test_http_status" { program = ["sh", "scripts/test_http_status.sh"] }
-
JimB about 6 yearsTerraform configuration is declarative, not procedural. The order the resources are declared has no bearing on the order that are executed. The only resource with a 'triggers" attribute is the
null_resource
, but an reference between resources created a dependency.
-
-
Rıfat Erdem Sahin over 5 yearsdepends_on works with any resource ? or does it have to be a module ?
-
Stephen over 5 yearsit works with any resource - terraform.io/intro/getting-started/…