I'm using Terraform to build and automate infrastructure and I'm having trouble in finding the solution to grab the output of an Azure WebApp, specifically the Public IP addresses used by that WebApp and use them as inputs to update a Cloudflare list.
output "webapp_ip" {
value = azurerm_linux_web_app.lwa.outbound_ip_addresses
}
will output something like this:
webapp_ip = "ip-address-1,ip-address-2,ip-address-3,ip-address-4"
and Cloudflare_list terraform resource receives data on the following format:
item {
value {
ip = "ip-address-1"
}
comment = "IP 1"}
item {
value {
ip = "ip-address-2"
}
comment = "IP 2"
}
I was thinking in dynamic lists but I don't know if it's the right way to go...
Dynamic blocks is the right way to go here. Your code should look something like this:
resource "cloudflare_list" "example" {
// some other attributes
dynamic "item" {
for_each = toset(split(",", azurerm_linux_web_app.lwa.outbound_ip_addresses)) // notice split
content {
value {
ip = item.value
}
comment = "IP: ${item.value}"
}
}
}
If Azure and Cloudflare are in two different workspaces (states) you can use either terraform_remote_state or tfe_outputs to pass Azure outputs to Cloudflare.