This Terraform project creates an Azure Resource Group using a simple and modular structure. It is designed to be used with Windows, PowerShell, and Visual Studio Code.
- Install Azure CLI on your machine.
- Install Terraform on your machine.
- Install Visual Studio Code on your machine.
- Install the Terraform extension for Visual Studio Code.
modules/
: Contains reusable Terraform modules.
Setup
-
Clone the repository to your local machine.
-
Open the project in Visual Studio Code or your preferred editor.
-
In the terminal, navigate to the project root directory.
-
Run the
setup_backend.ps1
script to set up the Terraform backend in Azure. This script will prompt you to input required information for your backend configuration. If the backend.sensitive.tfvars file does not exist, it will be created with the provided information: -
The setup_backend.ps1 script will generate a backend.tf file with the necessary configurations for the Terraform backend.
-
Review and modify the variable values in prod.tfvars and backend.sensitive.tfvars files as needed. Make sure these files contain the correct values for your environment and resources. Keep sensitive information like secrets and API keys in the backend.sensitive.tfvars file, and use prod.tfvars for other variables.
- To create a new workspace for your environment, run:
terraform workspace new <workspace_name>
Replace <workspace_name>
with a name for your environment, such as "dev", "staging", or "prod".
- To switch between workspaces, run:
terraform workspace select <workspace_name>
Replace <workspace_name>
with the name of the workspace you want to switch to.
- Initialize the Terraform working directory:
terraform init
- (Optional) Format your Terraform files to ensure they follow the standard formatting conventions:
terraform fmt
- (Optional) Validate the Terraform configuration files for any errors:
terraform validate
- (Optional) Generate an execution plan to preview the changes that will be made to your infrastructure:
terraform plan -var-file="prod.tfvars"
- To create a resource group, update the values in
prod.tfvars
andbackend.sensitive.tfvars
, then run:
terraform apply -var-file="prod.tfvars"
- To destroy a resource group, run:
terraform destroy -var-file="prod.tfvars"
To create or modify Terraform modules, update the files in the modules/
directory.
Please make sure to test your changes in an isolated environment before pushing them to the repository.