-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
57 lines (55 loc) · 2.42 KB
/
main.tf
File metadata and controls
57 lines (55 loc) · 2.42 KB
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
resource "azurerm_network_interface" "azure_linux_vm_nics" {
for_each = local.network_configuration_data
name = replace(each.key, ":", "-")
resource_group_name = var.azure_resource_group
location = var.azure_region
dynamic "ip_configuration" {
for_each = { for ip_config in each.value.ip_configurations : ip_config.name => ip_config }
content {
name = ip_configuration.key
subnet_id = ip_configuration.value.subnet_id
private_ip_address_allocation = ip_configuration.value.private_ip_address_allocation_method
private_ip_address = ip_configuration.value.private_ip_address
}
}
tags = {
Environment = var.env
}
}
resource "azurerm_linux_virtual_machine" "azure_linux_vm" {
for_each = var.azure_linux_vms
name = each.key
resource_group_name = var.azure_resource_group
location = var.azure_region
size = each.value.size
admin_username = each.value.admin_username
disable_password_authentication = each.value.use_ssh_authentication ? true : false
admin_password = each.value.use_ssh_authentication ? null : each.value.admin_password
zone = each.value.availability_zone
network_interface_ids = [
for nic in local.network_configuration_data : azurerm_network_interface.azure_linux_vm_nics["${nic.vm}:${nic.name}"].id if nic.vm == "${each.key}"
]
custom_data = each.value.custom_data == null ? null : each.value.custom_data
dynamic "admin_ssh_key" {
for_each = each.value.use_ssh_authentication == true ? toset([for ssh_key in each.value.ssh_keys : ssh_key]) : toset([])
iterator = ssh_key
content {
username = each.value.admin_username
public_key = file(ssh_key.value)
}
}
os_disk {
caching = each.value.os_disk_config.caching
storage_account_type = each.value.os_disk_config.storage_account_type
}
source_image_reference {
# This information can be found by running az vm image list --all
publisher = each.value.source_image_reference.publisher
offer = each.value.source_image_reference.offer
sku = each.value.source_image_reference.sku
version = each.value.source_image_reference.version
}
tags = {
Environment = var.env
}
}