
In this example, the instance_name
variable is defined with a type of string
, and it is given a default value of "my-instance"
. The AWS provider is then configured to use the us-west-2
region.
The aws_instance
resource is used to launch Amazon EC2 instances. The tags
argument is used to assign a name tag to the instance, and it is set to the value of the instance_name
variable.
You can change the value of instance_name
by modifying the default value in the variable definition, or you can specify a different value when you run Terraform by using the -var
flag. For example, if you want to launch an instance with the name "my-other-instance"
, you can run the following command:
variable "instance_name" { | |
type = string | |
default = "my-instance" | |
} | |
provider "aws" { | |
region = "us-west-2" | |
} | |
resource "aws_instance" "example" { | |
ami = "ami-0c55b159cbfafe1f0" | |
instance_type = "t2.micro" | |
tags = { | |
Name = var.instance_name | |
} | |
} |
$ terraform apply -var ‘instance_name=”my-other-instance”‘
provider "github" { | |
token = "" | |
organization = "devopsschool-sample-projects" | |
} | |
variable "reponame" { | |
type = string | |
description = "This is for demo of string variable" | |
default = "day3-broad" | |
} | |
resource "github_repository" "example" { | |
name = "${var.reponame}" | |
description = "My awesome codebase" | |
private = false | |
} |










I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND