Add conditions on a already provisioned module


I have created a module to make the provisioning of some “azurerm_function_app”, those ones are created on 2 locations and for cost management we will like to make the provisioning on 1 location only on certain environment (dev for example). But when i add the “count” parameter with the condition the “plan” step respons by a remove / create of those resources.
Is there a solution to modify this without recreate completely the resources?

Hi @sti291271,

You can let Terraform know that you want it to refer to the existing objects under a new address by using the terraform state mv command. You can apply that to an entire module by running a command line like this:

terraform state mv "module.example" "module.example[0]"

Note that this command will directly modify your Terraform state to change the addresses of all of the existing resources under module.example, so if you have multiple people working with this configuration you should make sure that they don’t try to run terraform plan or terraform apply between when you run terraform state mv and when you commit your change to the configuration, or else your colleagues might create an opposite plan where Terraform will plan to delete module.example[0] and create module.example.

1 Like