1
+ # Import Resource Group
2
+ resource "azurerm_resource_group" "rg" {
3
+ name = var. resource_group_name
4
+ location = var. resource_group_location
5
+ }
6
+
7
+ # Create virtual network
8
+ resource "azurerm_virtual_network" "vnet" {
9
+ name = " Vnet"
10
+ address_space = [" 10.0.0.0/16" ]
11
+ location = azurerm_resource_group. rg . location
12
+ resource_group_name = azurerm_resource_group. rg . name
13
+ }
14
+
15
+ # Create subnet
16
+ resource "azurerm_subnet" "subnet" {
17
+ name = " Subnet"
18
+ resource_group_name = azurerm_resource_group. rg . name
19
+ virtual_network_name = azurerm_virtual_network. vnet . name
20
+ address_prefixes = [" 10.0.1.0/24" ]
21
+ }
22
+
23
+
24
+ # Create network interface
25
+ resource "azurerm_network_interface" "nic" {
26
+ count = var. instances
27
+ name = " NIC${ count . index } "
28
+ location = azurerm_resource_group. rg . location
29
+ resource_group_name = azurerm_resource_group. rg . name
30
+
31
+ ip_configuration {
32
+ name = " NicConfig"
33
+ subnet_id = azurerm_subnet. subnet . id
34
+ private_ip_address_allocation = " Dynamic"
35
+ }
36
+ }
37
+
38
+ # Create virtual machine
39
+ resource "azurerm_linux_virtual_machine" "vm" {
40
+ count = var. instances
41
+ name = " EX42-${ count . index } "
42
+ location = azurerm_resource_group. rg . location
43
+ resource_group_name = azurerm_resource_group. rg . name
44
+ network_interface_ids = [azurerm_network_interface . nic [count . index ]. id ]
45
+ size = " Standard_DS1_v2"
46
+
47
+ admin_ssh_key {
48
+ username = " admin"
49
+ public_key = file (" ~/.ssh/id_rsa.pub" )
50
+ }
51
+
52
+ os_disk {
53
+ caching = " ReadWrite"
54
+ storage_account_type = " Standard_LRS"
55
+ }
56
+
57
+ source_image_reference {
58
+ publisher = " Canonical"
59
+ offer = " UbuntuServer"
60
+ sku = " 18.04-LTS"
61
+ version = " latest"
62
+ }
63
+
64
+ computer_name = " VM-${ count . index } "
65
+ admin_username = " admin"
66
+ admin_password = " wqe2sdf3"
67
+ disable_password_authentication = false
68
+ }
0 commit comments