I have a single main.tf at the root and different modules under it for different parts of my Azure cloud e.g.
main.tf
- apim
- firewall
- ftp
- function
The main.tf passes variable down to the various modules e.g. resource group name or a map of tags.
During development I have been investigating certain functionality using the portal and I don't have it in terraform yet.
e.g. working out how best to add a mock service in the web module
If I now want to update a different module (e.g. update firewall rules) terraform will suggest destroying the added service.
How can I do terraform plan/apply for just a single module?
You can target only the module by specifying the module namespace as the target argument in your plan and apply commands:
terraform plan -target=module.<declared module name>
For example, if your module declaration was:
module "the_firewall" {
source = "${path.root}/firewall"
}
then the command would be:
terraform plan -target=module.the_firewall
to only target that module declaration.
Note that this should only be used in development/testing scenarios, which it seems you already are focused on according to the question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With