Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm 1.24 & app_service CORS #3188

Closed
dhabierre opened this issue Apr 5, 2019 · 7 comments
Closed

azurerm 1.24 & app_service CORS #3188

dhabierre opened this issue Apr 5, 2019 · 7 comments

Comments

@dhabierre
Copy link

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
@Lucretius
Copy link
Contributor

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.

@dhabierre
Copy link
Author

Hi Lucretius,

You are right! My bad eyes :/

Thanks.

@dhabierre
Copy link
Author

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"

@kpatryk
Copy link

kpatryk commented Jun 6, 2019

@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.

@dhabierre
Copy link
Author

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

@tombuildsstuff
Copy link
Contributor

tombuildsstuff commented Aug 28, 2020

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

@ghost
Copy link

ghost commented Sep 27, 2020

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!

@ghost ghost locked and limited conversation to collaborators Sep 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants