Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disk name validation and other features #14

Merged
merged 35 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9ef664b
Added proximity placement group.
Jan 11, 2024
c14ce2d
Added accelerate networking.
Jan 11, 2024
8a7159e
Added changelog.
Jan 11, 2024
d9e7189
terraform-docs: automated action
github-actions[bot] Jan 12, 2024
cbb60c1
Change enable_accelerated_networking as nic config.
Jan 12, 2024
8911acf
Added azurerm_proximity_placement_group into azurerm_availability_set…
Jan 12, 2024
f3c0bfe
Fix merge.
Jan 12, 2024
503e0f5
terraform-docs: automated action
github-actions[bot] Jan 12, 2024
9ebbcf1
Delete allowed sizes in proximity placement group.
Jan 12, 2024
7854f52
Fix zone in data disk management.
Feb 22, 2024
2999442
Apply merge.
Feb 22, 2024
ba93288
Added new validation, adapt documentation.
Feb 22, 2024
2051aa3
Merge main.
Feb 22, 2024
c473f64
Delete duplicate line.
Feb 22, 2024
7064b3a
Adapted version.
Feb 22, 2024
86429bb
terraform-docs: automated action
github-actions[bot] Feb 22, 2024
ad0187b
Fix NSG object in nic.
Feb 23, 2024
995cac2
Fix logical name of the data disk.
Feb 23, 2024
d0f5f79
terraform-docs: automated action
github-actions[bot] Feb 23, 2024
958b4ec
Fixed documentation.
Feb 26, 2024
f7d0712
terraform-docs: automated action
github-actions[bot] Feb 26, 2024
a028622
Update and merge main branch.
Mar 25, 2024
c5d4015
Delete log anality and add hostname.
Mar 25, 2024
00b16ae
terraform-docs: automated action
github-actions[bot] Mar 25, 2024
0f25e7b
Adapt merge.
Aug 28, 2024
5cee7f2
Upgrade deprecated variable.
Aug 28, 2024
801bc2b
Added source resource id for disks.
Aug 29, 2024
7aeb589
Delete unnecesary tags.
Aug 29, 2024
74347eb
Include disk name validation, readme and changelog.
Aug 30, 2024
daa0b44
Update example.
Aug 30, 2024
cbf8808
terraform-docs: automated action
github-actions[bot] Aug 30, 2024
79589c8
Adapt os disk acceleration variable similar to vm linux module.
Aug 30, 2024
5f7229e
Changelog modified.
Aug 30, 2024
f6e00d4
Change readme after merge.
Aug 30, 2024
d5dd493
terraform-docs: automated action
github-actions[bot] Aug 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 42 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
# Changelog
All notable changes to this module will be documented in this file.


All notable changes to this module will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [5.0.0] - 2024-08-30

Added new features, variable change name and disk name validation.

### Added

Support:

- Support multiples network interfaces (NICs).
- NICs accelearate networking.
- Proximity placement group.
- Source resource ID for disk when create from copy or recovery.
- Disk validation of Logical Name can't contain a '-'

### Changed

- Variable name for os disk write_accelerator_enabled.

## [4.1.0] - 2024-05-07

### Added

- Set tags at all resources created in this repository that support tags
- Output of the created network interface

### Removed

- removed "ignore changes" for tags

## [4.0.0] - 2024-03-18

### Added

### Changed
### Changed

- fixed README title

### Removed
- removed old mma

- removed old mma

## [3.0.0] - 2024-02-08

Expand All @@ -33,13 +54,18 @@ and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.
Please note, that this upgrade makes the above properties managed by terraform. Therefore outside changes will be reverted by terraform from now on.

To upgrade to this new major version from `2.x` without changes to VMs (and therefore not supporting Update Manager) do:

1. Set variables
- `patch_assessment_mode="ImageDefault"`
- `patch_mode="AutomaticByOS"`
- `bypass_platform_safety_checks_on_user_schedule_enabled=false`
- `severity_group=""` if not already set
2. Run `terraform plan` and check if the values of the VM planned to change
- If the values of the properties are planned to change, use actual values instead of the above

- `patch_assessment_mode="ImageDefault"`
- `patch_mode="AutomaticByOS"`
- `bypass_platform_safety_checks_on_user_schedule_enabled=false`
- `severity_group=""` if not already set

1. Run `terraform plan` and check if the values of the VM planned to change


