0% found this document useful (0 votes)
3 views6 pages

Using Variables in TF

How to use TF variables.

Uploaded by

FreeMantle8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Using Variables in TF

How to use TF variables.

Uploaded by

FreeMantle8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Terraform: Variables in Conf File

Terraform : Deployment Automation

➤ Single Place Configuration is not a Good Idea.


➤ Use Variable to Manage the Secrets.
➤ No Need to push AWS creds in Git Repo
➤ User Variable for Dynamic Elements like AMI
➤ Variable Makes files flexible and env independent.
Terraform : Deployment Automation

➤ createInstance.tf -

provider "aws" {
access_key = "AKIASMSIZOF4QD2NTPB6"
secret_key = "SECRET_KEY_HERE"
region = "us-east-2"
}

resource "aws_instance" "MyFirstInstnace" {


count =3
ami = "ami-05692172625678b4e"
instance_type = "t2.micro"

tags = {
Name = "demoinstnce-${count.index}"
}
}
Terraform : Deployment Automation

➤ provider.tf -
provider "aws" {
access_key = "AKIASMSIZOF4QD2NTPB6"
secret_key = "SECRET_KEY_HERE"
region = "us-east-2"
}

provider "aws" {
access_key = “${var.AWS_ACCESS_KEY}”
secret_key = “${var.AWS_SECRET_KEY}”
region = “${var.AWS_REGION}”
}

➤ vars.tf -
variable “AWS_ACCESS_KEY” {}
variable “AWS_SECRET_KEY” {}
variable “AWS_REGION” {
default = “us-east-2”
}
Terraform : Deployment Automation

➤ terraform.tfvars -
AWS_ACCESS_KEY = “”
AWS_SECRET_KEY = “”
AWS_REGION = “”

➤ createInstance.tf -

resource "aws_instance" "MyFirstInstnace" {


ami = "ami-05692172625678b4e"
instance_type = "t2.micro"
}
Will see you in Next Lecture…

See you in next lecture …

You might also like