terraform/ecc-azure-142-asb_vm_net_ports_restrict/green/vm.tf (83 lines of code) (raw):
resource "azurerm_virtual_network" "this" {
name = "vnet-${var.prefix}-green"
address_space = ["10.0.0.0/24"]
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name
tags = var.tags
}
resource "azurerm_subnet" "snet1" {
name = "snet1-${var.prefix}"
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.this.name
address_prefixes = ["10.0.0.0/25"]
}
resource "azurerm_subnet" "snet2" {
name = "snet2-${var.prefix}"
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.this.name
address_prefixes = ["10.0.0.128/25"]
}
resource "azurerm_network_interface" "nic1" {
name = "nic1-${var.prefix}"
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name
ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.snet1.id
private_ip_address_allocation = "Dynamic"
}
tags = var.tags
}
resource "azurerm_network_interface" "nic2" {
name = "nic2-${var.prefix}"
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name
ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.snet2.id
private_ip_address_allocation = "Dynamic"
}
tags = var.tags
}
resource "azurerm_linux_virtual_machine" "vm1" {
name = "vm1-${var.prefix}"
resource_group_name = azurerm_resource_group.this.name
location = azurerm_resource_group.this.location
size = "Standard_F2"
admin_username = random_string.this.result
admin_password = random_password.this.result
disable_password_authentication = false
network_interface_ids = [azurerm_network_interface.nic1.id]
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
tags = var.tags
}
resource "azurerm_linux_virtual_machine" "vm2" {
name = "vm2-${var.prefix}"
resource_group_name = azurerm_resource_group.this.name
location = azurerm_resource_group.this.location
size = "Standard_F2"
admin_username = random_string.this.result
admin_password = random_password.this.result
disable_password_authentication = false
network_interface_ids = [azurerm_network_interface.nic2.id]
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
tags = var.tags
}