Skip to content

Commit

Permalink
added testing examples
Browse files Browse the repository at this point in the history
  • Loading branch information
caietbeyond committed Apr 3, 2024
1 parent ec3e750 commit 2c1bf9a
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 138 deletions.
File renamed without changes.
File renamed without changes.
144 changes: 144 additions & 0 deletions examples/advanced copy/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
provider "azurerm" {
features {}
}

module "virtual_machine" {
source = "../.."
public_ip_config = {
enabled = true
allocation_method = "Static"
}
stage = "tst"
nic_config = {
private_ip = "10.0.0.16"
enable_accelerated_networking = true
dns_servers = [ "10.0.0.10", "10.0.0.11" ]
nsg = azurerm_network_security_group.this
}
virtual_machine_config = {
hostname = "CUSTAPP007"
location = local.location
size = "Standard_B2s_v2"
zone = null # Could be the default value "1", or "2" or "3". Not compatible with availability_set_id enabled.
os_sku = "22_04-lts-gen2"
os_offer = "0001-com-ubuntu-server-jammy"
os_version = "latest"
os_publisher = "Canonical"
os_disk_caching = "ReadWrite"
os_disk_storage_type = "StandardSSD_LRS"
os_disk_size_gb = 64
availability_set_id = azurerm_availability_set.this.id # Not compatible with zone.
write_accelerator_enabled = false
proximity_placement_group_id = azurerm_proximity_placement_group.this.id
tags = {
"Environment" = "prd"
}
}
admin_credential = {
admin_username = "local_admin"
public_key = file("${path.root}/id_rsa.pub")
}

resource_group_name = azurerm_resource_group.this.name
subnet = azurerm_subnet.this
additional_network_interface_ids = [azurerm_network_interface.additional_nic_01.id]

data_disks = {
shared-01 = { # Examp. With disk prefix: vm-CUSTAPP007-datadisk-shared-01., Without: vm-CUSTAPP007-shared-01
lun = 1
tier = "P4"
caching = "None"
disk_size_gb = 513
create_option = "Empty"
storage_account_type = "Premium_LRS"
write_accelerator_enabled = false
on_demand_bursting_enabled = true
}
}

name_overrides = {
nic = local.nic
nic_ip_config = local.nic_ip_config
public_ip = local.public_ip
virtual_machine = local.virtual_machine
os_disk = "vm-CUSTAPP007_OsDisk"
data_disks = {
shared-01 = "vm-CUSTAPP007-datadisk-shared-01"
}
}
}

resource "azurerm_resource_group" "this" {
name = local.resource_group_name
location = local.location
}

resource "azurerm_virtual_network" "this" {
name = local.virtual_network_name
address_space = [ "10.0.0.0/24" ]
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name
}

resource "azurerm_subnet" "this" {
name = local.subnet_name
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.this.name
address_prefixes = [ "10.0.0.0/24" ]
}

resource "azurerm_availability_set" "this" {
name = local.availability_set_name
location = local.location
resource_group_name = azurerm_resource_group.this.name
proximity_placement_group_id = azurerm_proximity_placement_group.this.id
}

resource "azurerm_proximity_placement_group" "this" {
name = local.proximity_placement_group_name
location = local.location
resource_group_name = azurerm_resource_group.this.name

lifecycle {
ignore_changes = [tags]
}
}

resource "azurerm_network_interface" "additional_nic_01" {
name = "nic-vm-${replace(element(azurerm_virtual_network.this.address_space,0), "/[./]/", "-")}-01"
location = local.location
resource_group_name = azurerm_resource_group.this.name
dns_servers = []

ip_configuration {
name = "ip-nic-01"
subnet_id = azurerm_subnet.this.id
private_ip_address_allocation = "Dynamic"
private_ip_address = null
public_ip_address_id = null
}

lifecycle {
ignore_changes = [
tags
]
}
}

