This repository has been archived by the owner on Mar 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
testing.tf
94 lines (80 loc) · 2.78 KB
/
testing.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
data "template_file" "chef_load_conf" {
template = "${file("./chef_load.conf.tpl")}"
vars {
chef_server_fqdn = "${aws_instance.chef_server.public_dns}"
automate_server_fqdn = "${aws_instance.chef_automate.public_dns}"
}
}
resource "aws_instance" "chef_load" {
connection {
user = "${var.aws_ami_user}"
private_key = "${file("${var.aws_key_pair_file}")}"
}
count = 0
ami = "${data.aws_ami.centos.id}"
instance_type = "${var.aws_instance_type}"
key_name = "${var.aws_key_pair_name}"
subnet_id = "${data.aws_subnet_ids.automate.ids[1]}"
vpc_security_group_ids = ["${aws_security_group.chef_automate.id}"]
associate_public_ip_address = true
ebs_optimized = true
root_block_device {
delete_on_termination = true
volume_size = 20
volume_type = "gp2"
#iops = 1000
}
ebs_block_device {
device_name = "/dev/sdb"
volume_type = "io1"
iops = 5000 # iops = volume_size * 50
volume_size = 100
delete_on_termination = true
}
tags {
Name = "${format("${var.tag_automate}_chef_load_%02d_${random_id.automate_instance_id.hex}", count.index + 1)}"
X-Dept = "${var.tag_dept}"
X-Contact = "${var.tag_contact}"
}
# Set hostname in separate connection.
# Transient hostname doesn't set correctly in time otherwise.
provisioner "remote-exec" {
inline = [
"sudo hostnamectl set-hostname ${aws_instance.chef_automate.public_dns}",
"sudo mkdir /etc/chef/",
]
}
# mount the EBS volume
provisioner "file" {
source = "mount_data_volume"
destination = "/tmp/mount_data_volume"
}
provisioner "file" {
content = "${data.template_file.delivery_validator.rendered}"
destination = "/home/centos/delivery-validator.pem"
}
provisioner "file" {
content = "${data.template_file.chef_load_conf.rendered}"
destination = "/home/centos/chef_load.conf"
}
provisioner "file" {
source = "./files/chef_load.service"
destination = "/tmp/chef_load.service"
}
provisioner "remote-exec" {
inline = [
"sudo mv /tmp/chef_load.service /etc/systemd/system/chef_load.service",
]
}
provisioner "remote-exec" {
inline = [
"sudo bash -ex /tmp/mount_data_volume",
"sudo yum install git -y",
"cd && git clone https://github.com/jeremiahsnapp/chef-load.git",
"wget https://github.com/chef/chef-load/releases/download/v1.0.0/chef-load_1.0.0_Linux_64bit -O chef-load-1.0.0",
"chmod +x chef-load-1.0.0",
"chmod 600 delivery-validator.pem",
"knife ssl fetch https://${aws_instance.chef_server.public_dns}",
]
}
}