title: Terraform Invalid count argument that depends on another resource
body: <p>I'm getting the following error when trying to do a plan or an apply on a terraform script.</p>
  
  <pre><code>Error: Invalid count argument
  
    on main.tf line 157, in resource "azurerm_sql_firewall_rule" "sqldatabase_onetimeaccess_firewall_rule":
   157:   count               = length(split(",", azurerm_app_service.app_service.possible_outbound_ip_addresses))
  
  The "count" value depends on resource attributes that cannot be determined
  until apply, so Terraform cannot predict how many instances will be created.
  To work around this, use the -target argument to first apply only the
  resources that the count depends on.
  </code></pre>
  
  <p>I understand this is falling over because it doesn't know the count for the number of firewall rules to create until the app_service is created. I can just run the <code>apply</code> with an argument of <code>-target=azurerm_app_service.app_service</code> then run another apply after the app_service is created.</p>
  
  <p>However, this isn't great for our CI process, if we want to create a whole new environment from our terraform scripts we'd like to just tell terraform to just go build it without having to tell it each target to build in order.</p>
  
  <p>Is there a way in terraform to just say go build everything that is needed in order without having to add targets?</p>
  
  <p>Also below is an example terraform script that gives the above error:</p>
  
  <pre><code>provider "azurerm" {
    version = "=1.38.0"
  }
  
  resource "azurerm_resource_group" "resourcegroup" {
    name     = "rg-stackoverflow60187000"
    location = "West Europe"
  }
  
  resource "azurerm_app_service_plan" "service_plan" {
    name                = "plan-stackoverflow60187000"
    resource_group_name = azurerm_resource_group.resourcegroup.name
    location            = azurerm_resource_group.resourcegroup.location
    kind                = "Linux"
    reserved            = true
  
    sku {
      tier = "Standard"
      size = "S1"
    }
  }
  
  resource "azurerm_app_service" "app_service" {
    name                = "app-stackoverflow60187000"
    resource_group_name = azurerm_resource_group.resourcegroup.name
    location            = azurerm_resource_group.resourcegroup.location
    app_service_plan_id = azurerm_app_service_plan.service_plan.id
  
    site_config {
      always_on        = true
      app_command_line = ""
      linux_fx_version = "DOCKER|nginxdemos/hello"
    }
  
    app_settings = {
      "WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false"
    }
  }
  
  resource "azurerm_sql_server" "sql_server" {
    name                         = "mysqlserver-stackoverflow60187000"
    resource_group_name = azurerm_resource_group.resourcegroup.name
    location            = azurerm_resource_group.resourcegroup.location
    version                      = "12.0"
    administrator_login          = "4dm1n157r470r"
    administrator_login_password = "4-v3ry-53cr37-p455w0rd"
  }
  
  resource "azurerm_sql_database" "sqldatabase" {
    name                             = "sqldatabase-stackoverflow60187000"
    resource_group_name              =  azurerm_sql_server.sql_server.resource_group_name
    location                         =  azurerm_sql_server.sql_server.location
    server_name                      =  azurerm_sql_server.sql_server.name
    edition                          = "Standard"
    requested_service_objective_name = "S1"
  }
  
  resource "azurerm_sql_firewall_rule" "sqldatabase_firewall_rule" {
    name                = "App Service Access (${count.index})"
    resource_group_name = azurerm_sql_database.sqldatabase.resource_group_name
    server_name         = azurerm_sql_database.sqldatabase.name
    start_ip_address    = element(split(",", azurerm_app_service.app_service.possible_outbound_ip_addresses), count.index)
    end_ip_address      = element(split(",", azurerm_app_service.app_service.possible_outbound_ip_addresses), count.index)
    count               = length(split(",", azurerm_app_service.app_service.possible_outbound_ip_addresses))
  }
  
  </code></pre>