-
Notifications
You must be signed in to change notification settings - Fork 0
/
Instance.tf
140 lines (116 loc) · 3.56 KB
/
Instance.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
data template_file "getssl_cfg" {
template = "${file("${path.module}/files/getssl.cfg")}"
vars {
email = "${var.getssl_email}"
san_list = "${var.san_list}"
fqdn = "${lower(var.fqdn)}"
ca = "${var.prod_ca ? local.prod_ca : local.stage_ca}"
}
}
data "template_file" "ChefServer_setup_script" {
template = "${file("${path.module}/files/ChefServer.setup.sh")}"
vars {
fqdn = "${lower(var.fqdn)}"
admin_user = "${var.admin_user}"
admin_fn = "${var.admin_firstname}"
admin_ln = "${var.admin_lastname}"
admin_email = "${var.admin_email}"
org = "${lower(var.chef_organization)}"
enterprise = "${var.automate_enterprise}"
admin_password = "${var.admin_password}"
region = "${local.region}"
upgrade_chef = "${var.upgrade_chef}"
enable_telemetry = "${var.enable_telemetry}"
region = "${local.region}"
bucket_name = "${var.bucket_name}"
}
}
data "template_file" "aws_credentials" {
template = "${file("${path.module}/files/aws_credentials")}"
vars {
access_key_id = "${var.aws_access_key_id}"
secret_access_key = "${var.aws_secret_access_key}"
}
}
resource "aws_instance" "ChefServer" {
ami = "${local.ami}"
instance_type = "${var.instance_type}"
vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
subnet_id = "${var.subnet_id}"
key_name = "${var.key_name}"
root_block_device {
volume_size = "${var.volume_size}"
volume_type = "${var.volume_type}"
}
provisioner "remote-exec" {
inline = [
"mkdir -p /tmp/terraform/.getssl/${lower(var.fqdn)}",
]
connection {
type = "ssh"
host = "${self.private_ip}"
user = "ec2-user"
private_key = "${var.ssh_key}"
}
}
provisioner "file" {
content = "${data.template_file.aws_credentials.rendered}"
destination = "/tmp/terraform/aws_credentials"
connection {
type = "ssh"
host = "${self.private_ip}"
user = "ec2-user"
private_key = "${var.ssh_key}"
}
}
provisioner "file" {
content = "${data.template_file.getssl_cfg.rendered}"
destination = "/tmp/terraform/.getssl/${lower(var.fqdn)}/getssl.cfg"
connection {
type = "ssh"
host = "${self.private_ip}"
user = "ec2-user"
private_key = "${var.ssh_key}"
}
}
provisioner "file" {
content = "${var.account_key}"
destination = "/tmp/terraform/.getssl/account.key"
connection {
type = "ssh"
host = "${self.private_ip}"
user = "ec2-user"
private_key = "${var.ssh_key}"
}
}
provisioner "file" {
source = "${path.module}/files/dns_route53.py"
destination = "/tmp/terraform/dns_route53.py"
connection {
type = "ssh"
host = "${self.private_ip}"
user = "ec2-user"
private_key = "${var.ssh_key}"
}
}
provisioner "file" {
source = "${path.module}/files/s3_upload.py"
destination = "/tmp/terraform/s3_upload.py"
connection {
type = "ssh"
host = "${self.private_ip}"
user = "ec2-user"
private_key = "${var.ssh_key}"
}
}
provisioner "remote-exec" {
inline = "${data.template_file.ChefServer_setup_script.rendered}"
connection {
type = "ssh"
host = "${self.private_ip}"
user = "ec2-user"
private_key = "${var.ssh_key}"
}
}
tags = "${var.tags}"
}