0
votes

I have created terraform template (azure) with two modules. One module is for the resource group. the other is for vnet (it handles the creation of NSG and route table as well along with their association with subnets).

When I run terraform apply, it is giving an error for the route table, as the resource group is not created yet. the order of creation is showing as route table is created first and then resource group. Is there a way to set the order of creation? in the main.tf in the root folder, module resource group is called first and then vnet.

2

2 Answers

1
votes

Reconsider the idea of creating RG and resources using two modules. Ask yourself a simple question: why?

If you are 100% sure it is the right approach then use depends_on:

module "rg1" {
  source = "./rg_module"
  ...
}

module "net1" {
  source = "./network_module"
  ....
  depends_on = [module.rg1]
}
0
votes

You must use -out option to save the plan to a file. Like:

terraform plan -out <plan_file>

It is always recommended to use -out and save the plan file. This will ensure that the order of creation is preserved across subsequent applies.