Skip to content

Commit 96c76e6

Browse files
authored
Some infra changes to Terraform (#315)
- Edge server moved to much more lightweight VM - Amazon Linux version update - Expire EC2 instances after 3 days
1 parent 7f0e101 commit 96c76e6

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

environment/aws/main.tf

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ data "aws_security_group" "main" {
3939
# This is the machine(s) that will run Couchbase Server
4040
resource "aws_instance" "couchbaseserver" {
4141
count = var.server_count
42-
ami = "ami-05576a079321f21f8"
42+
ami = "ami-0cae6d6fe6048ca2c"
4343
instance_type = "m5.xlarge"
4444
key_name = var.key_name
4545

@@ -55,13 +55,18 @@ resource "aws_instance" "couchbaseserver" {
5555
tags = {
5656
Name = "cbs"
5757
Type = "couchbaseserver"
58+
ExpireAt = local.expire_at
59+
}
60+
61+
lifecycle {
62+
ignore_changes = [ tags["ExpireAt"] ]
5863
}
5964
}
6065

6166
# And the machine(s) that will run Sync Gateway
6267
resource "aws_instance" "sync_gateway" {
6368
count = var.sgw_count
64-
ami = "ami-05576a079321f21f8"
69+
ami = "ami-0cae6d6fe6048ca2c"
6570
instance_type = "m5.xlarge"
6671
key_name = var.key_name
6772

@@ -77,14 +82,19 @@ resource "aws_instance" "sync_gateway" {
7782
tags = {
7883
Name = "sg"
7984
Type = "syncgateway"
85+
ExpireAt = local.expire_at
86+
}
87+
88+
lifecycle {
89+
ignore_changes = [ tags["ExpireAt"] ]
8090
}
8191
}
8292

8393
# And the machine(s) that will run Edge Server
8494
resource "aws_instance" "edge_server" {
8595
count = var.es_count
86-
ami = "ami-05576a079321f21f8"
87-
instance_type = "m5.large"
96+
ami = "ami-0cae6d6fe6048ca2c"
97+
instance_type = "t3.micro"
8898
key_name = var.key_name
8999

90100
subnet_id = data.aws_subnet.main.id
@@ -94,13 +104,18 @@ resource "aws_instance" "edge_server" {
94104
tags = {
95105
Name = "es"
96106
Type = "edgeserver"
107+
ExpireAt = local.expire_at
108+
}
109+
110+
lifecycle {
111+
ignore_changes = [ tags["ExpireAt"] ]
97112
}
98113
}
99114

100115
# And the machine(s) that will run load balancers
101116
resource "aws_instance" "load_balancer" {
102117
count = var.lb_count
103-
ami = "ami-05576a079321f21f8"
118+
ami = "ami-0cae6d6fe6048ca2c"
104119
instance_type = "m5.large"
105120
key_name = var.key_name
106121

@@ -111,13 +126,18 @@ resource "aws_instance" "load_balancer" {
111126
tags = {
112127
Name = "lb"
113128
Type = "loadbalancer"
129+
ExpireAt = local.expire_at
130+
}
131+
132+
lifecycle {
133+
ignore_changes = [ tags["ExpireAt"] ]
114134
}
115135
}
116136

117137
# And the machine that will run LogSlurp
118138
resource "aws_instance" "log_slurp" {
119139
for_each = var.logslurp ? { "log_slurp": 1 } : {}
120-
ami = "ami-05576a079321f21f8"
140+
ami = "ami-0cae6d6fe6048ca2c"
121141
instance_type = "m5.large"
122142
key_name = var.key_name
123143

@@ -128,9 +148,21 @@ resource "aws_instance" "log_slurp" {
128148
tags = {
129149
Name = "ls"
130150
Type = "logslurp"
151+
ExpireAt = local.expire_at
152+
}
153+
154+
lifecycle {
155+
ignore_changes = [ tags["ExpireAt"] ]
131156
}
132157
}
133158

159+
locals {
160+
expire_at = formatdate(
161+
"YYYY-MM-DD'T'hh:mm:ss'Z'",
162+
timeadd(timestamp(), format("%dh", 3 * 24))
163+
)
164+
}
165+
134166
# This is a variable that needs to be specified and it specifies
135167
# the name (in AWS) of the public key that will be allowed SSH access
136168
variable "key_name" {

0 commit comments

Comments
 (0)