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
resource "azurerm_static_site" "webss" {
name = var.sitename
resource_group_name = azurerm_resource_group.webrgp.name
location = azurerm_resource_group.webrgp.location
resource "azurerm_static_site" "cats" {
name = "cats"
location = "westeurope"
resource_group_name = azurerm_resource_group.rg.name
sku_size = "Free"
sku_tier = "Free"
resource "azurerm_static_site" "srcs_help" {
name = "srcs-help"
resource_group_name = "src"
location = "eastasia"
}
resource "azurerm_static_site" "srcs_data_viewer" {
name = "srcs-data-viewer"
resource_group_name = "src"
location = "eastasia"
}
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
}
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
}
resource "azurerm_static_site" "terr_staticsite" {
name = "demostttsite446"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
}
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
}
resource "azurerm_static_site" "test" {
name = "example"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_static_site" "GoAzure" {
name = "website"
resource_group_name = azurerm_resource_group.GoAzure.name
location = "West Europe"
}
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.
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.
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.
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
"type": "Microsoft.Web/staticSites",
"location": "[parameters('location1')]",
"tags": "[parameters('webappresourceTags')]",
"properties": {
"repositoryUrl": "[parameters('repositoryUrl')]",
"branch": "[parameters('branch')]",
"type": "Microsoft.Web/staticSites",
"location": "West US 2",
"properties": {
"defaultHostname": "happy-sea-15afae3e.azurestaticwebsites.net",
"repositoryUrl": "https://github.com/username/RepoName",
"branch": "demo",
"type": "Microsoft.Web/staticSites",
"location": "West US 2",
"properties": {
"defaultHostname": "happy-sea-15afae3e.azurestaticwebsites.net",
"repositoryUrl": "https://github.com/username/RepoName",
"branch": "demo",
"type": "Microsoft.Web/staticSites",
"location": "[parameters('location')]",
"properties": {
"repositoryUrl": "[parameters('repositoryUrl')]",
"branch": "[parameters('branch')]",
"repositoryToken": "[parameters('repositoryToken')]",
"type": "Microsoft.Web/staticSites",
"location": "Central US EUAP",
"properties": {
"repositoryToken": "[parameters('githubPersonalAccessToken')]",
"buildProperties": {
"appLocation": "/"
"type": "Microsoft.Web/staticSites",
"location": "West US 2",
"properties": {
"defaultHostname": "happy-sea-15afae3e.azurestaticwebsites.net",
"repositoryUrl": "https://github.com/username/RepoName",
"branch": "demo",
"type": "Microsoft.Web/staticSites",
"location": "West US 2",
"properties": {
"defaultHostname": "happy-sea-15afae3e.azurestaticwebsites.net",
"repositoryUrl": "https://github.com/username/RepoName",
"branch": "demo",
"type": "Microsoft.Web/staticSites",
"location": "West US 2",
"properties": {
"defaultHostname": "happy-sea-15afae3e.azurestaticwebsites.net",
"repositoryUrl": "https://github.com/username/RepoName",
"branch": "demo",
"type": "Microsoft.Web/staticSites",
"location": "West US 2",
"properties": {
"defaultHostname": "happy-sea-15afae3e.azurestaticwebsites.net",
"repositoryUrl": "https://github.com/username/RepoName",
"branch": "demo",
"type": "Microsoft.Web/staticSites",
"location": "[parameters('location')]",
"tags": "[parameters('resourceTags')]",
"properties": {
"repositoryUrl": "[parameters('repositoryUrl')]",
"branch": "[parameters('branch')]",
Parameters
apiVersion
required - stringidentity
optionaltype
optional - stringType of managed service identity.
userAssignedIdentities
optional - undefinedThe 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 - stringKind of resource.
location
required - stringResource Location.
name
required - stringName of the static site to create or update.
properties
requiredallowConfigFileUpdates
optional - boolean<code>false</code> if config file is locked for this static web app; otherwise, <code>true</code>.
branch
optional - stringThe target branch in the repository.
buildProperties
optionalapiBuildCommand
optional - stringA custom command to run during deployment of the Azure Functions API application.
apiLocation
optional - stringThe path to the api code within the repository.
appArtifactLocation
optional - stringDeprecated: The path of the app artifacts after building (deprecated in favor of OutputLocation)
appBuildCommand
optional - stringA custom command to run during deployment of the static content application.
appLocation
optional - stringThe path to the app code within the repository.
githubActionSecretNameOverride
optional - stringGithub Action secret name override.
outputLocation
optional - stringThe output path of the app after building.
skipGithubActionWorkflowGeneration
optional - booleanSkip Github Action workflow generation.
repositoryToken
optional - stringA user's github repository token. This is used to setup the Github Actions workflow file and API secrets.
repositoryUrl
optional - stringURL for the repository of the static site.
stagingEnvironmentPolicy
optional - stringState indicating whether staging environments are allowed or not allowed for a static web app.
templateProperties
optionaldescription
optional - stringDescription of the newly generated repository.
isPrivate
optional - booleanWhether or not the newly generated repository is a private repository. Defaults to false (i.e. public).
owner
optional - stringOwner of the newly generated repository.
repositoryName
optional - stringName of the newly generated repository.
templateRepositoryUrl
optional - stringURL of the template repository. The newly generated repository will be based on this one.
sku
optionalcapabilities
optional arrayname
optional - stringName of the SKU capability.
reason
optional - stringReason of the SKU capability.
value
optional - stringValue of the SKU capability.
capacity
optional - integerCurrent number of instances assigned to the resource.
family
optional - stringFamily code of the resource SKU.
locations
optional - arrayLocations of the SKU.
name
optional - stringName of the resource SKU.
size
optional - stringSize specifier of the resource SKU.
skuCapacity
optionaldefault
optional - integerDefault number of workers for this App Service plan SKU.
elasticMaximum
optional - integerMaximum number of Elastic workers for this App Service plan SKU.
maximum
optional - integerMaximum number of workers for this App Service plan SKU.
minimum
optional - integerMinimum number of workers for this App Service plan SKU.
scaleType
optional - stringAvailable scale configurations for an App Service plan.
tier
optional - stringService tier of the resource SKU.
tags
optional - stringResource 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.