How to create a module for Resource group using Terraform - Part - 2
Using Terraform with Azure and create a module for Resource Group using Terraform
Its part -1 link
https://terraformwithkushagra.blogspot.com/2020/04/how-to-create-resource-in-azure-using.html
https://terraformwithkushagra.blogspot.com/2020/04/how-to-create-resource-in-azure-using.html
How to create a module for Resource group using Terraform ======================================================= -- Create a module folder in the working directory and create a subfolder resourcegroup subfolder inside module folder
Create 3 Files A.resource_group.tf =================== resource "azurerm_resource_group" "resource_group"{ name = var.resourcegroup location = var.location tags = var.tagging } B.variable.tf ==============
variable "resourcegroup" { type =string } variable "location" { type =string } variable "tagging" { type = map }
C.output.tf ========= output "azurerm_resource_group_tags" { description = "the tags provided for the resource group" value = "${azurerm_resource_group.resource_group.tags}" } output "azurerm_resource_group_name" { description = "name of the resource group provisioned" value = "${azurerm_resource_group.resource_group.name}" } output "azurerm_resource_group_location" { description = "name of the resource group provisioned" value = "${azurerm_resource_group.resource_group.location}" } How to call a module and create a resource group using Terraform create a folder named "training" in a working folder and go to the training Folder Create a file named --resourcegroup.tf --variable.tf and copy previously created backend.tf,version.tf into this folder. resourcegroup.tf ================== module "trainingrg" { source= ../modules/resourcegroup resourcegroup = var.resourcegroup location = var.location tagging = var.tags } variable.tf ============== variable "tags"{ type = map default={ Environment = "Development" Dept = "training" } } variable "resourcegroup"{ type=string default="rak-eastus-training-rg" } variable "location"{ type=string default="eastus" }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From Visual studio code terminal
run
terraform init -backend-config="access_key=$(az storage account keys list --resource-group "terraform-rg" --account-name "stgstoragefortf" --query '[0].value' -o tsv)"
Then Run
terraform plan
terraform apply
You will find a resource group got created with name "rak-eastus-training-rg"
This comment has been removed by the author.
ReplyDelete