forked from networknuts/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkspace-remote-backend.tf
62 lines (46 loc) · 980 Bytes
/
workspace-remote-backend.tf
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
61
62
# make sure the aws s3 bucket exist
# changing backend to s3
terraform {
backend "s3" {
region = "ap-south-1"
bucket = "networknuts-terra-states"
key = "state.tfstate"
encrypt = true #AES-256 encryption
}
}
# create terraform workspaces
# terraform workspace new prod
# terraform workspace new dev
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}"
}
}