This is to provide small example to create infrastructure on Azure with terraform by reading variables from Consul and saving terraform state in Consul.
We are using Consul as key/value store only. In this example we will create an empty availabilty set in azure.
Prerequisite:
-
Account in Azure portal. Install Azure cli and create test resource group.
-
Install Consul (https://www.consul.io/docs/install)
-
Install Terraform (https://learn.hashicorp.com/terraform/getting-started/install.html)
Procedure
-
For convenient purpose we will authorize terraform with azure using azure cli.
az login
-
Start the consul in dev mode. Since this is for test purpose we will start in "-dev" mode.
consul agent -dev
Terraform state and variables are not stored permanently. Once consul is stopped data is lost. Open the terminal session until this lesson is completed.
Open the Consul URL http://localhost:8500/
-
From top menu click Key/value, create 'variables' folder. In 'variables' folder create key-values called
- 'as-name' : Availabilty set name.
- 'rg' : Resource group name
-
Download the main.tf and variables.tf files from this repo. Provide your subscription and tenant id. Execute terraform commands
terraform init
terraform plan
terraform apply
Goto the Consul URL, you will see terraform state key/value will be created. If you close the Consul session data will be lost.
This can be extended with Consul Server-Agent mode to make data persistent and enabling ACL for secure access.