This repository provides an example of using Terraform to provision infrastructure in Azure. The example is meant to serve as a template for people who are new to Terraform or looking for a simple example to get started with.
To use this example, you need to have the following installed:
- Terraform CLI
- Azure CLI
- An Azure account with a working subscription
- Clone the repository
git clone https://github.com/Botvinnik94/terraform-example.git
- Authenticate to Azure CLI
az login
- Navigate to the repository directory
cd terraform-example/terraform
-
Check and modify the configuration files if necessary:
main.tf
contains the infrastructure definition.variables.tf
contains the variables used in the infrastructure definition.vars/<env>.tfvars
contains the actual variable value for each environment.
-
Ensure that you have created the following resources in Azure (you can change the naming by modifying the backend names in
main.tf
):- Resource Group with the name
botvinnik-tf-rg
- Storage Account within that Resource group with the name
botvinniktfstac
- Container within that Storage Account with the name
botvinnik-tf-cont
- Resource Group with the name
-
Initialize Terraform
terraform init
- Plan the Terraform execution with the variable file for the target environment
terraform plan -var-file=vars/<env>.tfvars
- Apply the Terraform execution
terraform apply -var-file=vars/<env>.tfvars
To destroy the resources created by Terraform, run:
terraform destroy