antonbabenko / terraform-best-practices

Terraform Best Practices free ebook translated into 🇬🇧🇦🇪🇧🇦🇧🇷🇫🇷🇬🇪🇩🇪🇬🇷🇮🇱🇮🇳🇮🇩🇮🇹🇯🇵🇰🇷🇵🇱🇷🇴🇨🇳🇪🇸🇹🇷🇺🇦🇵🇰
https://www.terraform-best-practices.com/
Other
2.07k stars 431 forks source link

Terraform script organization #60

Open NourMawla98 opened 1 month ago

NourMawla98 commented 1 month ago

I have a terraform script. The hierarchy is as follows:

/root ├─main.tf ├─variables.tf └─provider.tf

The script is as follows:

Step 1: Define Resource Group

resource "azurerm_resource_group" "rg" { location = var.zone name = var.rg-name }

Step 2: Create database

resource "azurerm_mysql_flexible_server" "mysql" { resource_group_name = azurerm_resource_group.rg.name

....

}

resource "azurerm_mysql_flexible_server_firewall_rule" "allow-all-ips" {

....

}

Steps 3, 4.....

as you can tell, the script is becoming too large and very difficult to maintain and handle

How can I use 1 provider.tf, 1 variables.tf and 1 main.tf to organize all these resources. Please not that some resources depends on the output of others

Any advice will be much appreciated