generated from pacroy/template-basic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
150 lines (126 loc) · 5.07 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
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
146
147
148
149
150
resource "azurerm_network_security_group" "default" {
name = join("-", [module.naming.network_security_group.name, "default"])
location = local.location
resource_group_name = local.resource_group_name
}
resource "azurerm_network_security_rule" "allow_control" {
resource_group_name = local.resource_group_name
network_security_group_name = azurerm_network_security_group.default.name
direction = "Inbound"
source_address_prefix = local.ip_address
source_address_prefixes = local.ip_address_list
source_port_range = "*"
destination_address_prefix = "*"
destination_port_ranges = [local.ssh_vm_port, "16443"]
protocol = "Tcp"
access = "Allow"
priority = 100
name = "AllowControlFromIP"
}
resource "azurerm_network_security_rule" "allow_https" {
resource_group_name = local.resource_group_name
network_security_group_name = azurerm_network_security_group.default.name
direction = "Inbound"
source_address_prefix = "Internet"
source_port_range = "*"
destination_address_prefix = "*"
destination_port_ranges = [local.http_port, local.https_port]
protocol = "Tcp"
access = "Allow"
priority = 110
name = "AllowHTTPsFromInternet"
}
resource "azurerm_network_security_rule" "allow_azurecloud" {
count = var.allow_kubectl_from_azurecloud ? 1 : 0
resource_group_name = local.resource_group_name
network_security_group_name = azurerm_network_security_group.default.name
direction = "Inbound"
source_address_prefix = "AzureCloud"
source_port_range = "*"
destination_address_prefix = "*"
destination_port_ranges = [local.ssh_vm_port, "16443"]
protocol = "Tcp"
access = "Allow"
priority = 120
name = "AllowControlFromAzureCloud"
}
resource "azurerm_virtual_network" "main" {
name = module.naming.virtual_network.name
resource_group_name = local.resource_group_name
location = local.location
address_space = [local.address_space]
subnet {
name = "default"
address_prefixes = [cidrsubnet(local.address_space, 8, 0)]
security_group = azurerm_network_security_group.default.id
}
}
resource "azurerm_network_interface" "main" {
name = module.naming.network_interface.name
resource_group_name = local.resource_group_name
location = local.location
accelerated_networking_enabled = true
ip_configuration {
name = "ipconfig1"
subnet_id = one(azurerm_virtual_network.main.subnet).id
private_ip_address_allocation = "Static"
private_ip_address = cidrhost(one(azurerm_virtual_network.main.subnet).address_prefixes[0], 4)
}
}
resource "azurerm_linux_virtual_machine" "main" {
name = module.naming.linux_virtual_machine.name
resource_group_name = local.resource_group_name
location = local.location
size = local.size
admin_username = local.admin_username
network_interface_ids = [azurerm_network_interface.main.id]
encryption_at_host_enabled = true
provision_vm_agent = true
patch_mode = "AutomaticByPlatform"
patch_assessment_mode = "AutomaticByPlatform"
bypass_platform_safety_checks_on_user_schedule_enabled = true
admin_ssh_key {
username = local.admin_username
public_key = local.public_key
}
boot_diagnostics {}
os_disk {
name = join("-", ["osdisk", module.naming.linux_virtual_machine.name])
caching = "ReadWrite"
storage_account_type = "Premium_LRS"
}
source_image_reference {
offer = "0001-com-ubuntu-server-focal"
publisher = "canonical"
sku = "20_04-lts-gen2"
version = "latest"
}
identity {
type = "SystemAssigned"
}
custom_data = data.cloudinit_config.init.rendered
}
resource "azurerm_maintenance_configuration" "main" {
name = "mc-${local.suffix}"
resource_group_name = local.resource_group_name
location = local.location
scope = "InGuestPatch"
in_guest_user_patch_mode = "User"
window {
start_date_time = "${local.vm_update_schedule_start_date} 00:00"
duration = "01:30"
time_zone = "UTC"
recur_every = "Day"
}
install_patches {
reboot = "IfRequired"
linux {
classifications_to_include = ["Critical", "Security"]
}
}
}
resource "azurerm_maintenance_assignment_virtual_machine" "main" {
location = local.location
maintenance_configuration_id = azurerm_maintenance_configuration.main.id
virtual_machine_id = azurerm_linux_virtual_machine.main.id
}