-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
77 lines (63 loc) · 2.05 KB
/
main.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
provider "aws" {
region = var.aws_region
}
resource "tls_private_key" "tfe" {
algorithm = "RSA"
}
resource "aws_key_pair" "tfe" {
key_name = var.environment_name
public_key = tls_private_key.tfe.public_key_openssh
}
resource "null_resource" "tfe" {
provisioner "local-exec" {
command = "echo '${tls_private_key.tfe.private_key_pem}' > ~/.ssh/${var.environment_name}.pem && chmod 600 ~/.ssh/${var.environment_name}.pem"
}
}
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
//--------------------------------------------------------------------
// TFE Server Instance
resource "aws_instance" "tfe-server" {
count = length(var.tfe_server_names)
ami = data.aws_ami.ubuntu.id
instance_type = var.instance_type
availability_zone = var.availability_zones[count.index]
subnet_id = module.vpc.public_subnets[count.index]
key_name = var.environment_name
vpc_security_group_ids = [aws_security_group.tfe-sg.id]
private_ip = var.tfe_server_private_ips[count.index]
iam_instance_profile = aws_iam_instance_profile.tfe-server.id
associate_public_ip_address = true
tags = merge(var.default_base_tags, {
Name = "${var.environment_name}-${var.tfe_server_names[count.index]}"
})
root_block_device {
volume_size = 50
}
user_data = templatefile("${path.module}/templates/userdata-server.tpl", {
tpl_server_count_index = count.index
})
connection {
type = "ssh"
user = "ubuntu"
private_key = "${file("~/.ssh/${var.environment_name}.pem")}"
host = self.public_ip
}
provisioner "file" {
source = "airgap/${var.airgap_file}"
destination = "/home/ubuntu/${var.airgap_file}"
}
lifecycle {
ignore_changes = [ami, tags]
}
}