9

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)?

Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
Preston Martin
  • 2,789
  • 3
  • 26
  • 42

2 Answers2

9

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

RuSs
  • 1,725
  • 1
  • 29
  • 47
2

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')]"
          ]
        },
Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
  • here is CORS module: https://github.com/transactiveltd/terraform-azurerm-app-service-cors and it seems to be working for me. – tridy Feb 20 '19 at 14:34
  • I see cors - (Optional) A cors block on terraform documentation, but the cors object block isn't working in site_config. Thanks tridy for helping out with terraform link. – Sidd Thota Apr 29 '19 at 14:22