Racking my head with a combo of terraform + azure devops process and figuring what is the best strategy to go about this,
I have 3 stages, to build and deploy some terraform code
- Stage 1 build : the individual services, e.g. sql server, database, app service terraform plan artifact folder path:
terraform\phase1\main.tf .... etc
- Stage2 deploy: artifact from stage1
terraform apply
- Stage3 build & deploy pipes: Grab the outbound ip addresses from the deployed azure app service via the tfstate back-end using
data "azurerm_app_service" "this"
and add these to the sql server firewall allowed ip's folder path:terraform\phase2\main.tf .... etc.
My issue comes through at Stage3 when I look at the phase2 folder which only defined the data outputs and resource creation for fw rules, though we are looking at the same backend state file, terraform plan cannot see any of the resources created in stage2 in the folder and therefore plans to destroy it.
In Phase2 folder my code looks something like this
data "azurerm_app_service" "tf_dr_awa_core-app" {
name = "dr-core-app"
resource_group_name = "dr-app"
}
resource "azurerm_sql_firewall_rule" "tf_dr_sql_server_firewall" {
count = length(split(",", data.azurerm_app_service.tf_dr_awa_core-app.possible_outbound_ip_addresses))
.....
}
Has anyone come across anything similar where you have to build the core parts of the infrastructure first, once they have metadata in the state file then grab that data and build pipes between the core pieces, in this case the sql server and the app service?