-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
63 lines (58 loc) · 1.69 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
terraform {
required_version = ">= 0.13"
required_providers {
random = {
source = "hashicorp/random"
version = "~> 3.1"
}
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.0"
}
}
}
resource "random_password" "vmpw" {
count = var.enable ? 1 : 0
length = 16
}
resource "azurerm_network_interface" "nic" {
count = var.enable ? 1 : 0
name = var.vm_name
location = var.location
resource_group_name = var.resource_group_name
ip_configuration {
name = "${var.vm_name}-nic"
subnet_id = var.subnet_id
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_virtual_machine" "vm" {
count = var.enable ? 1 : 0
name = var.vm_name
location = var.location
resource_group_name = var.resource_group_name
network_interface_ids = [azurerm_network_interface.nic[0].id]
vm_size = "Standard_B1s"
delete_os_disk_on_termination = true
delete_data_disks_on_termination = true
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
storage_os_disk {
name = "${var.vm_name}-osdisk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "StandardSSD_LRS"
}
os_profile {
computer_name = var.vm_name
admin_username = var.admin_user
admin_password = random_password.vmpw[0].result
}
os_profile_linux_config {
disable_password_authentication = false
}
}