|
| 1 | +--- |
| 2 | +title: 'Quickstart: Deploy a static website on Azure Storage using Terraform' |
| 3 | +description: Learn how to deploy an Azure Storage account with static website hosting enabled. |
| 4 | +author: normesta |
| 5 | +ms.service: azure-blob-storage |
| 6 | +ms.topic: quickstart |
| 7 | +ms.date: 11/17/2021 |
| 8 | +ms.author: normesta |
| 9 | +ms.custom: devx-track-terraform |
| 10 | +content_well_notification: |
| 11 | + - AI-contribution |
| 12 | +--- |
| 13 | + |
| 14 | +# Quickstart: Deploy a static website on Azure Storage using Terraform |
| 15 | + |
| 16 | +In this quickstart, you learn how to deploy an [Azure Storage account](https://www.terraform.io/docs/providers/azurerm/r/storage_account.html) with static website hosting enabled. |
| 17 | + |
| 18 | +[!INCLUDE [About Terraform](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)] |
| 19 | + |
| 20 | +In this article, you learn how to: |
| 21 | + |
| 22 | +> [!div class="checklist"] |
| 23 | +> * Create a random value (to be used in the resource group name) using [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) |
| 24 | +> * Create an Azure resource group using [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) |
| 25 | +> * Create a random value (to be used in the storage acccount name) using [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) |
| 26 | +> * Create a storage account with a static website using [azurerm_storage_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account) |
| 27 | +> * Create a storage account blob in the using [azurerm_storage_blob](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_blob) |
| 28 | +
|
| 29 | +## Prerequisites |
| 30 | + |
| 31 | +- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure) |
| 32 | + |
| 33 | +## Implement the Terraform code |
| 34 | + |
| 35 | +> [!NOTE] |
| 36 | +> The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-storage-account-with-static-website). You can view the log file containing the [test results from current and previous versions of Terraform](https://github.com/Azure/terraform/tree/master/quickstart/101-storage-account-with-static-website/TestRecord.md). |
| 37 | +> |
| 38 | +> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform) |
| 39 | +
|
| 40 | +1. Create a directory in which to test the sample Terraform code and make it the current directory. |
| 41 | + |
| 42 | +1. Create a file named `providers.tf` and insert the following code: |
| 43 | + |
| 44 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-storage-account-with-static-website/providers.tf"::: |
| 45 | + |
| 46 | +1. Create a file named `main.tf` and insert the following code: |
| 47 | + |
| 48 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-storage-account-with-static-website/main.tf"::: |
| 49 | + |
| 50 | +1. Create a file named `variables.tf` and insert the following code: |
| 51 | + |
| 52 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-storage-account-with-static-website/variables.tf"::: |
| 53 | + |
| 54 | +1. Create a file named `outputs.tf` and insert the following code: |
| 55 | + |
| 56 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-storage-account-with-static-website/outputs.tf"::: |
| 57 | + |
| 58 | +1. Create a file named `index.html` and insert the following code: |
| 59 | + |
| 60 | + :::code language="html" source="~/terraform_samples/quickstart/101-storage-account-with-static-website/index.html"::: |
| 61 | + |
| 62 | +## Initialize Terraform |
| 63 | + |
| 64 | +[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)] |
| 65 | + |
| 66 | +## Create a Terraform execution plan |
| 67 | + |
| 68 | +[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)] |
| 69 | + |
| 70 | +## Apply a Terraform execution plan |
| 71 | + |
| 72 | +[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)] |
| 73 | + |
| 74 | +## Verify the results |
| 75 | + |
| 76 | +#### [Azure CLI](#tab/azure-cli) |
| 77 | + |
| 78 | +1. Get the URL to the static web site. |
| 79 | + |
| 80 | + ```console |
| 81 | + primary_web_host=$(terraform output -raw primary_web_host) |
| 82 | + ``` |
| 83 | + |
| 84 | +1. Open a browser and enter the URL in your browser's address bar. |
| 85 | + |
| 86 | + :::image type="content" source="./media/storage-quickstart-static-website-terraform/static-website-running-in-storage-account.png" alt-text="Screenshot of the static web site stored in an Azure storage account."::: |
| 87 | + |
| 88 | +#### [Azure PowerShell](#tab/azure-powershell) |
| 89 | + |
| 90 | +1. Get the URL to the static web site. |
| 91 | + |
| 92 | + ```console |
| 93 | + $primary_web_host=$(terraform output -raw primary_web_host) |
| 94 | + ``` |
| 95 | + |
| 96 | +1. Open a browser and enter the URL in your browser's address bar. |
| 97 | + |
| 98 | + :::image type="content" source="./media/storage-quickstart-static-website-terraform/static-website-running-in-storage-account.png" alt-text="Screenshot of the static web site stored in an Azure storage account."::: |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +## Clean up resources |
| 103 | + |
| 104 | +[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)] |
| 105 | + |
| 106 | +## Troubleshoot Terraform on Azure |
| 107 | + |
| 108 | +[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot) |
| 109 | + |
| 110 | +## Next steps |
| 111 | + |
| 112 | +> [!div class="nextstepaction"] |
| 113 | +> [Introduction to Azure Blob Storage](./storage-blobs-introduction.md) |
0 commit comments