-
Notifications
You must be signed in to change notification settings - Fork 0
/
terraform.tf
100 lines (89 loc) · 3.49 KB
/
terraform.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
terraform {
required_version = ">= 0.11.10"
}
resource "azurerm_resource_group" "main" {
name = "${var.prefix}-rg"
location = "${var.location}"
}
resource "azurerm_virtual_network" "main" {
name = "${var.prefix}-vnet"
address_space = ["${var.vnet_space}/${var.vnet_prefix}"]
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
}
resource "azurerm_subnet" "consul_server" {
name = "consul-server-subnet"
resource_group_name = "${azurerm_resource_group.main.name}"
virtual_network_name = "${azurerm_virtual_network.main.name}"
address_prefix = "${var.consul_server_subnet_address}"
}
resource "azurerm_network_interface" "main" {
count = "${var.instance_count}"
name = "${var.prefix}${format("%03d", count.index + 1)}-nic"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
ip_configuration {
name = "${var.prefix}${format("%03d", count.index + 1)}-ip"
subnet_id = "${azurerm_subnet.consul_server.id}"
private_ip_address_allocation = "dynamic"
public_ip_address_id = "${element(azurerm_public_ip.main.*.id, count.index)}"
}
}
resource "azurerm_public_ip" "main" {
count = "${var.instance_count}"
name = "${var.prefix}${format("%03d", count.index + 1)}-pip"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
public_ip_address_allocation = "dynamic"
domain_name_label = "${var.prefix}${format("%03d", count.index + 1)}"
}
resource "azurerm_virtual_machine" "main" {
count = "${var.instance_count}"
name = "${var.prefix}${format("%03d", count.index + 1)}"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
network_interface_ids = ["${element(azurerm_network_interface.main.*.id, count.index)}"]
vm_size = "${var.vm_size}"
delete_os_disk_on_termination = true
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
storage_os_disk {
name = "${var.prefix}osdisk${format("%03d", count.index + 1)}"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "${var.prefix}${format("%03d", count.index+1)}"
admin_username = "${var.admin_username}"
custom_data = "${data.template_file.consul_config.rendered}"
}
os_profile_linux_config {
disable_password_authentication = true
ssh_keys {
path = "/home/${var.admin_username}/.ssh/authorized_keys"
key_data = "${file("~/.ssh/id_rsa.pub")}"
}
}
tags {
consul = "server"
environment ="testing"
}
}
data "template_file" "consul_config" {
template = "${file("${path.root}/install_consul.sh")}"
vars {
consul_encrpyt = "${var.consul_encrypt}"
consul_datacenter = "${var.location}"
consul_version = "${var.consul_version}"
scale_set_name = "${var.scale_set_name}-server"
subscription_id = "${var.subscription_id}"
tenant_id = "${var.tenant_id}"
client_id = "${var.client_id}"
secret_access_key = "${var.secret_access_key}"
}
}