Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring CORS in a Terraform Azure App Service Resource

I have the following Terraform resource for configuring an Azure app service:

resource "azurerm_app_service" "app_service" {
  name                = "Test-App-Service-3479112"
  location            = "${azurerm_resource_group.resource_group.location}"
  resource_group_name = "${azurerm_resource_group.resource_group.name}"
  app_service_plan_id = "${azurerm_app_service_plan.app_service_plan.id}"

  site_config {
    dotnet_framework_version = "v4.0"
    remote_debugging_version = "VS2012"
  }

  app_settings {
    "ASPNETCORE_ENVIRONMENT" = "test"
    "WEBSITE_NODE_DEFAULT_VERSION" = "4.4.7"
  }
}

I am attempting to add a CORS origin value to be utilized in my resource. Is there way to add this in Terraform, or if there is not, how could I go about configuring this in my Terraform file (possibly with the Azure SDK)?

like image 818
Preston Martin Avatar asked Dec 08 '17 16:12

Preston Martin


2 Answers

All,

This is now available here: https://www.terraform.io/docs/providers/azurerm/r/app_service.html#cors

And here is my example:

resource "azurerm_app_service" "my-app" {
  name                = "${var.api_name}"
  location            = "${var.location}"
  resource_group_name = "${var.resource_group}"
  app_service_plan_id = "${azurerm_app_service_plan.api_asp.id}"

  site_config {
    cors {
      allowed_origins = ["https://${var.ui_name}${var.dns_suffix}"]
    }
  }

  identity = {
    type = "SystemAssigned"
  }
}

And proof that the above works: enter image description here

like image 198
RuSs Avatar answered Oct 18 '22 01:10

RuSs


Currently, it is not supported. You could check azurerm_app_service.

In currently terrform version, cors is not supported.

If possible, you could use Azure template to do this, you could check this example.

 "properties": {
        "cors": {
          "allowedOrigins": [
            "[concat('https://', parameters('siteName'), '.azurewebsites.net')]"
          ]
        },
like image 25
Shui shengbao Avatar answered Oct 18 '22 00:10

Shui shengbao