Skip to content

Commit 9aa9c86

Browse files
committed
Add instance profile
1 parent eb72db3 commit 9aa9c86

File tree

2 files changed

+44
-35
lines changed

2 files changed

+44
-35
lines changed

main.tf

+36-31
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
data "aws_ami" "ami" {
22
most_recent = true
3-
owners = ["099720109477"]
3+
owners = ["099720109477"]
4+
45
filter {
5-
name = "name"
6+
name = "name"
67
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
78
}
9+
810
filter {
9-
name = "virtualization-type"
11+
name = "virtualization-type"
1012
values = ["hvm"]
1113
}
1214
}
1315

1416
resource "aws_instance" "instance" {
15-
ami = "${coalesce(var.ami, data.aws_ami.ami.image_id)}"
16-
instance_type = "${var.instance_type}"
17-
key_name = "${var.ssh_key_name}"
18-
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}"]
1921
associate_public_ip_address = true
22+
iam_instance_profile = "${var.iam_instance_profile}"
2023

2124
tags {
2225
Name = "${var.project_name}"
@@ -27,28 +30,28 @@ resource "aws_instance" "instance" {
2730
}
2831

2932
connection {
30-
user = "ubuntu"
33+
user = "ubuntu"
3134
private_key = "${file("${var.ssh_private_key}")}"
3235
}
3336

3437
provisioner "file" {
35-
content = "${file("crane.yml")}"
38+
content = "${file("crane.yml")}"
3639
destination = "~/crane.yml"
3740
}
3841

3942
provisioner "file" {
40-
content = "${var.init_script}"
43+
content = "${var.init_script}"
4144
destination = "~/init.sh"
4245
}
4346

4447
provisioner "remote-exec" {
4548
inline = [
46-
"mkdir -p ~/config"
49+
"mkdir -p ~/config",
4750
]
4851
}
4952

5053
provisioner "file" {
51-
source = "${path.cwd}/config/"
54+
source = "${path.cwd}/config/"
5255
destination = "~/config/"
5356
}
5457

@@ -61,7 +64,7 @@ resource "aws_instance" "instance" {
6164
"sudo apt-get install -y docker-engine",
6265
"sudo service docker start",
6366
"sudo usermod -aG docker $USER",
64-
"bash -c \"`curl -sL https://raw.githubusercontent.com/michaelsauter/crane/v2.9.0/download.sh`\" && sudo mv crane /usr/local/bin/crane"
67+
"bash -c \"`curl -sL https://raw.githubusercontent.com/michaelsauter/crane/v2.9.0/download.sh`\" && sudo mv crane /usr/local/bin/crane",
6568
]
6669
}
6770

@@ -70,43 +73,45 @@ resource "aws_instance" "instance" {
7073
"docker login quay.io -u dontspamus -p ${var.quay_password}",
7174
"chmod +x ./init.sh",
7275
"docker run -itd --restart always quay.io/buildo/bellosguardo:${var.bellosguardo_target}",
73-
"./init.sh"
76+
"./init.sh",
7477
]
7578
}
7679
}
7780

7881
resource "aws_cloudwatch_metric_alarm" "disk-full" {
79-
alarm_name = "${var.project_name}-${aws_instance.instance.id}-disk-full"
80-
comparison_operator = "GreaterThanOrEqualToThreshold"
81-
evaluation_periods = "3"
82-
metric_name = "DiskSpaceUtilization"
83-
namespace = "System/Linux"
84-
period = "60"
85-
statistic = "Average"
86-
threshold = "${var.disk_utilization_alarm_threshold}"
87-
alarm_description = "This metric monitors disk utilization"
88-
alarm_actions = ["${lookup(var.bellosguardo_sns_topic_arn, var.bellosguardo_target)}"]
89-
ok_actions = ["${lookup(var.bellosguardo_sns_topic_arn, var.bellosguardo_target)}"]
90-
treat_missing_data = "breaching"
82+
alarm_name = "${var.project_name}-${aws_instance.instance.id}-disk-full"
83+
comparison_operator = "GreaterThanOrEqualToThreshold"
84+
evaluation_periods = "3"
85+
metric_name = "DiskSpaceUtilization"
86+
namespace = "System/Linux"
87+
period = "60"
88+
statistic = "Average"
89+
threshold = "${var.disk_utilization_alarm_threshold}"
90+
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+
treat_missing_data = "breaching"
94+
9195
dimensions {
9296
InstanceId = "${aws_instance.instance.id}"
93-
MountPath = "/"
97+
MountPath = "/"
9498
Filesystem = "overlay"
9599
}
96100
}
97101

98102
variable "bellosguardo_sns_topic_arn" {
99103
type = "map"
104+
100105
default = {
101-
buildo = "arn:aws:sns:eu-west-1:309416224681:bellosguardo"
106+
buildo = "arn:aws:sns:eu-west-1:309416224681:bellosguardo"
102107
omnilab = "arn:aws:sns:eu-west-1:143727521720:bellosguardo"
103108
}
104109
}
105110

106111
resource "aws_route53_record" "dns" {
107112
zone_id = "${var.zone_id}"
108-
name = "${var.host_name}"
109-
type = "A"
110-
ttl = "300"
113+
name = "${var.host_name}"
114+
type = "A"
115+
ttl = "300"
111116
records = ["${aws_instance.instance.public_ip}"]
112117
}

variables.tf

+8-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ variable instance_type {
88

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

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

1919
variable ssh_private_key {
@@ -38,7 +38,7 @@ variable quay_password {
3838

3939
variable init_script {
4040
description = "bash code executed before `crane lift` is called, example: `\"${file(\"init.sh\")}\"`"
41-
default = ""
41+
default = ""
4242
}
4343
4444
variable in_open_ports {
@@ -51,9 +51,13 @@ variable in_cidr_blocks {
5151
5252
variable disk_utilization_alarm_threshold {
5353
description = "disk occupation alarm threshold (% of disk utilization)"
54-
default = "80"
54+
default = "80"
5555
}
5656
5757
variable bellosguardo_target {
5858
description = "Possible values are 'buildo', 'omnilab'"
5959
}
60+
61+
variable iam_instance_profile {
62+
default = ""
63+
}

0 commit comments

Comments
 (0)