Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@
| `azurerm_private_dns_zone` | [simple](azurerm/azurerm_private_dns_zone/simple) |
| `azurerm_public_ip` | [simple](azurerm/azurerm_public_ip/simple) |
| `azurerm_sql_server` | [simple](azurerm/azurerm_sql_server/simple) |
| `azurerm_storage_account` | [simple](azurerm/azurerm_storage_account/simple) |
| `azurerm_storage_account` | [simple](azurerm/azurerm_storage_account/simple) <p/> [azure, backends](backends/azure/azurerm_storage_container) |
| `azurerm_storage_blob` | [append](azurerm/azurerm_storage_blob/append) <p/> [block](azurerm/azurerm_storage_blob/block) <p/> [page](azurerm/azurerm_storage_blob/page) |
| `azurerm_storage_container` | [simple](azurerm/azurerm_storage_container/simple) |
| `azurerm_storage_container` | [simple](azurerm/azurerm_storage_container/simple) <p/> [azure, backends](backends/azure/azurerm_storage_container) |
| `azurerm_storage_queue` | [simple](azurerm/azurerm_storage_queue/simple) |
| `azurerm_storage_share` | [simple](azurerm/azurerm_storage_share/simple) |
| `azurerm_storage_table` | [simple](azurerm/azurerm_storage_table/simple) |
| `azurerm_subnet` | [simple](azurerm/azurerm_subnet/simple) |
| `azurerm_subscription` | [customer_account](azurerm/azurerm_subscription/customer_account) <p/> [enterprise_enrollment](azurerm/azurerm_subscription/enterprise_enrollment) |
| `azurerm_virtual_machine` | [linux](azurerm/azurerm_virtual_machine/linux) <p/> [windows](azurerm/azurerm_virtual_machine/windows) |
| `azurerm_virtual_network` | [azure](azurerm/azurerm_virtual_network/simple) |
| `azurerm_virtual_network` | [azure](azurerm/azurerm_virtual_network/simple) <p/> [azure, backends](backends/azure/azurerm_virtual_network) |
| `azurerm_windows_virtual_machine` | [simple](azurerm/azurerm_windows_virtual_machine/simple) |
| `backends` | [backends](backends) <p/> [aws, s3, aws_s3_bucket](backends/s3/aws_s3_bucket) <p/> [aws, remote](backends/remote) <p/> [google, gcs_bucket](backends/gcs/google_storage_bucket) |
| `backends` | [backends](backends) <p/> [aws, s3, aws_s3_bucket](backends/s3/aws_s3_bucket) <p/> [aws, remote](backends/remote) <p/> [google, gcs_bucket](backends/gcs/google_storage_bucket) <p/> [azure, azurerm_storage_container](backends/azure/azurerm_storage_container) |
| `count` | [aws, aws_instance](aws/aws_instance/count) <p/> [aws, aws_vpc](aws/aws_vpc/count) <p/> [google, gcp_attached_disk](google/google_compute_attached_disk/count) |
| `depends_on` | [aws](aws/aws_iam/groups) |
| `digitalocean` | [simple](digitalocean/digitalocean_droplet/simple) |
Expand Down
22 changes: 22 additions & 0 deletions backends/azure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
This example sets up an Azure Storage backend with a minimal example of a state stored in it.

It:

- Creates an Azure Storage account with a random name ('changemexxxxxxxxxxxxx') and a Container ('changemebackendazure')

- Sets up an Azure Virtual Network, storing state in that backend

These are the files used:

`destroy.sh` - Shell script to clean up any previous run of `run.sh`

`run.sh` - Run this whole example up, creating the Container, backend, and Azure Virtual Network

`azurerm_storage_container/main.tf` - Terraform code to set up a Container

`azurerm_storage_container/run.sh` - Script to create just the Container

`azurerm_storage_container/destroy.sh` - Script to destroy just the Container

`azurerm_virtual_network/main_template` - Template file for Terraform code for Azure Virtual Network

