Saturday, February 11, 2023

TERRAFORM META-ARGUMENT



Meta-Argument : This helps Engineers to create resources across multi-region and multiple cloud environment using the resources block which is the terraform provider meta argument. 

For Example: 
To create 20 resource at a time : One can use LOOPING OR COUNT in terraform to achieve that work flow. 

Provider Config file  : Inside of the provider config file, you define an ALIAS OF THE NEW VALUE which is giving to every provider config. 

An Alias : Is a unique item that specify a reference to a resource. Each time you reference the logical name in terraform, you are calling out the "LOCAL NAME "

For Example:
Provider argument such as "ALIAS" requires one to target where the region or another cloud provider and calling it out or pulling it.
                                        

                            DEPENDS_ON

Terraform has a feature that identifies its dependency. This is a meta-argument that explicitly defines the dependency, meaning, terraform can actually know the sequence in which the dependent resource needs and provision it.  Below are the steps taken to achieve this:
      Depends_on is used on those resources that depends on other resources that terraform cannot automatically infer like VPC. 

STEP 1: 
Create a folder for example call depends_on

STEP 2:
Create a file inside the folder  for example call it provider.tf
terraform {
required_version = "1.3.4"
required_providers {

aws = {
source = "hashicorp/aws"
version = "4.39.0"
}
}
}

provider "aws" {
region = "us-east-1"
profile= "default"
}


STEP 3: 
Create a file for example call it ec2.tf
resource "aws_instance" "Development-VM" {
ami = "ami-0b0d****867f****3"
instance_type = "t3.micro"
#count = 3 # create three similar EC2 instances

tags = {
Name = "Dev-VM"
}
}


STEP 4: 
Create a file inside the folder for example call it "eip.tf"(elastic IP ). To note, here I used Development-VM (dev-eip) as the environment.
resource "aws_eip" "dev-eip" {
instance =aws_instance.Development-VM
vpc = true
depends_on = [
aws_instance.Development-VM
]
}

                                   COUNT
Another Meta Argument is Count, which is a parameter use in creating multiple resources block which is specified in the block. Below are the steps taken to achieve this:

STEP 1: 
Create a  folder  for example call count

STEP 2:
Create a file inside folder example call provider.tf 
terraform {
required_version = "1.3.4"
required_providers {

aws = {
source = "hashicorp/aws"
version = "4.39.0"
}
}
}

provider "aws" {
region = "us-east-1"
profile= "default"
}


STEP 3: 
Create a file inside the folder for example call ec2.tf.
resource "aws_instance" "specify your environment name" {
ami = "ami-0b*******f052a63"
instance_type = "t3.micro"
count = 3 # create three similar EC2 instances

tags = {
Name = "specify your environment name"
}
}

                        MULTIPLE-PROVIDER
Using multiple providers can be useful if one need to manage resources from different providers in a single project. 

The example shows different providers to provision instance across AWS and AZURE environments. 

STEP 1 : 
Create a folder for example call multiple-provider. 

STEP 2 :
Create a file inside the folder for example call provider.tf. 
terraform {
required_version = "1.3.4"
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.39.0"
}
azurerm = {
source = "hashicorp/azurerm"
version = "2.47.0"
        }
    }
}



STEP 3:
Create a file inside the folder for example called instance-VM.tf for AWS (ec2 instance) as well as Azure (Virtual Machine -VM).

# AWS instance Block
resource "aws_instance" "specify your environment name" {
ami = "ami-0b0dc***7f05**2a63"
instance_type = "t3.micro"
tags = {
Name = "specify your environment name"
}
}

# AZURE Virtual Machine (VM) Block
resource "azurerm_virtual_machine" {
name = specify your environment name""
location = azurerm_resource vm_size = "Standard_D2s_v3"
}

STEP 4 : 
"cd" into the path 

STEP 5 :
Run the terraform commands
-Init
-Validate
-plan
-apply
-destroy


NB: In our next slide, we will talk about terraform provisioners. 

                   Prof Mbandi : https://github.com/awanmbandi/Terraform-1

No comments:

Post a Comment

CONFIGURING A PHISHING CAMPAIGN IN MICROSOFT DEFENDER.

Configuring a phishing campaign in Microsoft Defender (specifically Microsoft Defender for Office 365) involves creating a simulated attack ...