This repository shows how we can use Containers and Terraform to build a Linux VM Scalable Sets. This tutorial uses a cloud storage container to store the Terraform backend. Click here to see options of how you can manage your Terraform backend.
-
You need to have a Service Principal - it gives you a
CLIENT_ID
andCLIENT_PASSWORD
that I am using as environment variables (example.env) -
You need an Azure SUBSCRIPTION_ID and TENANT_ID to make the communication between Terraform and the provider.
-
This tutorial uses a remote Terraform state which requires a Storage Account and a Blob container. These resources store our Terraform state file. Try it here. Both resources provide information to connect our backend remotely.
To configure our backend remotely, there are many ways. Here it uses:
-
the environment variables, such as
ARM_ACCESS_KEY
in example.env; -
the Terraform variables (.tfvars), such as
resource_group_name
,storage_account_name
,key
,container_name
in example-backend-config.tfvars. These variables are to read/modify our Terraform state file on Azure.
The
ARM_ACCESS_KEY
is accessible in the Access keys menu on your Azure storage account. -
-
You need a container engine. This tutorial covers Podman and Docker, that will enable us to run Terraform in it.
If you already have resources in your infrastructure, consider importing them to your state.
git clone https://github.com/rorvts/terraform-azure-linux-scale-set.git
sudo docker run -it -v $PWD:/app -w /app --label terraform --env-file ./example.env --entrypoint "" hashicorp/terraform:light sh
If you belong to the Docker Group, you do not need the statement sudo
.
podman run -it -v $PWD:/app -w /app --label terraform --env-file ./example.env --entrypoint "" hashicorp/terraform:light sh
terraform init --backend-config=./example-backend-config.tfvars
terraform plan -var-file="example-secret.tfvars" -out=plan
terraform apply "plan"
terraform destroy "plan"
Note: If you had added a resource in your terraform state, it will be on the destroy command. Take careful!
- Fork this repository;
- Make a branch with your feature:
git checkout -b my-feature
; - Commit the changes:
git commit -m 'feat: My new feature'
; - Push to your branch:
git push origin my-feature
; - Open a pull request Pull Request.
- Author: Rodrigo Santos @rorsgo
This repository is under MIT LICENSE. For more information, read the LICENSE file.