1
1
data "aws_ami" "ami" {
2
2
most_recent = true
3
- owners = [" 099720109477" ]
3
+ owners = [" 099720109477" ]
4
+
4
5
filter {
5
- name = " name"
6
+ name = " name"
6
7
values = [" ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*" ]
7
8
}
9
+
8
10
filter {
9
- name = " virtualization-type"
11
+ name = " virtualization-type"
10
12
values = [" hvm" ]
11
13
}
12
14
}
13
15
14
16
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 } " ]
19
21
associate_public_ip_address = true
22
+ iam_instance_profile = " ${ var . iam_instance_profile } "
20
23
21
24
tags {
22
25
Name = " ${ var . project_name } "
@@ -27,28 +30,28 @@ resource "aws_instance" "instance" {
27
30
}
28
31
29
32
connection {
30
- user = " ubuntu"
33
+ user = " ubuntu"
31
34
private_key = " ${ file (" ${ var . ssh_private_key } " )} "
32
35
}
33
36
34
37
provisioner "file" {
35
- content = " ${ file (" crane.yml" )} "
38
+ content = " ${ file (" crane.yml" )} "
36
39
destination = " ~/crane.yml"
37
40
}
38
41
39
42
provisioner "file" {
40
- content = " ${ var . init_script } "
43
+ content = " ${ var . init_script } "
41
44
destination = " ~/init.sh"
42
45
}
43
46
44
47
provisioner "remote-exec" {
45
48
inline = [
46
- " mkdir -p ~/config"
49
+ " mkdir -p ~/config" ,
47
50
]
48
51
}
49
52
50
53
provisioner "file" {
51
- source = " ${ path . cwd } /config/"
54
+ source = " ${ path . cwd } /config/"
52
55
destination = " ~/config/"
53
56
}
54
57
@@ -61,7 +64,7 @@ resource "aws_instance" "instance" {
61
64
" sudo apt-get install -y docker-engine" ,
62
65
" sudo service docker start" ,
63
66
" 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" ,
65
68
]
66
69
}
67
70
@@ -70,43 +73,45 @@ resource "aws_instance" "instance" {
70
73
" docker login quay.io -u dontspamus -p ${ var . quay_password } " ,
71
74
" chmod +x ./init.sh" ,
72
75
" docker run -itd --restart always quay.io/buildo/bellosguardo:${ var . bellosguardo_target } " ,
73
- " ./init.sh"
76
+ " ./init.sh" ,
74
77
]
75
78
}
76
79
}
77
80
78
81
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
+
91
95
dimensions {
92
96
InstanceId = " ${ aws_instance . instance . id } "
93
- MountPath = " /"
97
+ MountPath = " /"
94
98
Filesystem = " overlay"
95
99
}
96
100
}
97
101
98
102
variable "bellosguardo_sns_topic_arn" {
99
103
type = " map"
104
+
100
105
default = {
101
- buildo = " arn:aws:sns:eu-west-1:309416224681:bellosguardo"
106
+ buildo = " arn:aws:sns:eu-west-1:309416224681:bellosguardo"
102
107
omnilab = " arn:aws:sns:eu-west-1:143727521720:bellosguardo"
103
108
}
104
109
}
105
110
106
111
resource "aws_route53_record" "dns" {
107
112
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"
111
116
records = [" ${ aws_instance . instance . public_ip } " ]
112
117
}
0 commit comments