├── README.md ├── main.tf └── outputs.tf /README.md: -------------------------------------------------------------------------------- 1 | # devops-terraform 2 | 3 | 4 | This repository contains sample Terraform configuration that can be used to provision a resource group and a storage account static website on Azure. 5 | 6 | 7 | ## Prerequisites 8 | 9 | 10 | - Install [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest) 11 | - Install [Terraform](https://learn.hashicorp.com/terraform/getting-started/install) 12 | 13 | 14 | To run the following sample project you need to login with your Azure account: 15 | 16 | 17 | ```az login``` 18 | 19 | ## Build and run 20 | 21 | Create remote state with: 22 | 23 | ``` 24 | terraform init 25 | ``` 26 | 27 | Run terraform validate command to validate the configuration files in a directory: 28 | 29 | ``` 30 | terraform validate 31 | ``` 32 | 33 | Run terraform plan to verify creation process and then terraform apply to create real resources: 34 | 35 | ``` 36 | terraform plan 37 | terraform apply 38 | ``` 39 | 40 | After executing the apply command you will get a prompt that will ask if you want to create it, enter `yes`. 41 | 42 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | provider "azurerm" { 2 | version = "=2.0.0" 3 | features {} 4 | } 5 | 6 | 7 | # Create a resource group 8 | resource "azurerm_resource_group" "resource_group" { 9 | name = "rg-devops-showcase" 10 | location = "East US" 11 | } 12 | 13 | # Create azure storage account used to host a static website. 14 | resource "azurerm_storage_account" "storage_account" { 15 | name = "stdevopsshowcase" 16 | resource_group_name = azurerm_resource_group.resource_group.name 17 | location = "East US" 18 | 19 | # Storage account kind needs to be "StorageV2" to support static website hosting 20 | account_kind = "StorageV2" 21 | account_tier = "Standard" 22 | account_replication_type = "GRS" 23 | 24 | enable_https_traffic_only = true 25 | 26 | static_website { 27 | index_document = "index.html" 28 | error_404_document = "index.html" 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /outputs.tf: -------------------------------------------------------------------------------- 1 | # Output variables for Resource group 2 | 3 | 4 | output "resource_name" { 5 | value = azurerm_resource_group.resource_group.name 6 | description = "Output name of the created Resource Group" 7 | } 8 | 9 | 10 | # Output variables for the Static Website module 11 | 12 | output "name" { 13 | value = azurerm_storage_account.storage_account.name 14 | description = "Output name of the storage account." 15 | } 16 | 17 | output "primary_connection_string" { 18 | value = azurerm_storage_account.storage_account.primary_connection_string 19 | sensitive = true 20 | description = "The connection string associated with the primary location." 21 | } 22 | 23 | output "primary_access_key" { 24 | value = azurerm_storage_account.storage_account.primary_access_key 25 | sensitive = true 26 | description = "The primary access key for the storage account." 27 | } 28 | 29 | output "primary_web_endpoint" { 30 | value = azurerm_storage_account.storage_account.primary_web_host 31 | description = "The endpoint URL for web storage in the primary location." 32 | } 33 | 34 | output "secondary_web_endpoint" { 35 | value = azurerm_storage_account.storage_account.secondary_web_host 36 | description = "The endpoint URL for web storage in the secondary location." 37 | } 38 | --------------------------------------------------------------------------------