|
| 1 | +locals { |
| 2 | + password_seed = replace(uuid(), "-", "") |
| 3 | + generated_password = format("%s_+%s", substr(local.password_seed, 0, 12), substr(local.password_seed, 12, 10)) |
| 4 | + instance_password = var.instance_password != "" ? var.instance_password : local.generated_password |
| 5 | + |
| 6 | +} |
| 7 | + |
| 8 | +resource "azurerm_resource_group" "redc" { |
| 9 | + name = "redc-resources-1" |
| 10 | + location = "West Europe" |
| 11 | +} |
| 12 | + |
| 13 | +resource "azurerm_public_ip" "redc" { |
| 14 | + name = "test-publicip" |
| 15 | + resource_group_name = azurerm_resource_group.redc.name |
| 16 | + location = azurerm_resource_group.redc.location |
| 17 | + allocation_method = "Static" |
| 18 | +} |
| 19 | + |
| 20 | +resource "azurerm_network_security_group" "redc" { |
| 21 | + name = "test-security-group" |
| 22 | + location = azurerm_resource_group.redc.location |
| 23 | + resource_group_name = azurerm_resource_group.redc.name |
| 24 | + depends_on = [ |
| 25 | + azurerm_resource_group.redc, |
| 26 | + ] |
| 27 | + |
| 28 | + security_rule { |
| 29 | + name = "test-security-group-rule" |
| 30 | + priority = 100 |
| 31 | + direction = "Inbound" |
| 32 | + access = "Allow" |
| 33 | + protocol = "Tcp" |
| 34 | + source_port_range = "22" |
| 35 | + destination_port_range = "*" |
| 36 | + source_address_prefix = "*" |
| 37 | + destination_address_prefix = "*" |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +resource "azurerm_virtual_network" "redc" { |
| 42 | + name = "test-network" |
| 43 | + address_space = ["10.0.0.0/16"] |
| 44 | + location = azurerm_resource_group.redc.location |
| 45 | + resource_group_name = azurerm_resource_group.redc.name |
| 46 | + depends_on = [ |
| 47 | + azurerm_resource_group.redc, |
| 48 | + ] |
| 49 | +} |
| 50 | + |
| 51 | +resource "azurerm_subnet" "redc" { |
| 52 | + name = "test-internal" |
| 53 | + resource_group_name = azurerm_resource_group.redc.name |
| 54 | + virtual_network_name = azurerm_virtual_network.redc.name |
| 55 | + address_prefixes = ["10.0.2.0/24"] |
| 56 | + depends_on = [ |
| 57 | + azurerm_resource_group.redc, |
| 58 | + azurerm_virtual_network.redc |
| 59 | + ] |
| 60 | +} |
| 61 | + |
| 62 | +resource "azurerm_network_interface" "redc" { |
| 63 | + name = "test-nic" |
| 64 | + location = azurerm_resource_group.redc.location |
| 65 | + resource_group_name = azurerm_resource_group.redc.name |
| 66 | + depends_on = [ |
| 67 | + azurerm_resource_group.redc, |
| 68 | + azurerm_public_ip.redc, |
| 69 | + azurerm_subnet.redc |
| 70 | + ] |
| 71 | + |
| 72 | + ip_configuration { |
| 73 | + name = "test-internal" |
| 74 | + subnet_id = azurerm_subnet.redc.id |
| 75 | + private_ip_address_allocation = "Dynamic" |
| 76 | + public_ip_address_id = azurerm_public_ip.redc.id |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +resource "azurerm_linux_virtual_machine" "redc" { |
| 81 | + name = "test-machine" |
| 82 | + resource_group_name = azurerm_resource_group.redc.name |
| 83 | + location = azurerm_resource_group.redc.location |
| 84 | + size = "Standard_D2a_v4" |
| 85 | + admin_username = "redcadmin" |
| 86 | + admin_password = local.instance_password |
| 87 | + disable_password_authentication = false |
| 88 | + user_data = "IyEvYmluL2Jhc2g=" |
| 89 | + network_interface_ids = [ |
| 90 | + azurerm_network_interface.redc.id, |
| 91 | + ] |
| 92 | + depends_on = [ |
| 93 | + azurerm_resource_group.redc, |
| 94 | + azurerm_network_interface.redc |
| 95 | + ] |
| 96 | + |
| 97 | + os_disk { |
| 98 | + caching = "ReadWrite" |
| 99 | + storage_account_type = "Standard_LRS" |
| 100 | + } |
| 101 | + |
| 102 | + source_image_reference { |
| 103 | + publisher = "Canonical" |
| 104 | + offer = "UbuntuServer" |
| 105 | + sku = "18.04-LTS" |
| 106 | + version = "latest" |
| 107 | + } |
| 108 | +} |
0 commit comments