Terraform

create main.tf

got to DOCS: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs

Providers : copy the script paste in visual studio

got to view–Terminal

execuete : terraform init

Got to

AD–App regtistration–create new registration.

copy: clientID: 

copy TenantID: 

copy subscription ID: 

AD–App registration-select created form–lefthand select certificates and secrets– create new client secret- copy teh secret ID

CLient Secret ID: hdkjhskjhfkjhshfds

provider “azurerm” {
features{}
# Configuration options
client_id= “”
tenant_id= “”
subscription_id= “”
client_secret= “”
}

execute

terraform validate
terraform plan
terraform apply

terrafrom.tfstate will be created.

//////////////////////////////////////////////////////////////////////////////////

How to cerate resourcegroup

got to DOCS : https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group

search bar — resourcegroup

resource “azurerm_resource_group” “example” {
name = “example”
location = “West Europe”
}

terraform validate
terraform plan
terraform apply –auto-approve

How to create virtual switch

resource “azurerm_resource_group” “Test1RG” {
name = “Test1”
location = “eastus”
}
resource “azurerm_resource_group” “Test2RG” {
name = “Test2”
location = “westus”
}
resource “azurerm_virtual_network” “test1vnet” {
name = “testvnet”
location = azurerm_resource_group.Test1RG.location
resource_group_name = azurerm_resource_group.Test1RG.name
address_space = [“10.10.0.0/16”]
# dns_servers = [“10.0.0.4”, “10.0.0.5”]klsajdlkjdslk

subnet {
name = “testsubnet1”
address_prefix = “10.10.1.0/24”
}

subnet {
name = “testsubnet2”
address_prefix = “10.10.2.0/24”
}

tags = {
environment = “test1”
createdby = “Ramu”
}

terraform validate
terraform plan
terraform apply –auto-approve

////////////////////////////////////////////////////////////////////////////////

Variables topic

variables are values

use of variables: hide the values ( like clinet id, locatin secret id etc)

create two files in visual studio.

1 variables.tf
2.variables.tfvars

keep the information in variables.tfvars like example below

client_id= “dd098941-1b04-40c5-ac3e-221310d5c75a”
tenant_id= “4b6f90b2-12cc-45f0-8527-da31b2259cca”
subscription_id= “7b43c9f5-2b23-42c6-a7bf-d8e1cf4af406”
client_secret= “JEh8Q~Apkczpsk4iFXVzPDn-OWM.MjFW-6kiaaE9”
location = “eastus”

keep the names ( clientid,loaction. tenant id) in variables.tf

variable “client_id”{}
variable “tenant_id”{}
variable “subscription_id”{}
variable “client_secret” {}
variable “location” {}

then keep the variable names in the main.tf file example below

provider “azurerm” {
features{}
# Configuration options
client_id= var.client_id
tenant_id= var.tenant_id
subscription_id= var.subscription_id
client_secret= var.client_secret
}

resource “azurerm_resource_group” “Test1RG” {
name = “Test1”
location = var.location
}

execuete command

terraform apply –var-file variables.tfvars

count is name
length is function

length(var.location)=== function

Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment