Terraform: Error: Error parsing App Service Resource ID

Viewed 1058

This is a continuation to this question

resource "azurerm_app_service_slot" "app_service_slot_template"   {
  for_each = {for sl in "${var.app_service_slots}" : sl.name => sl }
  
  app_service_name = "${var.mandatory_prefix}-${var.app_service_name}"
  resource_group_name = "${var.resource_group_name}"
  app_service_plan_id = "${data.azurerm_app_service_plan.service_plan.id}"
  location = "${var.resource_location}"
  https_only = true

 
      
        
  name =  "${each.value["name"]}"
  
  dynamic "site_config" {
    for_each = "${var.site_config}"
    content {
      min_tls_version = lookup(site_config.value, "min_tls_version", null)
      python_version = lookup(site_config.value, "python_version", null)
      java_version = lookup(site_config.value, "java_version", null)
      always_on = lookup(site_config.value, "always_on", null)
      app_command_line = lookup(site_config.value, "app_command_line", null)
      dotnet_framework_version = lookup(site_config.value, "dotnet_framework_version", null)          
    }
  }
  
  dynamic "connection_string" {
    for_each =  "${each.value["connection_strings"]}"
    content {
      name = "${connection_string.value["name"]}"
      type = "${connection_string.value["type"]}"
      value = "${connection_string.value["value"]}"
    }
  }

  app_settings = "${merge(each.value["app_settings"], local.additional_app_settings)}"
}



  # Get the Id of the subnet
data "azurerm_subnet" "azurerm_subnet_template" {
  name                 = "${var.subnet_name}"
  virtual_network_name = "${var.virtual_network_name}"
  resource_group_name  = "${var.vnet_resource_group_name}"
}

resource "azurerm_app_service_virtual_network_swift_connection" "azureapp_vnet_integration_for_slot" {
  for_each = {for sl in "${azurerm_app_service_slot.app_service_slot_template}" : sl.name => sl }

  app_service_id = "${each.value.id}"
  subnet_id      = "${data.azurerm_subnet.azurerm_subnet_template.id}"
  depends_on = [azurerm_app_service_slot.app_service_slot_template]
}

This works perfectly on the Terraform plan, however during the apply it failed with the below error

Error: Error parsing App Service Resource ID

on .terraform/modules/generic_app_service/main.tf line 235, in resource "azurerm_app_service_virtual_network_swift_connection" "azureapp_vnet_integration_for_slot": 235: resource "azurerm_app_service_virtual_network_swift_connection" "azureapp_vnet_integration_for_slot" {

I can confirm from the plan output the app_service_id is getting/passing the correct resource id for the azure slot but don't know why it is complaining about App Service Resource ID

1 Answers

The docs for app_service_id write:

The ID of the App Service or Function App to associate to the VNet. Changing this forces a new resource to be created.

So it should be either ID of azurerm_app_service or azurerm_function_app. But you are trying to use azurerm_app_service_slot, which is a different resource.

Related