Terraform & Devops
  • Home
  • TERRAFORM CERTIFCATION
  • AWS-CLOUD
  • GCP-CLOUD
  • ANSIBLE
  • KUBERNETES
  • Aboutus
  • Contact Us
No Result
View All Result
  • Home
  • TERRAFORM CERTIFCATION
  • AWS-CLOUD
  • GCP-CLOUD
  • ANSIBLE
  • KUBERNETES
  • Aboutus
  • Contact Us
No Result
View All Result
Terraform & Devops
No Result
View All Result
Home TERRAFORM CERTIFCATION

Local and dynamic blocks:

by abubakarsiddiq858
January 4, 2021
in TERRAFORM CERTIFCATION
154 7
0
Local and dynamic blocks:
184
SHARES
2.3k
VIEWS
Share on FacebookShare on Twitter

Local and dynamic blocks:

Local blocks:

If we need to use common values in repeated blocks then we go for local blocks.all the values can be declared in a block called  locals{}.

To use these values in source code  we can call them with local.tagname

In our example   we declared common tags as shown below

locals {
common_tags = {
users = "devteam"
}
}

Example usage:

provider "aws" {
region = "us-east-1"
access_key = ""
}
locals {
common_tags = {
users = "devteam"
}

}


resource aws_instance "myec2" {
ami = "ami-96fda3c22c1c990a"
instance_type = "t2.small"
tags = local.common_tags
}

resource aws_instance "myec3" {
ami = "ami-96fda3c22c1c990a"
instance_type = "t2.small"
tags = local.common_tags
}

Dyanmic blocks:

Dynamic blocks helps to reduce repetitive codes. In below example we have shown the inbound rule for various security groups.here we have used for_each  loop to pick the values from list .

provider "aws" {
region = "us-east-1"
access_key = ""
}
variable "ports" {
type = list
default = [22, 2049, 80]
}
resource aws_security_group "mysec" {
name = "prodsecgroups"
dynamic "ingress" {
for_each = var.ports
content {
from_port = ingress.value
to_port = ingress.value
protocol = "tcp"
cidr_blocks = ["10.0.0.0/16"]
}
}
}


Tags: BitcoinBusiness AnalysisOil MarketSillicon ValleyUnited StatedWall Street
  • Trending
  • Comments
  • Latest
Terraform – Modules

Terraform – Modules

January 4, 2021
Terraform Life cycle

Terraform Life cycle

January 4, 2021
Terraform – Functions

Terraform – Functions

January 4, 2021
Terraform installation

Terraform installation

January 4, 2021
Implementing VPC Architecture using Terraform

Implementing VPC Architecture using Terraform

0
Local and dynamic blocks:

Local and dynamic blocks:

0
Terraform  Provisioners

Terraform Provisioners

0
Managing Terraform States in Remote Locations:

Managing Terraform States in Remote Locations:

0
Implementing VPC Architecture using Terraform

Implementing VPC Architecture using Terraform

August 28, 2021
Build a CICD Pipeline with Git Jenkins Terraform

Build a CICD Pipeline with Git Jenkins Terraform

May 24, 2021

Configuring VPC Components in AWS

February 8, 2021

Introduction to AWS

February 7, 2021

Recent News

Implementing VPC Architecture using Terraform

Implementing VPC Architecture using Terraform

August 28, 2021
Build a CICD Pipeline with Git Jenkins Terraform

Build a CICD Pipeline with Git Jenkins Terraform

May 24, 2021

Categories

  • Uncategorized
  • AWS-CLOUD
  • TERRAFORM CERTIFCATION

Site Navigation

  • Home
  • Advertisement
  • Contact Us
  • Privacy & Policy
  • Other Links
Terraform & Devops

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Check our landing page for details.

No Result
View All Result
  • Home
  • TERRAFORM CERTIFCATION
  • AWS-CLOUD
  • GCP-CLOUD
  • ANSIBLE
  • KUBERNETES
  • Aboutus
  • Contact Us

© 2021 TheTerraform.in - All Rights Reserved.
Designed By TenXinfotech.

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist