jaffar shaik
1 min readJan 5, 2021

Terraform workspaces

Workspaces are how Terraform Cloud organizes infrastructure.
workspace commands in terraform
 terraform workspace show
“this command shows us the current workspace

 terraform workspace select workspacename
“this command helps to move to the particular workspace when we have multiple workspaces.

 terraform workspace new workspacename
this command helps to create a new workspace and
also we will be shifted to new created workspace terraform workspace list
this command lists the all workspaces present in our environment
Example usage:
In the below Example we have created default ,prod test and dev workspaces. Based on the workspace the instance type will be selected.

provider "aws" {
region = "us-east-1"
access_key = ""
secret_key = ""
}
variable "mappi" {
type = map
default = {
default = "t2.small"
prod = "t2.large"
test = "t2.medium"
dev = "t2.small"
}
}
resource aws_instance "myec3" {
ami = "ami-08f63db601b82ff5f"
instance_type = lookup(var.mappi, terraform.workspace)
}
jaffar shaik
jaffar shaik

Written by jaffar shaik

Am DevOps Engineer and SRE based in india.

No responses yet