-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
76 lines (62 loc) · 2.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
resource "azurerm_resource_group" "this" {
name = "rg-${var.project}-${var.environment}-${var.location}"
location = var.location
}
resource "azurerm_virtual_network" "this" {
name = "vnet-${var.project}-${var.environment}"
resource_group_name = azurerm_resource_group.this.name
location = azurerm_resource_group.this.location
address_space = ["10.0.0.0/16"]
}
resource "azurerm_subnet" "subnet" {
name = "snet-${var.project}-${var.environment}"
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.this.name
address_prefixes = ["10.0.1.0/24"]
}
resource "azurerm_network_interface" "nic" {
count = 4
name = "nic-${var.project}-${var.environment}-${count.index}"
resource_group_name = azurerm_resource_group.this.name
location = azurerm_resource_group.this.location
ip_configuration {
name = "ipc-private"
subnet_id = azurerm_subnet.subnet.id
private_ip_address_allocation = "Dynamic"
}
}
resource "random_password" "vm" {
length = 16
}
resource "azurerm_linux_virtual_machine" "vm" {
count = 4
name = "vm${var.project}${var.environment}${count.index}"
resource_group_name = azurerm_resource_group.this.name
location = azurerm_resource_group.this.location
size = "Standard_F2s_v2"
admin_username = "adminuser"
admin_password = random_password.vm.result
disable_password_authentication = false
network_interface_ids = [
azurerm_network_interface.nic[count.index].id
]
os_disk {
caching = "ReadWrite"
storage_account_type = "StandardSSD_LRS"
}
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
}
variable "project" {
type = string
}
variable "environment" {
type = string
}
variable "location" {
type = string
}