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

Alias and Data sources in Terraform

by abubakarsiddiq858
January 4, 2021
in TERRAFORM CERTIFCATION
156 10
0
Alias and Data sources in Terraform
190
SHARES
2.4k
VIEWS
Share on FacebookShare on Twitter

Alias and Data sources in Terraform

Alias:
What if I need to launch my resources in multiple regions within a single configuration file then Alias variable does this functionality.
In the below example we have declared
alias = “pillows” in one provider block.
we can call this variable to refer to a resource other than a default region with the following syntax
provider = providername. aliasvariablename
In our case alias variable is “pillows” and provider is aws so therefore we can write it as provider =pillows.aws


Provider"aws" {
region = "us-east-1"
access_key = "
}
provider "aws" {
region = "ap-south-1"
access_key = "
alias = "pillows"
}
resource aws_instance "myec2" {
ami = "ami-96fda3c22c1c990a"
instance_type = "t2.small"
tags = {
name = "devservers"
}
}
resource aws_instance "myec3" {
ami = "ami-08f63db601b82ff5f"
instance_type = "t2.medium"
provider = aws.pillows
tags = {
name = "prodservers"
}
}

 

Data sources :
Data sources allow data to be fetched or computed for use elsewhere in Terraform configuration. Use of data sources allows a Terraform configuration to make use of information defined outside of Terraform, or defined by another separate Terraform configuration.
Syntax for Data source:
The syntax for data source starts with keyword Data fallowed by data source name.
Data “datasourcename” “nayname”
Example:
In the below example we are fetching ami id dynamically using aws_ami data source.
under the code if we need to call the ami the syntax is :
ami = data.datsourcename.resourcename.attributename
in our example it is ami = data.aws_ami.myec2.id

provider "aws" {
access_key = ""
secret_key = "qZY "
region = "us-east-1"
}
data "aws_ami" "myec2" {
most_recent = true
owners = ["amazon"]
filter {
values = ["redhat8-ami-hvm*"]
name = "name"
}
}
resource "aws_instance" "myec2" {
ami = data.aws_ami.myec2.id
instance_type = "t2.large"
}
Tags: BitcoinBusiness AnalysisBusiness TipsMarket StoriesOil MarketUnited Stated
  • 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