I have the following resource specification in my templates:
resource "azurerm_sql_firewall_rule" "allow_app_server" {
count = "${length(split(",", azurerm_app_service.backend.outbound_ip_addresses))}"
depends_on = ["azurerm_app_service.backend"]
name = "${format("Allow App Service Plan %d", count.index)}"
start_ip_address = "${element(split(",", azurerm_app_service.backend.possible_outbound_ip_addresses), count.index)}"
end_ip_address = "${element(split(",", azurerm_app_service.backend.possible_outbound_ip_addresses), count.index)}"
resource_group_name = "${var.environment_resource_group_name}"
server_name = "${var.db_server_name}"
}
resource "azurerm_app_service" "backend" {
# properties ommitted for brevity
}
Now when I run terraform plan
, it errors with the message
azurerm_sql_firewall_rule.allow_app_server: value of 'count' cannot be computed
Why? What can I do to fix this (that doesn't require me to partially deploy the template)?
count is a meta-argument defined by the Terraform language. It can be used with modules and with every resource type. The count meta-argument accepts a whole number, and creates that many instances of the resource or module.
What is count in Terraform? When you define a resource block in Terraform, by default, this specifies one resource that will be created. To manage several of the same resources, you can use either count or for_each , which removes the need to write a separate block of code for each one.
The fields which have known only after apply is not an error, but just informs the user that these fields only get populated in terraform state after its applied. The dependency order is handled by Terraform and hence referring values (even those which have known only after apply ) will be resolved at run time. Thanks.
Terraform variables allow you to write configuration that is flexible and easier to re-use. Add a variable to define the instance name. Create a new file called variables.tf with a block defining a new instance_name variable. Note: Terraform loads all files in the current directory ending in .
you have double quotes issue, try this:
count = "${length(split(',', azurerm_app_service.backend.outbound_ip_addresses))}"
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