Azure App Service (Web Apps) Static Site

This page shows how to write Terraform and Azure Resource Manager for App Service (Web Apps) Static Site and write them securely.

azurerm_static_site (Terraform)

The Static Site in App Service (Web Apps) can be configured in Terraform with the resource name azurerm_static_site. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

webapp.tf#L1
resource "azurerm_static_site" "webss" {
  name                = var.sitename
  resource_group_name = azurerm_resource_group.webrgp.name
  location            = azurerm_resource_group.webrgp.location
main.tf#L22
resource "azurerm_static_site" "cats" {
  name                = "cats"
  location            = "westeurope"
  resource_group_name = azurerm_resource_group.rg.name
  sku_size            = "Free"
  sku_tier            = "Free"
help.tf#L2
resource "azurerm_static_site" "srcs_help" {
  name                = "srcs-help"
  resource_group_name = "src"
  location            = "eastasia"
}
viewer.tf#L2
resource "azurerm_static_site" "srcs_data_viewer" {
  name                = "srcs-data-viewer"
  resource_group_name = "src"
  location            = "eastasia"
}
resource_static_site.tf#L2
resource "azurerm_static_site" "wesleytrust-com" {
  name                = local.resource_name
  resource_group_name = azurerm_resource_group.resource_group.name
  location            = azurerm_resource_group.resource_group.location
}
static-site.tf#L9
resource "azurerm_static_site" "mdkb" {
  name                = azurerm_resource_group.mdkb.name
  location            = azurerm_resource_group.mdkb.location
  resource_group_name = azurerm_resource_group.mdkb.name
}

main.tf#L11
resource "azurerm_static_site" "terr_staticsite" {
  name                = "demostttsite446"
  resource_group_name = azurerm_resource_group.rg.name
  location            = azurerm_resource_group.rg.location
}

main.tf#L38
resource "azurerm_static_site" "amapolis_dot_dev_web_app" {
  name                = "amapolis-dot-dev-web-app"
  resource_group_name = azurerm_resource_group.amapolis_dot_dev_resource_group.name
  location            = azurerm_resource_group.amapolis_dot_dev_resource_group.location
}
main.tf#L26
resource "azurerm_static_site" "test" {
  name                = "example"
  location            = azurerm_resource_group.test.location
  resource_group_name = azurerm_resource_group.test.name
}

main.tf#L10
resource "azurerm_static_site" "GoAzure" {
  name                = "website"
  resource_group_name = azurerm_resource_group.GoAzure.name
  location            = "West Europe"
}

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

The following arguments are supported:

  • name - (Required) The name which should be used for this Static Web App. Changing this forces a new Static Web App to be created.

  • location - (Required) The Azure Region where the Static Web App should exist. Changing this forces a new Static Web App to be created.

  • resource_group_name - (Required) The name of the Resource Group where the Static Web App should exist. Changing this forces a new Static Web App to be created.

  • sku_tier - (Optional) Specifies the sku tier of the Static Web App. Possible values are "Free" or "Standard". Defaults to "Free".

  • sku_size - (Optional) Specifies the sku size of the Static Web App. Possible values are "Free" or "Standard". Defaults to "Free".

  • tags - (Optional) A mapping of tags to assign to the resource.

In addition to the Arguments listed above - the following Attributes are exported:

  • id - The ID of the Static Web App.

  • api_key - The API key of this Static Web App, which is used for later interacting with this Static Web App from other clients, e.g. Github Action.

  • default_host_name - The default host name of the Static Web App.

Explanation in Terraform Registry

Manages an App Service Static Site. ->NOTE: After the Static Site is provisioned, you'll need to associate your target repository, which contains your web app, to the Static Site, by following the Azure Static Site document.

Tips: Best Practices for The Other Azure App Service (Web Apps) Resources

In addition to the azurerm_app_service, Azure App Service (Web Apps) has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

azurerm_app_service

Ensure your App Service is accessible via HTTPS only

It is better to configure the App Service to be accessible via HTTPS only. By default, both HTTP and HTTPS are available.

risk-label

azurerm_function_app

Ensure to enable authentication to prevent anonymous request being accepted

It is better to enable authentication to prevent anonymous requests and ensure all communications in the application are authenticated.

Review your Azure App Service (Web Apps) settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Microsoft.Web/staticSites (Azure Resource Manager)

The staticSites in Microsoft.Web can be configured in Azure Resource Manager with the resource name Microsoft.Web/staticSites. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

Tyrell_Corp_Deploy.json#L65
                "type": "Microsoft.Web/staticSites",
                "location": "[parameters('location1')]",
                "tags": "[parameters('webappresourceTags')]",
                "properties": {
                    "repositoryUrl": "[parameters('repositoryUrl')]",
                    "branch": "[parameters('branch')]",
PatchStaticSite.json#L17
        "type": "Microsoft.Web/staticSites",
        "location": "West US 2",
        "properties": {
          "defaultHostname": "happy-sea-15afae3e.azurestaticwebsites.net",
          "repositoryUrl": "https://github.com/username/RepoName",
          "branch": "demo",
CreateOrUpdateStaticSite.json#L31
        "type": "Microsoft.Web/staticSites",
        "location": "West US 2",
        "properties": {
          "defaultHostname": "happy-sea-15afae3e.azurestaticwebsites.net",
          "repositoryUrl": "https://github.com/username/RepoName",
          "branch": "demo",
azure-deploy.arm.json#L37
            "type": "Microsoft.Web/staticSites",
            "location": "[parameters('location')]",
            "properties": {
                "repositoryUrl": "[parameters('repositoryUrl')]",
                "branch": "[parameters('branch')]",
                "repositoryToken": "[parameters('repositoryToken')]",
example.json#L22
            "type": "Microsoft.Web/staticSites",
            "location": "Central US EUAP",
            "properties": {
                "repositoryToken": "[parameters('githubPersonalAccessToken')]",
                "buildProperties": {
                    "appLocation": "/"
PatchStaticSite.json#L17
        "type": "Microsoft.Web/staticSites",
        "location": "West US 2",
        "properties": {
          "defaultHostname": "happy-sea-15afae3e.azurestaticwebsites.net",
          "repositoryUrl": "https://github.com/username/RepoName",
          "branch": "demo",
PatchStaticSite.json#L17
        "type": "Microsoft.Web/staticSites",
        "location": "West US 2",
        "properties": {
          "defaultHostname": "happy-sea-15afae3e.azurestaticwebsites.net",
          "repositoryUrl": "https://github.com/username/RepoName",
          "branch": "demo",
PatchStaticSite.json#L17
        "type": "Microsoft.Web/staticSites",
        "location": "West US 2",
        "properties": {
          "defaultHostname": "happy-sea-15afae3e.azurestaticwebsites.net",
          "repositoryUrl": "https://github.com/username/RepoName",
          "branch": "demo",
PatchStaticSite.json#L17
        "type": "Microsoft.Web/staticSites",
        "location": "West US 2",
        "properties": {
          "defaultHostname": "happy-sea-15afae3e.azurestaticwebsites.net",
          "repositoryUrl": "https://github.com/username/RepoName",
          "branch": "demo",
azuredeploy.json#L46
                "type": "Microsoft.Web/staticSites",
                "location": "[parameters('location')]",
                "tags": "[parameters('resourceTags')]",
                "properties": {
                    "repositoryUrl": "[parameters('repositoryUrl')]",
                    "branch": "[parameters('branch')]",

Parameters

  • apiVersion required - string
  • identity optional
      • type optional - string

        Type of managed service identity.

      • userAssignedIdentities optional - undefined

        The list of user assigned identities associated with the resource. The user identity dictionary key references will be ARM resource ids in the form: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}

  • kind optional - string

    Kind of resource.

  • location required - string

    Resource Location.

  • name required - string

    Name of the static site to create or update.

  • properties required
      • allowConfigFileUpdates optional - boolean

        <code>false</code> if config file is locked for this static web app; otherwise, <code>true</code>.

      • branch optional - string

        The target branch in the repository.

      • buildProperties optional
          • apiBuildCommand optional - string

            A custom command to run during deployment of the Azure Functions API application.

          • apiLocation optional - string

            The path to the api code within the repository.

          • appArtifactLocation optional - string

            Deprecated: The path of the app artifacts after building (deprecated in favor of OutputLocation)

          • appBuildCommand optional - string

            A custom command to run during deployment of the static content application.

          • appLocation optional - string

            The path to the app code within the repository.

          • githubActionSecretNameOverride optional - string

            Github Action secret name override.

          • outputLocation optional - string

            The output path of the app after building.

          • skipGithubActionWorkflowGeneration optional - boolean

            Skip Github Action workflow generation.

      • repositoryToken optional - string

        A user's github repository token. This is used to setup the Github Actions workflow file and API secrets.

      • repositoryUrl optional - string

        URL for the repository of the static site.

      • stagingEnvironmentPolicy optional - string

        State indicating whether staging environments are allowed or not allowed for a static web app.

      • templateProperties optional
          • description optional - string

            Description of the newly generated repository.

          • isPrivate optional - boolean

            Whether or not the newly generated repository is a private repository. Defaults to false (i.e. public).

          • owner optional - string

            Owner of the newly generated repository.

          • repositoryName optional - string

            Name of the newly generated repository.

          • templateRepositoryUrl optional - string

            URL of the template repository. The newly generated repository will be based on this one.

  • sku optional
      • capabilities optional array
          • name optional - string

            Name of the SKU capability.

          • reason optional - string

            Reason of the SKU capability.

          • value optional - string

            Value of the SKU capability.

      • capacity optional - integer

        Current number of instances assigned to the resource.

      • family optional - string

        Family code of the resource SKU.

      • locations optional - array

        Locations of the SKU.

      • name optional - string

        Name of the resource SKU.

      • size optional - string

        Size specifier of the resource SKU.

      • skuCapacity optional
          • default optional - integer

            Default number of workers for this App Service plan SKU.

          • elasticMaximum optional - integer

            Maximum number of Elastic workers for this App Service plan SKU.

          • maximum optional - integer

            Maximum number of workers for this App Service plan SKU.

          • minimum optional - integer

            Minimum number of workers for this App Service plan SKU.

          • scaleType optional - string

            Available scale configurations for an App Service plan.

      • tier optional - string

        Service tier of the resource SKU.

  • tags optional - string

    Resource tags.

  • type required - string

Frequently asked questions

What is Azure App Service (Web Apps) Static Site?

Azure App Service (Web Apps) Static Site is a resource for App Service (Web Apps) of Microsoft Azure. Settings can be wrote in Terraform.

Where can I find the example code for the Azure App Service (Web Apps) Static Site?

For Terraform, the Official-James/about.jamescook.dev, johannesg/aws-cats and 7474/SRC source code examples are useful. See the Terraform Example section for further details.

For Azure Resource Manager, the dhillii/PGCC-Cloud-Portfolio, debhol/azuredocs and debhol/azuredocs source code examples are useful. See the Azure Resource Manager Example section for further details.