- If the values of the properties are planned to change, use actual values instead of the above

### Added

Expand Down Expand Up @@ -75,15 +101,15 @@ Apply a default naming convention for disks. To upgrade to the new version from
- allow override of OsDisk and Data Disk names

## [1.1.1] - 2023-10-17

### Added

### Changed

### Removed

- removed ignore_changes for tags in the windows virtual machine resource
- removed ignore_changes for tags in the windows virtual machine resource

### Fixed

- you can now add tags also after initial deployment, they are not ignored anymore
- you can now add tags also after initial deployment, they are not ignored anymore
99 changes: 73 additions & 26 deletions README.md

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions data_disk.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
resource "azurerm_managed_disk" "data_disk" {
for_each = var.data_disks
name = lookup(var.name_overrides.data_disks, each.key, "disk-${var.virtual_machine_config.hostname}-${each.key}")
location = var.virtual_machine_config.location
resource_group_name = var.resource_group_name
storage_account_type = each.value["storage_account_type"]
create_option = each.value["create_option"]
disk_size_gb = each.value["disk_size_gb"]
zone = var.virtual_machine_config.zone
for_each = var.data_disks
name = lookup(var.name_overrides.data_disks, each.key, "disk-${var.virtual_machine_config.hostname}-${each.key}")
location = var.virtual_machine_config.location
resource_group_name = var.resource_group_name
zone = var.virtual_machine_config.zone
storage_account_type = each.value["storage_account_type"]
create_option = each.value["create_option"]
source_resource_id = each.value["source_resource_id"]
disk_size_gb = each.value["disk_size_gb"]
on_demand_bursting_enabled = each.value["on_demand_bursting_enabled"]

tags = var.tags
lifecycle {
prevent_destroy = true
Expand All @@ -24,4 +27,4 @@ resource "azurerm_virtual_machine_data_disk_attachment" "data_disk" {
lifecycle {
prevent_destroy = true
}
}
}
22 changes: 0 additions & 22 deletions examples/advanced/.terraform.lock.hcl

This file was deleted.

22 changes: 11 additions & 11 deletions examples/advanced/locals.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
locals {
location = "West Europe"
resource_group_name = "rg-examples_vm_deploy-02"
virtual_network_name = "vnet-examples_vm_deploy-02"
subnet_name = "snet-examples_vm_deploy-02"
availability_set_name = "as-examples_vm_deploy-02"
managed_disk_name = "disk-examples_vm_deploy-02"
nsg_name = "nsg-examples_vm_deploy-02"
law_name = "law-examplesvmdeploy-02"
location = "West Europe"
resource_group_name = "rg-examples_vm_deploy-02"
virtual_network_name = "vnet-examples_vm_deploy-02"
subnet_name = "snet-examples_vm_deploy-02"
availability_set_name = "as-examples_vm_deploy-02"
proximity_placement_group_name = "ppg-examples_vm_deploy-02"
managed_disk_name = "examples_vm_deploy02"
nsg_name = "nsg-examples_vm_deploy-02"

nic = "nic-examples_vm_deploy-02"
nic_ip_config = "nic-ip-examples_vm_deploy-02"
public_ip = "pip-examples_vm_deploy-02"
nic = "nic-examples_vm_deploy-02"
nic_ip_config = "nic-ip-examples_vm_deploy-02"
public_ip = "pip-examples_vm_deploy-02"
virtual_machine = "vm-examples_vm_deploy-02"
}
92 changes: 69 additions & 23 deletions examples/advanced/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,36 @@ module "virtual_machine" {
allocation_method = "Static"
}
nic_config = {
private_ip = "10.0.0.16"
dns_servers = ["10.0.0.10", "10.0.0.11"]
nsg = azurerm_network_security_group.this
private_ip = "10.0.0.16"
dns_servers = ["10.0.0.10", "10.0.0.11"]
enable_accelerated_networking = true
nsg = azurerm_network_security_group.this
}
virtual_machine_config = {
hostname = "CUSTAPP007"
size = "Standard_B1s"
os_sku = "2022-datacenter-g2"
location = azurerm_resource_group.this.location
availability_set_id = azurerm_availability_set.this.id
os_version = "latest"
admin_username = "loc_admin"
os_disk_caching = "ReadWrite"
os_disk_storage_type = "Standard_LRS"
os_disk_size_gb = 128
os_disk_name = "DiskOverride"
timezone = "Azores Standard Time"
write_accelerator_enabled = false
hostname = "CUSTAPP007"
location = azurerm_resource_group.this.location
size = "Standard_B1s"
os_sku = "2022-datacenter-g2"
os_version = "latest"
os_disk_name = "DiskOverride"
os_disk_size_gb = 128
os_disk_caching = "ReadWrite"
os_disk_storage_type = "Standard_LRS"
os_disk_write_accelerator_enabled = false
availability_set_id = azurerm_availability_set.this.id
proximity_placement_group_id = azurerm_proximity_placement_group.this.id

admin_username = "loc_admin"

timezone = "Azores Standard Time"

patch_assessment_mode = "AutomaticByPlatform"
patch_mode = "AutomaticByPlatform"
bypass_platform_safety_checks_on_user_schedule_enabled = true

tags = {
"Environment" = "prd"
}
}
admin_password = "H3ll0W0rld!"
resource_group_name = azurerm_resource_group.this.name
Expand All @@ -41,9 +53,10 @@ module "virtual_machine" {
write_accelerator_enabled = false
}
}
tags = {
"example" = "examplevalue"
}

