Skip to content

rorsgo/terraform-azure-linux-scale-set

Repository files navigation

Linux Scale Set Example

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.


Prerequisites

  • You need to have a Service Principal - it gives you a CLIENT_ID and CLIENT_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:

    1. the environment variables, such as ARM_ACCESS_KEY in example.env;

    2. 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.


Getting Started

Clone the project


git clone https://github.com/rorvts/terraform-azure-linux-scale-set.git

Create the Container Environment

Building a container environment to start the Terraform project


Docker

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

podman run -it -v $PWD:/app -w /app --label terraform --env-file ./example.env --entrypoint "" hashicorp/terraform:light sh

Configure Terraform in the container


Initialize Terraform with your remote state configuration (example-backend-config.tfvars)


terraform init --backend-config=./example-backend-config.tfvars

Generate the Terraform plan


terraform plan -var-file="example-secret.tfvars" -out=plan

Apply the Terraform plan


terraform apply "plan"

Destroy the infrastructure created


terraform destroy "plan"

Note: If you had added a resource in your terraform state, it will be on the destroy command. Take careful!


Contribute

  • 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.

Credits


License

This repository is under MIT LICENSE. For more information, read the LICENSE file.

About

Build a Linux scale set on Azure using Containers and Terraform.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published