2 changes: 2 additions & 0 deletions backends/azure/azurerm_storage_container/destroy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
../../../bin/destroy.sh azurerm
58 changes: 58 additions & 0 deletions backends/azure/azurerm_storage_container/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Summary: Creates an Azure Storage account and a Container

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
required_version = ">= 1.0.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 2.0"
}
}
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "azure_subscription_id" {
type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
# Documentation: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
provider "azurerm" {
features {}

subscription_id = var.azure_subscription_id
}


# Explanation: This resource is not necessary for the creation of an Azure Storage Account, but is here to ensure that
# the Azure Account name is unique.
#
# Documentation: https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id
resource "random_id" "changeme_backends_azure_storage_name" {
byte_length = 8
}

# Resource Group
# Documentation: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group
resource "azurerm_resource_group" "changeme_backends_azure_storage_resource_group" {
name = "changeme-azure-storage-container-resource-group"
location = "East US"
}

# Storage Account within the Resource Group
# Documentation: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account
resource "azurerm_storage_account" "changeme_backends_azure_storage_account" {
name = "changeme${random_id.changeme_backends_azure_storage_name.hex}"
resource_group_name = azurerm_resource_group.changeme_backends_azure_storage_resource_group.name
location = azurerm_resource_group.changeme_backends_azure_storage_resource_group.location
account_tier = "Standard"
account_replication_type = "LRS"
}

# Storage Container in the Storage Account
# Documentation: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_container
resource "azurerm_storage_container" "changeme_backends_azure_storage_container" {
name = "changemebackendazure"
storage_account_name = azurerm_storage_account.changeme_backends_azure_storage_account.name
}
3 changes: 3 additions & 0 deletions backends/azure/azurerm_storage_container/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
../../../bin/apply.sh azurerm

2 changes: 2 additions & 0 deletions backends/azure/azurerm_virtual_network/destroy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
../../../bin/destroy.sh azurerm
49 changes: 49 additions & 0 deletions backends/azure/azurerm_virtual_network/main_template
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Summary: A simple Azure Virtual Network

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {

#required_version = ">= 1.0.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 2.0"
}
}

backend "azurerm" {
resource_group_name = "changeme-azure-storage-container-resource-group"
storage_account_name = ACCOUNT_NAME
container_name = "changemebackendazure"
key = "terraform.tfstate"
}
}

# Documentation: https://www.terraform.io/docs/language/values/variables.html
variable "azure_subscription_id" {
type = string
}

# Documentation: https://www.terraform.io/docs/language/providers/requirements.html
# Documentation: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
provider "azurerm" {
features {}

subscription_id = var.azure_subscription_id
}

# Resource Group
# Documentation: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group
resource "azurerm_resource_group" "changeme_azure_backend_storage_resource_group" {
name = "changeme-azure-backend-storage-resource-group"
location = "East US"
}

# Virtual Network within the Resource Group
# Documentation: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network
resource "azurerm_virtual_network" "changeme_azure_backend_storage_virtual_network" {
name = "changeme-azure-backend-storage-virtual-network"
resource_group_name = azurerm_resource_group.changeme_azure_backend_storage_resource_group.name
location = azurerm_resource_group.changeme_azure_backend_storage_resource_group.location
address_space = ["10.0.0.0/16"]
}
15 changes: 15 additions & 0 deletions backends/azure/destroy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Move to the folder this script is in.
cd "${0%/*}" || exit 1

# shellcheck disable=SC1091
source ../../bin/shared.sh

log "Cleaning up azurerm_virtual_network"
cd azurerm_virtual_network || exit 1
rm -f main.tf
./destroy.sh 2>/dev/null || rm -rf .terraform terraform*
log "Cleaning up azurerm_storage_container"
cd ../azurerm_storage_container || exit 1
terraform destroy -auto-approve
27 changes: 27 additions & 0 deletions backends/azure/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Move to the folder this script is in.
cd "${0%/*}" || exit 1

# shellcheck disable=SC1091
source ../../bin/shared.sh

log "Destroying any pre-existing runs..."
./destroy.sh

log "Set up Azure Storage Account and Container..."
cd azurerm_storage_container || exit 1
# shellcheck disable=SC1091
source run.sh
terraform init
terraform plan
terraform apply -auto-approve
ACCOUNT_NAME="$(terraform show | grep storage_account_name | awk '{print $NF}')"
log "Azure Storage account name is: ${ACCOUNT_NAME}"
cd ../azurerm_virtual_network || exit 1
log "Setting up Terraform code from main_template in azurerm_virtual_network..."
sed "s/ACCOUNT_NAME/${ACCOUNT_NAME}/g" main_template > main.tf
log "Set up virtual network, storing state in backend..."
terraform init
terraform plan
terraform apply -auto-approve