resource "azurerm_network_security_group" "this" {
name = local.nsg_name
location = local.location
resource_group_name = azurerm_resource_group.this.name

security_rule {
name = "example"
priority = 100
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "*"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}
42 changes: 22 additions & 20 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@ provider "azurerm" {
}

module "virtual_machine" {
source = "../.."
source = "../.."

virtual_machine_config = {
hostname = "CUSTAPP001"
location = local.location
size = "Standard_B1ms"
os_sku = "22_04-lts-gen2"
os_offer = "0001-com-ubuntu-server-jammy"
os_version = "latest"
os_publisher = "Canonical"
}
admin_credential = {
admin_username = "local_admin"
admin_password = "H3ll0W0rld!"
disable_password_authentication = false
}
virtual_machine_config = {
hostname = "CUSTAPP001"
location = local.location
size = "Standard_B1ms"
os_sku = "22_04-lts-gen2"
os_offer = "0001-com-ubuntu-server-jammy"
os_version = "latest"
os_publisher = "Canonical"
severity_group = "01-second-monday-0300-XCSUFEDTG-reboot"
}
admin_credential = {
admin_username = "local_admin"
admin_password = "H3ll0W0rld!"
disable_password_authentication = false
}
stage = "tst"

resource_group_name = azurerm_resource_group.this.name
subnet = azurerm_subnet.this
resource_group_name = azurerm_resource_group.this.name
subnet = azurerm_subnet.this
}

resource "azurerm_resource_group" "this" {
Expand All @@ -31,7 +33,7 @@ resource "azurerm_resource_group" "this" {

resource "azurerm_virtual_network" "this" {
name = local.virtual_network_name
address_space = [ "10.0.0.0/24" ]
address_space = ["10.0.0.0/24"]
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name
}
Expand All @@ -40,5 +42,5 @@ resource "azurerm_subnet" "this" {
name = local.subnet_name
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.this.name
address_prefixes = [ "10.0.0.0/24" ]
}
address_prefixes = ["10.0.0.0/24"]
}
146 changes: 39 additions & 107 deletions examples/write_accelerator/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,141 +4,73 @@ provider "azurerm" {

module "virtual_machine" {
source = "../.."
public_ip_config = {
enabled = true
allocation_method = "Static"
}
stage = "tst"
nic_config = {
private_ip = "10.0.0.16"
enable_accelerated_networking = true
dns_servers = [ "10.0.0.10", "10.0.0.11" ]
nsg = azurerm_network_security_group.this
}

virtual_machine_config = {
hostname = "CUSTAPP007"
location = local.location
size = "Standard_B2s_v2"
zone = null # Could be the default value "1", or "2" or "3". Not compatible with availability_set_id enabled.
os_sku = "22_04-lts-gen2"
os_offer = "0001-com-ubuntu-server-jammy"
os_version = "latest"
os_publisher = "Canonical"
os_disk_caching = "ReadWrite"
os_disk_storage_type = "StandardSSD_LRS"
os_disk_size_gb = 64
availability_set_id = azurerm_availability_set.this.id # Not compatible with zone.
write_accelerator_enabled = false
proximity_placement_group_id = azurerm_proximity_placement_group.this.id
tags = {
"Environment" = "prd"
}
hostname = "CUSTAPP001"
location = azurerm_resource_group.this.location
size = "Standard_M8ms"
os_sku = "22_04-lts-gen2"
os_offer = "0001-com-ubuntu-server-jammy"
os_version = "latest"
os_publisher = "Canonical"
severity_group = "01-second-monday-0300-XCSUFEDTG-reboot"
}
admin_credential = {
admin_username = "local_admin"
public_key = file("${path.root}/id_rsa.pub")
admin_password = "H3ll0W0rld!"
}

resource_group_name = azurerm_resource_group.this.name
subnet = azurerm_subnet.this
additional_network_interface_ids = [azurerm_network_interface.additional_nic_01.id]
stage = "tst"

data_disks = {
shared-01 = { # Examp. With disk prefix: vm-CUSTAPP007-datadisk-shared-01., Without: vm-CUSTAPP007-shared-01
shared-01 = {
lun = 1
tier = "P4"
caching = "ReadOnly"
disk_size_gb = 513
create_option = "Empty"
storage_account_type = "Premium_LRS"
write_accelerator_enabled = true
on_demand_bursting_enabled = true
}
shared-02 = {
lun = 2
tier = "P4"
caching = "None"
disk_size_gb = 513
create_option = "Empty"
storage_account_type = "Premium_LRS"
write_accelerator_enabled = true
on_demand_bursting_enabled = true
}
}

name_overrides = {
nic = local.nic
nic_ip_config = local.nic_ip_config
public_ip = local.public_ip
virtual_machine = local.virtual_machine
os_disk = "vm-CUSTAPP007_OsDisk"
data_disks = {
shared-01 = "vm-CUSTAPP007-datadisk-shared-01"
shared-03 = {
lun = 3
tier = "P4"
caching = "ReadWrite"
disk_size_gb = 513
create_option = "Empty"
storage_account_type = "Premium_LRS"
write_accelerator_enabled = false
on_demand_bursting_enabled = false
}
}
resource_group_name = azurerm_resource_group.this.name
subnet = azurerm_subnet.this
}

resource "azurerm_resource_group" "this" {
name = local.resource_group_name
location = local.location
name = "rg-TestLinuxWriteAccelerator-tst-01"
location = "westeurope"
}

resource "azurerm_virtual_network" "this" {
name = local.virtual_network_name
address_space = [ "10.0.0.0/24" ]
name = "vnet-10-0-0-0-24-${azurerm_resource_group.this.location}"
address_space = ["10.0.0.0/24"]
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name
}

resource "azurerm_subnet" "this" {
name = local.subnet_name
name = "snet-10-0-0-0-24-Test"
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.this.name
address_prefixes = [ "10.0.0.0/24" ]
}

resource "azurerm_availability_set" "this" {
name = local.availability_set_name
location = local.location
resource_group_name = azurerm_resource_group.this.name
proximity_placement_group_id = azurerm_proximity_placement_group.this.id
}

resource "azurerm_proximity_placement_group" "this" {
name = local.proximity_placement_group_name
location = local.location
resource_group_name = azurerm_resource_group.this.name

lifecycle {
ignore_changes = [tags]
}
}

resource "azurerm_network_interface" "additional_nic_01" {
name = "nic-vm-${replace(element(azurerm_virtual_network.this.address_space,0), "/[./]/", "-")}-01"
location = local.location
resource_group_name = azurerm_resource_group.this.name
dns_servers = []

ip_configuration {
name = "ip-nic-01"
subnet_id = azurerm_subnet.this.id
private_ip_address_allocation = "Dynamic"
private_ip_address = null
public_ip_address_id = null
}

lifecycle {
ignore_changes = [
tags
]
}
address_prefixes = ["10.0.0.0/24"]
}

resource "azurerm_network_security_group" "this" {
name = local.nsg_name
location = local.location
resource_group_name = azurerm_resource_group.this.name

security_rule {
name = "example"
priority = 100
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "*"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}
2 changes: 1 addition & 1 deletion locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ locals {

virtual_machine = {
name = coalesce(var.name_overrides.virtual_machine, "vm-${var.virtual_machine_config.hostname}")
tags = merge(var.tags, { "Severity Group Monthly" = var.severity_group, "Update allowed" = local.update_allowed })
tags = merge(var.tags, { "Severity Group Monthly" = var.virtual_machine_config.severity_group, "Update allowed" = local.update_allowed })
}
os_disk_name = coalesce(var.name_overrides.os_disk, "disk-${var.virtual_machine_config.hostname}-Os")
update_allowed = var.update_allowed ? "yes" : "no"
Expand Down
Loading

0 comments on commit 2c1bf9a

Please sign in to comment.