additional_network_interface_ids = [azurerm_network_interface.additional_nic_01.id]
severity_group = "01-third-tuesday-0200-XCSUFEDTG-reboot"
update_allowed = true

name_overrides = {
nic = local.nic
Expand All @@ -54,7 +67,10 @@ module "virtual_machine" {
"${local.managed_disk_name}" = "Override"
}
}
severity_group = "01-first-monday-2000-csu-reboot"

tags = {
"example" = "examplevalue"
}
}

resource "azurerm_resource_group" "this" {
Expand All @@ -77,9 +93,41 @@ resource "azurerm_subnet" "this" {
}

resource "azurerm_availability_set" "this" {
name = local.availability_set_name
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" {
Expand All @@ -99,5 +147,3 @@ resource "azurerm_network_security_group" "this" {
destination_address_prefix = "*"
}
}


3 changes: 1 addition & 2 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ locals {
}
os_disk_name = coalesce(var.name_overrides.os_disk, "disk-${var.virtual_machine_config.hostname}-Os")
update_allowed = var.update_allowed ? "yes" : "no"
}

}
26 changes: 13 additions & 13 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ resource "azurerm_public_ip" "this" {
}

resource "azurerm_network_interface" "this" {
name = local.nic.name
location = var.virtual_machine_config.location
resource_group_name = var.resource_group_name
dns_servers = var.nic_config.dns_servers
name = local.nic.name
location = var.virtual_machine_config.location
resource_group_name = var.resource_group_name
dns_servers = var.nic_config.dns_servers
accelerated_networking_enabled = var.nic_config.enable_accelerated_networking

ip_configuration {
name = local.nic.ip_config_name
Expand Down Expand Up @@ -40,9 +41,6 @@ resource "azurerm_windows_virtual_machine" "this" {
provision_vm_agent = true
admin_username = var.virtual_machine_config.admin_username
admin_password = var.admin_password
network_interface_ids = [
azurerm_network_interface.this.id,
]

os_disk {
name = local.os_disk_name
Expand All @@ -58,12 +56,14 @@ resource "azurerm_windows_virtual_machine" "this" {
version = var.virtual_machine_config.os_version
}

availability_set_id = var.virtual_machine_config.availability_set_id
zone = var.virtual_machine_config.zone
tags = local.virtual_machine.tags
timezone = var.virtual_machine_config.timezone
patch_mode = var.virtual_machine_config.patch_mode
patch_assessment_mode = var.virtual_machine_config.patch_assessment_mode
proximity_placement_group_id = var.virtual_machine_config.proximity_placement_group_id
network_interface_ids = concat([azurerm_network_interface.this.id], var.additional_network_interface_ids)
availability_set_id = var.virtual_machine_config.availability_set_id
zone = var.virtual_machine_config.zone
tags = local.virtual_machine.tags
timezone = var.virtual_machine_config.timezone
patch_mode = var.virtual_machine_config.patch_mode
patch_assessment_mode = var.virtual_machine_config.patch_assessment_mode
bypass_platform_safety_checks_on_user_schedule_enabled = var.virtual_machine_config.bypass_platform_safety_checks_on_user_schedule_enabled

lifecycle {
Expand Down
Loading