-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
base.tf
145 lines (120 loc) · 4.12 KB
/
base.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
141
142
143
144
145
# Microsoft Azure Provider
provider "azurerm" {
# If using a service principal, fill in details here
}
variable "ssh_key" {
type = "string"
}
# This is the primary username used to administer the machine
variable "admin_username" {
type = "string"
default = "azureuser"
}
# This is the secondary username used to administer services
variable "paas_username" {
type = "string"
default = "paas"
}
variable "instance_prefix" {
default = "paas"
}
variable "shared_prefix" {
default = "demo"
}
variable "ssh_port" {
default = "22"
}
variable "location" {
default = "Central US"
}
variable "standard_vm_size" {
default = "Standard_B1s"
}
variable "storage_type" {
default = "Premium_LRS"
}
variable "cloud_config" {
default = "base.yml.tpl"
}
locals {
resource_group_name = "${var.shared_prefix}"
tags = {
environment = "production"
solution = "${var.instance_prefix}"
}
vnet_name = "${var.shared_prefix}"
vnet_address_space = "10.0.0.0/16"
subnet_name = "default"
subnet_address_prefix = "10.0.0.0/24"
}
# Resource group
resource "azurerm_resource_group" "rg" {
name = "${local.resource_group_name}"
location = "${var.location}"
tags = "${merge(local.tags, map("provisionedBy", "terraform"))}"
}
# Networking
resource "azurerm_virtual_network" "vnet" {
name = "${local.vnet_name}"
location = "${azurerm_resource_group.rg.location}"
address_space = ["${local.vnet_address_space}"]
resource_group_name = "${azurerm_resource_group.rg.name}"
tags = "${local.tags}"
}
resource "azurerm_subnet" "default" {
name = "${local.subnet_name}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
address_prefix = "${local.subnet_address_prefix}"
}
# Generate random text for a unique storage account name
resource "random_id" "pseudo" {
keepers = {
resource_group = "${azurerm_resource_group.rg.name}"
location = "${azurerm_resource_group.rg.location}"
}
byte_length = 4
}
resource "azurerm_storage_account" "diagnostics" {
name = "${var.shared_prefix}diag${random_id.pseudo.hex}"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
account_replication_type = "LRS"
account_tier = "Standard"
tags = "${local.tags}"
}
resource "azurerm_availability_set" "machines" {
name = "${var.shared_prefix}"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
managed = true
tags = "${local.tags}"
}
data "template_file" "cloud_config" {
template = "${file("${path.module}/cloud-config/${var.cloud_config}")}"
vars {
ssh_port = "${var.ssh_port}"
ssh_key = "${var.ssh_key}"
admin_username = "${var.admin_username}"
paas_username = "${var.paas_username}"
}
}
module "linux" {
source = "./linux"
name = "${var.instance_prefix}"
vm_size = "${var.standard_vm_size}"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
admin_username = "${var.admin_username}"
ssh_key = "${var.ssh_key}"
ssh_port = "${var.ssh_port}"
// this is something that annoys me - passing the resource would be nicer
diag_storage_name = "${azurerm_storage_account.diagnostics.name}"
diag_storage_primary_blob_endpoint = "${azurerm_storage_account.diagnostics.primary_blob_endpoint}"
diag_storage_primary_access_key = "${azurerm_storage_account.diagnostics.primary_access_key}"
availability_set_id = "${azurerm_availability_set.machines.id}"
subnet_id = "${azurerm_subnet.default.id}"
storage_type = "${var.storage_type}"
tags = "${local.tags}"
cloud_config = "${base64encode(data.template_file.cloud_config.rendered)}"
}