This project demonstrates the deployment of an Azure Resource Group using Terraform. It includes a PowerShell script to run terraform deployment and destroy process commands and a GNU General Public License.
Ensure the following are installed:
- Terraform: Download and install from terraform.io.
- Azure CLI: Download and install from docs.microsoft.com.
- Git: Download and install from git-scm.com.
- PowerShell: Available by default on Windows; for other operating systems, download from Microsoft.
Note: IDE use is Visual Studio Code.
azure-deployment-terraform/
│
├── .gitignore
├── LICENSE.md
├── README.md
├── Script.ps1
├── main.tf
├── outputs.tf
├── terraform.tfvars
└── variables.tf
This file defines the input variables used in the Terraform configuration.
The value of the variables are provided from terraform.tfvars
.
variable "azurerm_resource_group" {
description = "The name of the resource group"
}
variable "azurerm_location" {
description = "The Azure region in which resources will be provisioned"
}
This file defines the provider and the resource group to be created.
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=3.0.0"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "RGDeployment-Test" {
name = var.azurerm_resource_group
location = var.azurerm_location
tags = var.tags
}
- terraform block: Specifies the required provider
(AzureRM)
and its version. - provider "azurerm": Configures the AzureRM provider.
- resource "azurerm_resource_group" "RGDeployment-Test": Defines the Azure Resource Group resource with its name, location and tags. The tags are created for easy identification and cost analysis purpose.
This file defines the outputs for the Terraform configuration.
output "resource_group_name" {
value = "The name of the provisioned resource group is: ${azurerm_resource_group.RGDeployment-Test.name}"
}
-
Initialize Git Repository: Refer to my detailed steps Guide. Alternatively, you may clone my crafted
how-to-git guide
.git clone https://github.com/RScrafted/guide-how-to-git.git cd guide-how-to-git
-
Configure Azure CLI: Ensure you are logged in to Azure CLI and set the appropriate subscription:
az login az account set --subscription "your-subscription-id"
-
Run the commands from PowerShell Script (using F8 shourcut): The provided
Script.ps1
provides the Terraform commands in sequential process. Open PowerShell and navigate to the project directory, then run each one by one:The script will:
- Initialize the Terraform working directory.
- Validate the configuration.
- Create a plan for the deployment.
- Apply the plan (provisioning the resources).
- Validate the output by showing the resource group details.
- Optionally, destroy the resources to clean up.
To destroy the resources and clean up your environment, use the terraform destroy
command. The Script.ps1
also includes this step at the end:
terraform destroy
I aim to enhance by adding additional resources into the deployment and automate them. Future enhancements may include:
- Adding
virtual networks
,subnets
, andnetwork interfaces
. - Provisioning
virtual machines
with specified configurations. - Implementing advanced networking features such as
network security groups
andload balancers
. - Implement backup strategy to backup
.tfstate
.
- Potential enhancements In progress - Please visit my terraform-azure-vm-automation repository.
- I am working to optimize and automate the IaC using CI/CD
Feel free to fork this repository and submit pull requests. For major changes, please open an issue first to discuss what you would like to change. I have started a discussion, and everyone can bring ideas there.
- Terraform Documentation
- Azure Documentation
- PowerShell: PowerShell file used to centralize terraform commands related to this project.
- GitHub: Platform for version control and collaboration.