Terraform-provider-azurerm: azurerm 1.24 & app_service CORS

Created on 5 Apr 2019  ·  7Comments  ·  Source: terraform-providers/terraform-provider-azurerm

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

Terraform v0.11.13
provider.azurerm v1.24.0

Affected Resource(s)

  • azurerm_app_service

Terraform Configuration Files

resource "azurerm_app_service" "app_service_backend" {
  name                = "${local.app_resource_prefix}-app-service-backend"
  location            = "${azurerm_resource_group.app_resource_group.location}"
  resource_group_name = "${azurerm_resource_group.app_resource_group.name}"
  app_service_plan_id = "${azurerm_app_service_plan.app_service_plan.id}"
  https_only          = true

  identity {
    type = "SystemAssigned"
  }

  cors {
    allowed_origins     = "${split(",", var.cors_allowed_origins)}"
    support_credentials = false
  }

  tags = "${local.app_tags}"
}

Debug Output

2019-04-05T11:49:20.7177386Z Terraform version:
2019-04-05T11:49:21.5612925Z Terraform v0.11.13
2019-04-05T11:49:21.8207832Z + provider.azurerm v1.24.0
2019-04-05T11:49:21.8209311Z 
2019-04-05T11:49:21.8975802Z ##[command]"terraform" apply -auto-approve -var-file="variables.tfvars" -input=false -no-color
2019-04-05T11:49:22.8587751Z 
2019-04-05T11:49:22.8588496Z Error: azurerm_app_service.app_service_backend: : invalid or unknown key: cors

Expected Behavior

No error.

Actual Behavior

invalid or unknown key: cors
  1. terraform apply
enhancement servicapp-service

Most helpful comment

I have the same error when using terraform 0.12.1 & azurerm 1.30.1:

