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
apiVersionrequired - stringidentityoptionaltypeoptional - stringType of managed service identity.
userAssignedIdentitiesoptional - 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}
kindoptional - stringKind of resource.
locationrequired - stringResource Location.
namerequired - stringName of the static site to create or update.
propertiesrequiredallowConfigFileUpdatesoptional - boolean<code>false</code> if config file is locked for this static web app; otherwise, <code>true</code>.
branchoptional - stringThe target branch in the repository.
buildPropertiesoptionalapiBuildCommandoptional - stringA custom command to run during deployment of the Azure Functions API application.
apiLocationoptional - stringThe path to the api code within the repository.
appArtifactLocationoptional - stringDeprecated: The path of the app artifacts after building (deprecated in favor of OutputLocation)
appBuildCommandoptional - stringA custom command to run during deployment of the static content application.
appLocationoptional - stringThe path to the app code within the repository.
githubActionSecretNameOverrideoptional - stringGithub Action secret name override.
outputLocationoptional - stringThe output path of the app after building.
skipGithubActionWorkflowGenerationoptional - booleanSkip Github Action workflow generation.
repositoryTokenoptional - stringA user's github repository token. This is used to setup the Github Actions workflow file and API secrets.
repositoryUrloptional - stringURL for the repository of the static site.
stagingEnvironmentPolicyoptional - stringState indicating whether staging environments are allowed or not allowed for a static web app.
templatePropertiesoptionaldescriptionoptional - stringDescription of the newly generated repository.
isPrivateoptional - booleanWhether or not the newly generated repository is a private repository. Defaults to false (i.e. public).
owneroptional - stringOwner of the newly generated repository.
repositoryNameoptional - stringName of the newly generated repository.
templateRepositoryUrloptional - stringURL of the template repository. The newly generated repository will be based on this one.
skuoptionalcapabilitiesoptional arraynameoptional - stringName of the SKU capability.
reasonoptional - stringReason of the SKU capability.
valueoptional - stringValue of the SKU capability.
capacityoptional - integerCurrent number of instances assigned to the resource.
familyoptional - stringFamily code of the resource SKU.
locationsoptional - arrayLocations of the SKU.
nameoptional - stringName of the resource SKU.
sizeoptional - stringSize specifier of the resource SKU.
skuCapacityoptionaldefaultoptional - integerDefault number of workers for this App Service plan SKU.
elasticMaximumoptional - integerMaximum number of Elastic workers for this App Service plan SKU.
maximumoptional - integerMaximum number of workers for this App Service plan SKU.
minimumoptional - integerMinimum number of workers for this App Service plan SKU.
scaleTypeoptional - stringAvailable scale configurations for an App Service plan.
tieroptional - stringService tier of the resource SKU.
tagsoptional - stringResource tags.
typerequired - 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.