-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.tf
112 lines (101 loc) · 3.96 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
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
resource "azurerm_network_security_rule" "allow_ssh" {
name = "${var.prefix}-ssh"
priority = 300
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefixes = var.allowed_ssh_cidr_blocks
destination_address_prefix = "*"
resource_group_name = var.resource_group
network_security_group_name = var.nsg_name
}
resource "azurerm_network_security_rule" "allow_8081" {
name = "${var.prefix}-http-nomad"
priority = 301
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "8080-8081"
source_address_prefixes = var.allowed_http_cidr_blocks
destination_address_prefix = "*"
resource_group_name = var.resource_group
network_security_group_name = var.nsg_name
}
resource "azurerm_network_security_rule" "allow_80" {
name = "${var.prefix}-http-hashicups"
priority = 302
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "80"
source_address_prefixes = var.allowed_http_cidr_blocks
destination_address_prefix = "*"
resource_group_name = var.resource_group
network_security_group_name = var.nsg_name
}
# By default if the user doesn't disable it we create an asg
resource "azurerm_public_ip" "public_ip" {
name = "${var.prefix}-client-ip"
location = var.location
resource_group_name = var.resource_group
allocation_method = "Static"
tags = {
environment = "Production"
}
}
resource "azurerm_network_interface" "client_nic" {
name = "${var.prefix}-client-nic"
location = var.location
resource_group_name = var.resource_group
ip_configuration {
name = "${var.prefix}-ip-config"
subnet_id = var.subnet_id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.public_ip.id
}
}
resource "azurerm_linux_virtual_machine" "vm" {
name = "${var.prefix}-client-vm"
location = var.location
resource_group_name = var.resource_group
size = "Standard_F2s_v2"
admin_username = "adminuser"
network_interface_ids = [azurerm_network_interface.client_nic.id]
admin_ssh_key {
username = "adminuser"
public_key = var.ssh_public_key
}
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "Canonical"
offer = "0001-com-ubuntu-server-focal"
sku = "20_04-lts-gen2"
version = "latest"
}
user_data = base64encode(templatefile("${path.module}/templates/user_data.sh", {
setup = base64gzip(templatefile("${path.module}/templates/setup.sh", {
consul_config = var.client_config_file,
consul_ca = var.client_ca_file,
consul_acl_token = var.root_token,
consul_version = var.consul_version,
consul_service = base64encode(templatefile("${path.module}/templates/service", {
service_name = "consul",
service_cmd = "/usr/bin/consul agent -data-dir /var/consul -config-dir=/etc/consul.d/",
})),
nomad_service = base64encode(templatefile("${path.module}/templates/service", {
service_name = "nomad",
service_cmd = "/usr/bin/nomad agent -dev-connect -consul-token=${var.root_token}",
})),
hashicups = base64encode(file("${path.module}/templates/hashicups.nomad")),
nginx_conf = base64encode(file("${path.module}/templates/nginx.conf")),
vpc_cidr = var.vpc_cidr
})),
}))
}