resource "azurerm_app_service" "app_service_backend" {
  name                = "${local.app_resource_prefix}-app-service-backend"
  location            = azurerm_resource_group.app_resource_group.location
  resource_group_name = azurerm_resource_group.app_resource_group.name
  app_service_plan_id = azurerm_app_service_plan.app_service_plan.id
  https_only          = true

  identity {
    type = "SystemAssigned"
  }

  site_config {
    cors {
      allowed_origins = split(",", var.cors_allowed_origins)
    }
  }

  tags = local.app_tags
}
Error: web.AppsClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>

  on main.tf line 59, in resource "azurerm_app_service" "app_service_backend":
  59: resource "azurerm_app_service" "app_service_backend" {


##[error] Terraform failed to execute. Error: 
End of Task Terraform
##[section]Finishing: Terraform apply -auto-approve

All 7 comments

Hi @dhabierre, from looking at the PR that added this functionality, it looks like cors is a key underneath the root site_config property. Try adding it there and see if it works.

Hi Lucretius,

You are right! My bad eyes :/

Thanks.

I can't deploy the app_service with site_config / cors

resource "azurerm_app_service" "app_service_backend" {
  name                = "${local.app_resource_prefix}-app-service-backend"
  location            = "${azurerm_resource_group.app_resource_group.location}"
  resource_group_name = "${azurerm_resource_group.app_resource_group.name}"
  app_service_plan_id = "${azurerm_app_service_plan.app_service_plan.id}"
  https_only          = true

  identity {
    type = "SystemAssigned"
  }

  tags = "${local.app_tags}"
}

=> OK

resource "azurerm_app_service" "app_service_backend" {
  name                = "${local.app_resource_prefix}-app-service-backend"
  location            = "${azurerm_resource_group.app_resource_group.location}"
  resource_group_name = "${azurerm_resource_group.app_resource_group.name}"
  app_service_plan_id = "${azurerm_app_service_plan.app_service_plan.id}"
  https_only          = true

  identity {
    type = "SystemAssigned"
  }

  site_config {
    cors {
      allowed_origins     = "${split(",", var.cors_allowed_origins)}"
      support_credentials = false
    }
  }

  tags = "${local.app_tags}"
}

=> Failure

azurerm_app_service.app_service_backend: web.AppsClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>

Execution trace:

azurerm_app_service.app_service_backend: Creating...
  app_service_plan_id:                             "" => "/subscriptions/XXXX/resourceGroups/sdbx-dha/providers/Microsoft.Web/serverfarms/sdbx-dha-app-service-plan"
  app_settings.%:                                  "" => "<computed>"
  client_affinity_enabled:                         "" => "<computed>"
  connection_string.#:                             "" => "<computed>"
  default_site_hostname:                           "" => "<computed>"
  enabled:                                         "" => "true"
  https_only:                                      "" => "true"
  identity.#:                                      "" => "1"
  identity.0.principal_id:                         "" => "<computed>"
  identity.0.tenant_id:                            "" => "<computed>"
  identity.0.type:                                 "" => "SystemAssigned"
  location:                                        "" => "westeurope"
  name:                                            "" => "sdbx-dha-app-service-backend"
  outbound_ip_addresses:                           "" => "<computed>"
  possible_outbound_ip_addresses:                  "" => "<computed>"
  resource_group_name:                             "" => "sdbx-dha"
  site_config.#:                                   "" => "1"
  site_config.0.always_on:                         "" => "false"
  site_config.0.cors.#:                            "" => "1"
  site_config.0.cors.0.allowed_origins.#:          "" => "2"
  site_config.0.cors.0.allowed_origins.400898633:  "" => "https://sdbx-dha-app-service-frontend.azurewebsites.net"
  site_config.0.cors.0.allowed_origins.4240710842: "" => "http://localhost:8080"
  site_config.0.cors.0.support_credentials:        "" => "false"
  site_config.0.dotnet_framework_version:          "" => "v4.0"
  site_config.0.ftps_state:                        "" => "<computed>"
  site_config.0.http2_enabled:                     "" => "false"
  site_config.0.ip_restriction.#:                  "" => "<computed>"
  site_config.0.linux_fx_version:                  "" => "<computed>"
  site_config.0.local_mysql_enabled:               "" => "<computed>"
  site_config.0.min_tls_version:                   "" => "<computed>"
  site_config.0.remote_debugging_enabled:          "" => "false"
  site_config.0.scm_type:                          "" => "None"
  site_config.0.use_32_bit_worker_process:         "" => "<computed>"
  site_config.0.websockets_enabled:                "" => "<computed>"
  site_credential.#:                               "" => "<computed>"
  source_control.#:                                "" => "<computed>"
  tags.%:                                          "" => "5"
  tags.application:                                "" => "dha"
  tags.businessunit:                               "" => "businessunit"
  tags.costcenter:                                 "" => "costcenter"
  tags.deployment:                                 "" => "terraform"
  tags.environment:                                "" => "sdbx"

@dhabierre - The nil is returned when support_credentials is set (which is marked as optional in Terraform provider code).

Try to remove it , it should work properly and CORS settings are updated accordingly.
Tested with v1.24 (where PR was merged) and latest v1.29 as well. Update code fragment:

site_config {
    cors {
      allowed_origins     = "${split(",", var.cors_allowed_origins)}"
    }
}

Still, it seems call to Azure API is failing when support_credentials key=value is set.

I have the same error when using terraform 0.12.1 & azurerm 1.30.1:

resource "azurerm_app_service" "app_service_backend" {
  name                = "${local.app_resource_prefix}-app-service-backend"
  location            = azurerm_resource_group.app_resource_group.location
  resource_group_name = azurerm_resource_group.app_resource_group.name
  app_service_plan_id = azurerm_app_service_plan.app_service_plan.id
  https_only          = true

  identity {
    type = "SystemAssigned"
  }

  site_config {
    cors {
      allowed_origins = split(",", var.cors_allowed_origins)
    }
  }

  tags = local.app_tags
}
Error: web.AppsClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>

  on main.tf line 59, in resource "azurerm_app_service" "app_service_backend":
  59: resource "azurerm_app_service" "app_service_backend" {


##[error] Terraform failed to execute. Error: 
End of Task Terraform
##[section]Finishing: Terraform apply -auto-approve

Closing this in favour of #6796 which'll highlight the actual error being returned here

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings