forked from sanjayguruji/terra-code
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwork-space.tf
More file actions
60 lines (45 loc) · 1.11 KB
/
work-space.tf
File metadata and controls
60 lines (45 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
provider "aws" {
region="ap-south-1"
}
locals {
env="${terraform.workspace}"
counts = {
"default"=1
"prod"=3
"dev"=2
}
instances = {
"default"="t2.micro"
"prod"="t2.small"
"dev"="t2.micro"
}
tags = {
"default"="webserver-def"
"prod"="webserver-prod"
"dev"="webserver-dev"
}
instance_type="${lookup(local.instances,local.env)}"
count="${lookup(local.counts,local.env)}"
mytag="${lookup(local.tags,local.env)}"
}
resource "aws_instance" "my_work" {
ami="ami-0447a12f28fddb066"
instance_type="${local.instance_type}"
count="${local.count}"
tags = {
Name="${local.mytag}"
}
}
#Create two workspaces - dev and prod
#terraform workspace new dev
#terraform workspace new prod
#Switch to a workspace
#terraform workspace select <workspace-name>
#List all workspaces
#terraform workspace list
#Delete a workspace
#terraform workspace delete <workspace-name>
#
#The advantage of using locals instead of variables is that locals can have
#logic inside them, instead of in the resource. Whereas variables only allows
#values and push the logic inside the resource.