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

Support for app settings configuration for azurerm_static_site #13451

Open
irnc opened this issue Sep 22, 2021 · 6 comments
Open

Support for app settings configuration for azurerm_static_site #13451

irnc opened this issue Sep 22, 2021 · 6 comments

Comments

@irnc
Copy link

irnc commented Sep 22, 2021

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

New or Affected Resource(s)

  • azurerm_static_site

Potential Terraform Configuration

Same as app_settings for azurerm_app_service and azurerm_function_app: app_settings - (Optional) A map of key-value pairs for App Settings and custom values.

resource "azurerm_static_site" "example" {
  name                = "example"
  app_settings = {
    "SOME_KEY" = "some-value"
  }
}

References

@fvdnabee
Copy link
Contributor

fvdnabee commented Feb 3, 2022

One work-around for setting SWA App Settings is to provision an ARM Resource Group Template Deployment via azurerm_resource_group_template_deployment for a Microsoft.Web/staticSites/config resource. Just make sure you link it to the correct parent resource for your SWA.

Working example:

variable "resource_group_name" {}

data "azurerm_resource_group" "rg" {
  name = var.resource_group_name
}

variable "swa_name" {}
variable "swa_sku_tier" {}

resource "azurerm_static_site" "frontend" {
  name                = var.swa_name
  resource_group_name = data.azurerm_resource_group.rg.name
  location            = data.azurerm_resource_group.rg.location
  sku_tier            = var.swa_sku_tier
}

variable "app_setting1" {}
variable "app_setting2" {}

resource "azurerm_resource_group_template_deployment" "frontend_appsettings" {
  deployment_mode     = "Incremental"
  name                = "frontend-appsettings"
  resource_group_name = data.azurerm_resource_group.rg.name

  template_content = file("staticwebapp-arm-staticsite-config.json")
  parameters_content = jsonencode({
    staticSiteName = {
      value = azurerm_static_site.frontend.name
    },
    appSetting1 = {
      value = var.app_setting1
    },
    appSetting2 = {
      value = var.app_setting2
    },
  })
}

With staticwebapp-arm-staticsite-config.json:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "staticSiteName": {
      "type": "string"
    },
    "appSetting1": {
      "type": "string"
    },
    "appSetting2": {
      "type": "string"
    }
  },
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.Web/staticSites/config",
      "apiVersion": "2020-10-01",
      "name": "[concat(parameters('staticSiteName'), '/appsettings')]",
      "kind": "string",
      "properties": {
        "APP_SETTING1": "[parameters('appSetting1')]",
        "APP_SETTING2": "[parameters('appSetting2')]"
      }
    }
  ],
  "outputs": {}
}

@kiranpradeep

This comment was marked as off-topic.

@zhenik

This comment was marked as off-topic.

@Devvox93
Copy link

It's not just the app settings, it is also other configuration.
If you look at the Terraform template reference for Microsoft.Web staticSites in the docs, as well as the subresources (check navigation to the left), you see that all those resources and settings are documented to use "azapi_resource" with

body = jsonencode({
    properties = {
        ...
    }
})

Perhaps this is a separate issue, but I don't see why solving this for the app settings could not be part of general support for the entire API version (which is 2022-03-01 in the aforementioned docs).

This issue has no milestone yet. While the azapi_resource approach is documented well, it would be nice to have an implementation like there is for other (Terraform/Azure) resources.
Any update on where this fits on the roadmap?

I could maybe try to work on this if time permits it, but only if it would be merged or picked up further.

@jonnekleijer
Copy link

Is it supported now? Since azurerm 3.76.0 it is in the documentation:
https://registry.terraform.io/providers/hashicorp/azurerm/3.76.0/docs/resources/static_site

@jdelforno
Copy link

Is it supported now? Since azurerm 3.76.0 it is in the documentation: https://registry.terraform.io/providers/hashicorp/azurerm/3.76.0/docs/resources/static_site

It's documented but I just tried to use it and it's not working unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants