Added hosts as modules
This commit is contained in:
parent
111b454307
commit
fcab4a6b95
|
@ -0,0 +1,41 @@
|
||||||
|
variable "username" {
|
||||||
|
type = string
|
||||||
|
description = "VMs admin username"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_public_key" {
|
||||||
|
type = string
|
||||||
|
description = "SSH public signature's of the admin"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "machine_type" {
|
||||||
|
type = string
|
||||||
|
description = "Machine type/size"
|
||||||
|
default = "Standard_B1s" # Defaulting to the 750 free hours tier machine.
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "host_name" {
|
||||||
|
type = string
|
||||||
|
description = "Name of VM instance"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "resource_group_name" {
|
||||||
|
type = string
|
||||||
|
description = "Azure resource group name"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "location" {
|
||||||
|
type = string
|
||||||
|
description = "location of resource"
|
||||||
|
default = "eastus"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "local_network_cidr" {
|
||||||
|
type = string
|
||||||
|
description = "CIDR Range of the local virtual network"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "local_subnet_cidr" {
|
||||||
|
type = string
|
||||||
|
description = "CIDR Range of the local subnet, usually contained within the local_network_cidr"
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
output "resources" {
|
||||||
|
value = {
|
||||||
|
host = azurerm_linux_virtual_machine.deployed_host
|
||||||
|
nic = azurerm_network_interface.host_network_interface
|
||||||
|
net = azurerm_virtual_network.local_network
|
||||||
|
subnet = azurerm_subnet.local_subnet
|
||||||
|
pub_ip = azurerm_public_ip.host_public_ip
|
||||||
|
}
|
||||||
|
sensitive = false
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
resource "azurerm_linux_virtual_machine" "deployed_host" {
|
||||||
|
admin_username = var.username
|
||||||
|
location = var.location
|
||||||
|
name = var.host_name
|
||||||
|
resource_group_name = var.resource_group_name
|
||||||
|
secure_boot_enabled = true
|
||||||
|
size = var.machine_type
|
||||||
|
vtpm_enabled = true
|
||||||
|
admin_ssh_key {
|
||||||
|
public_key = var.ssh_public_key
|
||||||
|
username = var.username
|
||||||
|
}
|
||||||
|
boot_diagnostics {
|
||||||
|
}
|
||||||
|
os_disk {
|
||||||
|
caching = "ReadWrite"
|
||||||
|
storage_account_type = "Premium_LRS"
|
||||||
|
}
|
||||||
|
source_image_reference {
|
||||||
|
offer = "0001-com-ubuntu-server-jammy"
|
||||||
|
publisher = "canonical"
|
||||||
|
sku = "22_04-lts-gen2"
|
||||||
|
version = "latest"
|
||||||
|
}
|
||||||
|
network_interface_ids = [ azurerm_network_interface.host_network_interface.id ]
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
resource "azurerm_virtual_network" "local_network" {
|
||||||
|
address_space = [ var.local_network_cidr ]
|
||||||
|
location = var.location
|
||||||
|
name = "${var.host_name}-vnet"
|
||||||
|
resource_group_name = var.resource_group_name
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_subnet" "local_subnet" {
|
||||||
|
address_prefixes = [ var.local_subnet_cidr ]
|
||||||
|
name = "default"
|
||||||
|
resource_group_name = var.resource_group_name
|
||||||
|
virtual_network_name = azurerm_virtual_network.local_network.name
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_public_ip" "host_public_ip" {
|
||||||
|
name = "${var.host_name}-ip"
|
||||||
|
allocation_method = "Static"
|
||||||
|
domain_name_label = var.host_name
|
||||||
|
location = var.location
|
||||||
|
resource_group_name = var.resource_group_name
|
||||||
|
sku = "Standard"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_network_interface" "host_network_interface" {
|
||||||
|
name = "${var.host_name}-nic"
|
||||||
|
location = var.location
|
||||||
|
resource_group_name = var.resource_group_name
|
||||||
|
ip_configuration {
|
||||||
|
name = "ipconfig1"
|
||||||
|
private_ip_address_allocation = "Dynamic"
|
||||||
|
public_ip_address_id = azurerm_public_ip.host_public_ip.id
|
||||||
|
subnet_id = azurerm_subnet.local_subnet.id
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue