-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
61 lines (52 loc) · 2.29 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
locals {
suffix = length(var.suffix) == 0 ? "" : "-${var.suffix}"
virtual_machine_name = var.custom_virtual_machine_name == "" ? "vm-${var.env}${local.suffix}" : "${var.custom_virtual_machine_name}${local.suffix}"
network_interface_name = var.custom_network_interface_name == null ? "nic-${var.project}-${var.env}-${var.location}${local.suffix}" : "${var.custom_network_interface_name}${local.suffix}"
public_ip = var.custom_public_ip_name == null ? "ip-${var.project}-${var.env}-${var.location}${local.suffix}" : "${var.custom_public_ip_name}${local.suffix}"
}
resource "azurerm_public_ip" "this" {
count = var.public_ip_enabled ? 1 : 0
name = local.public_ip
resource_group_name = var.resource_group
location = var.location
tags = var.tags
allocation_method = var.public_ip_allocation_method
}
resource "azurerm_network_interface" "this" {
name = local.network_interface_name
location = var.location
resource_group_name = var.resource_group
tags = var.tags
ip_configuration {
name = "ip-config-${var.project}-${var.env}-${var.location}"
subnet_id = var.subnet_id
private_ip_address_allocation = var.network_interface_private_ip_address_allocation
public_ip_address_id = try(azurerm_public_ip.this[0].id, null)
}
}
resource "azurerm_windows_virtual_machine" "this" {
name = local.virtual_machine_name
location = var.location
tags = var.tags
resource_group_name = var.resource_group
network_interface_ids = [azurerm_network_interface.this.id]
size = var.vm_size
admin_username = var.vm_admin_username
admin_password = var.vm_admin_password
source_image_reference {
publisher = var.source_image_reference.publisher
offer = var.source_image_reference.offer
sku = var.source_image_reference.sku
version = var.source_image_reference.version
}
os_disk {
caching = var.os_disk.caching
storage_account_type = var.os_disk.storage_account_type
}
dynamic "identity" {
for_each = var.identity_enabled ? [1] : []
content {
type = "SystemAssigned"
}
}
}