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

CORS settings for function app #1374

Closed
TsuyoshiUshio opened this issue Jun 9, 2018 · 12 comments
Closed

CORS settings for function app #1374

TsuyoshiUshio opened this issue Jun 9, 2018 · 12 comments

Comments

@TsuyoshiUshio
Copy link
Contributor

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

Description

When I deploy FunctionApp with CORS settings, I have no way to config that. If no one is trying this, I'd happy to contribute this.

New or Affected Resource(s)

  • azurerm_function_app

Potential Terraform Configuration

resource "azurerm_function_app" "test" {
  name                      = "test-azure-functions"
  location                  = "${azurerm_resource_group.test.location}"
  resource_group_name       = "${azurerm_resource_group.test.name}"
  app_service_plan_id       = "${azurerm_app_service_plan.test.id}"
  storage_connection_string = "${azurerm_storage_account.test.primary_connection_string}"
  cors_settings = ["http://localhost:8080", "http://aaa.bbbb.com"]
}

References

--->

  • #0000
@katbyte
Copy link
Collaborator

katbyte commented Jun 11, 2018

Hi @TsuyoshiUshio,

Currently as far as I know no one is working on this.

@kevinneufeld
Copy link

FWIW: here is our current (workaround) azurerm_template_deployment for CORS

resource "azurerm_template_deployment" "cors" {
  name                = "arm_cors"
  resource_group_name = "${azurerm_function_app.test_fn_app.resource_group_name}"
  deployment_mode     = "Incremental"

  template_body = <<DEPLOY
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "functionAppName": {
      "type": "string"
    }
  },
  "variables": {},
  "resources": [
    {
      "comments": "CORS allow origins *.",
      "type": "Microsoft.Web/sites/config",
      "name": "[concat(parameters('functionAppName'), '/web')]",
      "apiVersion": "2016-08-01",
      "properties": {
        "cors": {
          "allowedOrigins": [
            "*"
          ]
        }
      },
      "dependsOn": []
    }
  ]
}
DEPLOY

  parameters {
    "functionAppName" = "${azurerm_function_app.test_fn_app.name}"
  }

  depends_on = [
    "azurerm_function_app.test_fn_app",
  ]
}

@TsuyoshiUshio
Copy link
Contributor Author

@kevinneufeld
Thanks for sharing. :) It is helpful.

@egorchabala
Copy link

CORS has been implemented for App Service in provider v.1.24. Is there any blockers implement this for azurerm_function_app as well?

@daveobike
Copy link

Is there any new status on this? Given that functions are often implemented as service oriented API controllers, CORS is important for web browser security policies.

@stack72
Copy link
Contributor

stack72 commented Jun 14, 2019

FYI, I added this support in #3666. To follow the same convention of that of app_service, the schema will look as follows:

resource "azurerm_function_app" "test" {
  name                      = "sample-function-cors"
  location                  = "${azurerm_resource_group.test.location}"
  resource_group_name       = "${azurerm_resource_group.test.name}"
  app_service_plan_id       = "${azurerm_app_service_plan.test.id}"
  storage_connection_string = "${azurerm_storage_account.test.primary_connection_string}"

  site_config {
    cors {
      allowed_origins = [
        "http://www.contoso.com",
        "www.contoso.com",
        "contoso.com"
      ]
      support_credentials = true
    }
  }
}

@StefanSchoof
Copy link
Contributor

As workaround I created a module to wrap a az command in resources: https://registry.terraform.io/modules/StefanSchoof/function-cors/azurerm

@StefanSchoof
Copy link
Contributor

I think this is done in #3949 and released with 1.33.0.

@StefanSchoof
Copy link
Contributor

@katbyte or @tombuildsstuff: I thing this is done and can be closed.

@tombuildsstuff
Copy link
Contributor

Closing @StefanSchoof's request - thanks for the ping :)

@sonic1981
Copy link

Seems there is an issue with this causing it to fail if you specify support_credentials see: #3188 (comment)

@ghost
Copy link

ghost commented Dec 31, 2019

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 Dec 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
9 participants