-
Notifications
You must be signed in to change notification settings - Fork 4
/
ec2-launch-configuration.tf
61 lines (49 loc) · 1.76 KB
/
ec2-launch-configuration.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
data "template_file" "tpl_nexus-ecs-config" {
template = "${file("${path.module}/custom/ecs.config")}"
vars = {
cluster-name = "${var.cluster-name}"
}
}
data "template_file" "tpl_nexus-cloud-config" {
template = "${file("${path.module}/custom/cloudinit.sh")}"
vars = {
bucket-name = "${aws_s3_bucket.s3_nexus.id}"
efs-id = "${aws_efs_file_system.efs_nexus.id}"
}
}
resource "tls_private_key" "kp-create_nexus" {
algorithm = "RSA"
provisioner "local-exec" {
command = "echo '${tls_private_key.kp-create_nexus.private_key_pem}' > ${path.cwd}/outputs/kp_nexus"
}
}
resource "aws_iam_instance_profile" "iam-ins-profile_nexus" {
name = "iam-ins-profile_nexus"
role = "${aws_iam_role.iam_nexus-ec2-role.id}"
}
resource "aws_key_pair" "kp_nexus" {
key_name = "kp_nexus"
public_key = "${tls_private_key.kp-create_nexus.public_key_openssh}"
depends_on = ["tls_private_key.kp-create_nexus"]
}
resource "random_id" "bucket-name" {
byte_length = 12
prefix = "${var.bucket-name-prefix}"
}
resource "aws_s3_bucket" "s3_nexus" {
bucket = "${random_id.bucket-name.hex}"
}
resource "aws_s3_bucket_object" "s3_nexus-object" {
bucket = "${aws_s3_bucket.s3_nexus.id}"
key = "ecs.config"
content = "${data.template_file.tpl_nexus-ecs-config.rendered}"
}
resource "aws_launch_configuration" "launch-config_nexus" {
name = "launch-config_nexus"
image_id = "${var.ami}"
instance_type = "${var.instance-type}"
key_name = "${aws_key_pair.kp_nexus.key_name}"
user_data = "${data.template_file.tpl_nexus-cloud-config.rendered}"
iam_instance_profile = "${aws_iam_instance_profile.iam-ins-profile_nexus.id}"
security_groups = ["${aws_security_group.sg-ec2_nexus.id}"]
}