Skip to content

Commit 1589fca

Browse files
authored
Merge pull request #6 from buildo/5-update-to-terraform-0.12
#5: Update to terraform 0.12
2 parents 9aa9c86 + ccdde42 commit 1589fca

File tree

5 files changed

+66
-61
lines changed

5 files changed

+66
-61
lines changed

main.tf

+22-20
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,35 @@ data "aws_ami" "ami" {
1414
}
1515

1616
resource "aws_instance" "instance" {
17-
ami = "${coalesce(var.ami, data.aws_ami.ami.image_id)}"
18-
instance_type = "${var.instance_type}"
19-
key_name = "${var.ssh_key_name}"
20-
security_groups = ["${aws_security_group.sg.name}"]
17+
ami = coalesce(var.ami, data.aws_ami.ami.image_id)
18+
instance_type = var.instance_type
19+
key_name = var.ssh_key_name
20+
security_groups = [aws_security_group.sg.name]
2121
associate_public_ip_address = true
22-
iam_instance_profile = "${var.iam_instance_profile}"
22+
iam_instance_profile = var.iam_instance_profile
2323

24-
tags {
25-
Name = "${var.project_name}"
24+
tags = {
25+
Name = var.project_name
2626
}
2727

2828
root_block_device {
29-
volume_size = "${var.volume_size}"
29+
volume_size = var.volume_size
3030
}
3131

3232
connection {
33+
host = coalesce(self.public_ip, self.private_ip)
34+
type = "ssh"
3335
user = "ubuntu"
34-
private_key = "${file("${var.ssh_private_key}")}"
36+
private_key = file(var.ssh_private_key)
3537
}
3638

3739
provisioner "file" {
38-
content = "${file("crane.yml")}"
40+
content = file("crane.yml")
3941
destination = "~/crane.yml"
4042
}
4143

4244
provisioner "file" {
43-
content = "${var.init_script}"
45+
content = var.init_script
4446
destination = "~/init.sh"
4547
}
4648

@@ -86,21 +88,21 @@ resource "aws_cloudwatch_metric_alarm" "disk-full" {
8688
namespace = "System/Linux"
8789
period = "60"
8890
statistic = "Average"
89-
threshold = "${var.disk_utilization_alarm_threshold}"
91+
threshold = var.disk_utilization_alarm_threshold
9092
alarm_description = "This metric monitors disk utilization"
91-
alarm_actions = ["${lookup(var.bellosguardo_sns_topic_arn, var.bellosguardo_target)}"]
92-
ok_actions = ["${lookup(var.bellosguardo_sns_topic_arn, var.bellosguardo_target)}"]
93+
alarm_actions = [var.bellosguardo_sns_topic_arn[var.bellosguardo_target]]
94+
ok_actions = [var.bellosguardo_sns_topic_arn[var.bellosguardo_target]]
9395
treat_missing_data = "breaching"
9496

95-
dimensions {
96-
InstanceId = "${aws_instance.instance.id}"
97+
dimensions = {
98+
InstanceId = aws_instance.instance.id
9799
MountPath = "/"
98100
Filesystem = "overlay"
99101
}
100102
}
101103

102104
variable "bellosguardo_sns_topic_arn" {
103-
type = "map"
105+
type = map(string)
104106

105107
default = {
106108
buildo = "arn:aws:sns:eu-west-1:309416224681:bellosguardo"
@@ -109,9 +111,9 @@ variable "bellosguardo_sns_topic_arn" {
109111
}
110112

111113
resource "aws_route53_record" "dns" {
112-
zone_id = "${var.zone_id}"
113-
name = "${var.host_name}"
114+
zone_id = var.zone_id
115+
name = var.host_name
114116
type = "A"
115117
ttl = "300"
116-
records = ["${aws_instance.instance.public_ip}"]
118+
records = [aws_instance.instance.public_ip]
117119
}

outputs.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ output "ssh_cmd" {
77
}
88

99
output "public_ip" {
10-
value = "${aws_instance.instance.public_ip}"
10+
value = aws_instance.instance.public_ip
1111
}
1212

security_group.tf

+23-24
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
resource "aws_security_group" "sg" {
2-
name = "${var.project_name}"
2+
name = var.project_name
33
}
44

55
resource "aws_security_group_rule" "ssh" {
6-
type = "ingress"
7-
protocol = "tcp"
8-
security_group_id = "${aws_security_group.sg.id}"
9-
from_port = 22
10-
to_port = 22
11-
cidr_blocks = "${var.in_cidr_blocks}"
6+
type = "ingress"
7+
protocol = "tcp"
8+
security_group_id = aws_security_group.sg.id
9+
from_port = 22
10+
to_port = 22
11+
cidr_blocks = var.in_cidr_blocks
1212
}
1313

1414
resource "aws_security_group_rule" "out_all" {
15-
type = "egress"
16-
protocol = -1
17-
security_group_id = "${aws_security_group.sg.id}"
18-
from_port = 0
19-
to_port = 0
20-
cidr_blocks = ["0.0.0.0/0"]
15+
type = "egress"
16+
protocol = -1
17+
security_group_id = aws_security_group.sg.id
18+
from_port = 0
19+
to_port = 0
20+
cidr_blocks = ["0.0.0.0/0"]
2121
}
2222

2323
resource "aws_security_group_rule" "custom_ports" {
24-
count = "${length(var.in_open_ports)}"
25-
type = "ingress"
26-
protocol = "tcp"
27-
security_group_id = "${aws_security_group.sg.id}"
28-
from_port = "${2 == length(split("-", element(var.in_open_ports, count.index))) ?
29-
element(split("-", element(var.in_open_ports, count.index)), 0) :
30-
element(var.in_open_ports, count.index) }"
31-
to_port = "${2 == length(split("-", element(var.in_open_ports, count.index))) ?
32-
element(split("-", element(var.in_open_ports, count.index)), 1) :
33-
element(var.in_open_ports, count.index) }"
34-
cidr_blocks = "${var.in_cidr_blocks}"
24+
count = length(var.in_open_ports)
25+
type = "ingress"
26+
protocol = "tcp"
27+
security_group_id = aws_security_group.sg.id
28+
from_port = 2 == length(split("-", element(var.in_open_ports, count.index))) ? element(split("-", element(var.in_open_ports, count.index)), 0) : element(var.in_open_ports, count.index)
29+
30+
to_port = 2 == length(split("-", element(var.in_open_ports, count.index))) ? element(split("-", element(var.in_open_ports, count.index)), 1) : element(var.in_open_ports, count.index)
31+
32+
cidr_blocks = var.in_cidr_blocks
3533
}
34+

variables.tf

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
variable project_name {
1+
variable "project_name" {
22
description = "Project name, used for namespacing things"
33
}
44

5-
variable instance_type {
5+
variable "instance_type" {
66
default = "t2.micro"
77
}
88

9-
variable ami {
9+
variable "ami" {
1010
description = "Custom AMI, if empty will use latest Ubuntu"
1111
default = ""
1212
}
1313

14-
variable volume_size {
14+
variable "volume_size" {
1515
description = "Volume size"
1616
default = 8
1717
}
1818

19-
variable ssh_private_key {
19+
variable "ssh_private_key" {
2020
description = "Used to connect to the instance once created"
2121
}
2222

23-
variable ssh_key_name {
23+
variable "ssh_key_name" {
2424
description = "Name of the key-pair on EC2 (aws-ireland, buildo-aws, ...)"
2525
}
2626

27-
variable zone_id {
27+
variable "zone_id" {
2828
description = "Route53 Zone ID"
2929
}
3030

31-
variable host_name {
31+
variable "host_name" {
3232
description = "DNS host name"
3333
}
3434

35-
variable quay_password {
35+
variable "quay_password" {
3636
description = "Quay password"
3737
}
3838

39-
variable init_script {
40-
description = "bash code executed before `crane lift` is called, example: `\"${file(\"init.sh\")}\"`"
39+
variable "init_script" {
40+
description = "bash code executed before `crane lift` is called, example: `\"$${file(\\\"init.sh\\\")}\"`"
4141
default = ""
4242
}
4343

44-
variable in_open_ports {
44+
variable "in_open_ports" {
4545
default = []
4646
}
4747

48-
variable in_cidr_blocks {
48+
variable "in_cidr_blocks" {
4949
default = ["0.0.0.0/0"]
5050
}
5151

52-
variable disk_utilization_alarm_threshold {
52+
variable "disk_utilization_alarm_threshold" {
5353
description = "disk occupation alarm threshold (% of disk utilization)"
5454
default = "80"
5555
}
5656

57-
variable bellosguardo_target {
57+
variable "bellosguardo_target" {
5858
description = "Possible values are 'buildo', 'omnilab'"
5959
}
6060

61-
variable iam_instance_profile {
61+
variable "iam_instance_profile" {
6262
default = ""
6363
}

versions.tf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
terraform {
3+
required_version = ">= 0.12"
4+
}

0 commit comments

Comments
 (0)