I am going to show how you can deploy a static Azure Storage Website using Terraform; this supports static content from HTML, CSS, JavaScript and Image Files.
These files are served from a storage container that needs to be called $web
A V2 Storage Account is also required. During initial setup of the website it will create a folder called $web as a blob within the Storage Account
Note:- Contents of $web are case sensitive
Overview of my Terraform
The static website will be deployed using Terraform, with the following folder structure:-
Azure-StorageAccount-StaticWebsite-Terraform └──terraform └──index.html └──main.tf └──terraform.tfvars └──variables.tf
index.html
The .html webpage that you want to be displayed
<h1> thomasthornton.cloud example </h1>
main.tf
Declaring required providers to create static website
provider "azurerm" { # The "feature" block is required for AzureRM provider 2.x. # If you're using version 1.x, the "features" block is not allowed. version = "~>2.0" features {} } data "azurerm_client_config" "current" {} #Create Resource Group resource "azurerm_resource_group" "resource_group" { name = var.resource_group location = var.location } #Create Storage account resource "azurerm_storage_account" "storage_account" { name = var.storage_account resource_group_name = azurerm_resource_group.resource_group.name location = var.location account_tier = "Standard" account_replication_type = "LRS" account_kind = "StorageV2" static_website { index_document = "index.html" } } #Add index.html to blob storage resource "azurerm_storage_blob" "example" { name = "index.html" storage_account_name = azurerm_storage_account.storage_account.name storage_container_name = "$web" type = "Block" content_type = "text/html" source = "index.html" }
terraform.tfvars
Variable names for the required location, resource group & storage account
location = "eastus2" resource_group = "tamopswebsiterg" storage_account = "tamopswebsitesa"
variables.tf
Declare required variables
variable "location" { type = string description = "Azure Region Location" } variable "resource_group" { type = string description = "Resource Group Name" } variable "storage_account" { type = string description = "Storage Account Name" }
Reviewing the deployment
After you deploy the above using Terraform, lets review in the Azure Portal


Now to test the static website, using URL:- https://tamopswebsitesa.z20.web.core.windows.net/
