Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform "value of 'count' cannot be computed: why?

Tags:

terraform

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)?

like image 710
Tomas Aschan Avatar asked Jan 10 '19 13:01

Tomas Aschan


People also ask

How does count work in Terraform?

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.

Can we use count and for each in Terraform?

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.

Is a list of number known only after apply Terraform?

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.

How do you declare an input variable in Terraform?

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 .


1 Answers

you have double quotes issue, try this:

count = "${length(split(',', azurerm_app_service.backend.outbound_ip_addresses))}"
like image 141
Tomasz Avatar answered Sep 23 '22 00:09

Tomasz