-
Notifications
You must be signed in to change notification settings - Fork 1
/
vm.tf
66 lines (56 loc) · 2.08 KB
/
vm.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
# Create virtual machine
# ToDo:
# - Add disk encryption?
# - Set availability zone?
resource "azurerm_linux_virtual_machine" "indy_node" {
name = var.instance_name
location = var.resource_group.location
resource_group_name = var.resource_group.name
network_interface_ids = [azurerm_network_interface.client_nic.id, azurerm_network_interface.node_nic.id]
size = var.instance_size
os_disk {
name = "${var.instance_name}_osdisk"
caching = var.os_disk.caching
storage_account_type = var.os_disk.storage_account_type
}
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
}
computer_name = var.instance_name
admin_username = var.admin_username
disable_password_authentication = true
admin_ssh_key {
username = var.admin_username
public_key = var.public_ssh_key
}
boot_diagnostics {
storage_account_uri = azurerm_storage_account.storage.primary_blob_endpoint
}
tags = merge({
Name = var.instance_name
Instance = var.instance_name
}, var.default_tags)
}
# Generate random text for a unique storage account name
resource "random_id" "randomId" {
keepers = {
# Generate a new ID only when a new resource group is defined
resource_group = var.resource_group.name
}
byte_length = 6
}
# Create storage account for boot diagnostics
resource "azurerm_storage_account" "storage" {
name = replace("${var.instance_name}-${random_id.randomId.hex}", "-", "")
resource_group_name = var.resource_group.name
location = var.resource_group.location
account_tier = var.storage_account.account_tier
account_replication_type = var.storage_account.account_replication_type
tags = merge({
Name = "${var.instance_name}-${random_id.randomId.hex}"
Instance = var.instance_name
}, var.default_tags)
}