Skip to content

Commit

Permalink
added tagging for the resources
Browse files Browse the repository at this point in the history
  • Loading branch information
QBY-ChristianHartmann committed May 7, 2024
1 parent c046a22 commit 4f95803
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 61 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.

## [Unreleased]

## [4.1.0] - 2024-05-07

### Added
- Set tags at all resources created in this repository that support tags

### Removed
- removed "ignore changes" for tags

## [4.0.0] - 2024-03-18

### Added
Expand Down
4 changes: 1 addition & 3 deletions data_disk.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ resource "azurerm_managed_disk" "data_disk" {
create_option = each.value["create_option"]
disk_size_gb = each.value["disk_size_gb"]
zone = var.virtual_machine_config.zone
tags = var.tags
lifecycle {
prevent_destroy = true
ignore_changes = [
tags
]
}
}

Expand Down
28 changes: 14 additions & 14 deletions examples/advanced/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 15 additions & 17 deletions examples/advanced/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@ module "virtual_machine" {
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"

tags = {
"Environment" = "prd"
}
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
}
admin_password = "H3ll0W0rld!"
Expand All @@ -45,7 +41,9 @@ module "virtual_machine" {
write_accelerator_enabled = false
}
}

tags = {
"example" = "examplevalue"
}

name_overrides = {
nic = local.nic
Expand Down
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.virtual_machine_config.tags, { "Severity Group Monthly" = var.severity_group }, { "Update allowed" = local.update_allowed })
tags = merge(var.tags, { "Severity Group Monthly" = var.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
12 changes: 2 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ resource "azurerm_public_ip" "this" {
location = var.virtual_machine_config.location
allocation_method = var.public_ip_config.allocation_method

lifecycle {
ignore_changes = [
tags
]
}
tags = var.tags
}

resource "azurerm_network_interface" "this" {
Expand All @@ -26,11 +22,7 @@ resource "azurerm_network_interface" "this" {
public_ip_address_id = var.public_ip_config.enabled ? azurerm_public_ip.this[0].id : null
}

lifecycle {
ignore_changes = [
tags
]
}
tags = var.tags
}

resource "azurerm_network_interface_security_group_association" "this" {
Expand Down
1 change: 1 addition & 0 deletions tests/names/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module "virtual_machine" {
os_version = "latest"
os_disk_storage_type = "Standard_LRS"
}
severity_group = "01-first-monday-2000-csu-reboot"
admin_password = "H3ll0W0rld!"
resource_group_name = azurerm_resource_group.this.name
subnet = azurerm_subnet.this
Expand Down
37 changes: 21 additions & 16 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,21 @@ variable "subnet" {

variable "virtual_machine_config" {
type = object({
hostname = string
size = string
os_sku = string
location = string
availability_set_id = optional(string)
zone = optional(string)
os_version = optional(string, "latest")
admin_username = optional(string, "loc_sysadmin")
os_disk_caching = optional(string, "ReadWrite")
os_disk_storage_type = optional(string, "StandardSSD_LRS")
os_disk_size_gb = optional(number)
tags = optional(map(string))
timezone = optional(string, "UTC")
write_accelerator_enabled = optional(bool, false)
patch_assessment_mode = optional(string, "AutomaticByPlatform")
patch_mode = optional(string, "AutomaticByPlatform")
hostname = string
size = string
os_sku = string
location = string
availability_set_id = optional(string)
zone = optional(string)
os_version = optional(string, "latest")
admin_username = optional(string, "loc_sysadmin")
os_disk_caching = optional(string, "ReadWrite")
os_disk_storage_type = optional(string, "StandardSSD_LRS")
os_disk_size_gb = optional(number)
timezone = optional(string, "UTC")
write_accelerator_enabled = optional(bool, false)
patch_assessment_mode = optional(string, "AutomaticByPlatform")
patch_mode = optional(string, "AutomaticByPlatform")
bypass_platform_safety_checks_on_user_schedule_enabled = optional(bool, true)
})
validation {
Expand Down Expand Up @@ -164,4 +163,10 @@ variable "name_overrides" {
default = {}
}

variable "tags" {
type = map(string)
description = "A mapping of tags to add to the resources created in this module"
default = {}
}


0 comments on commit 4f95803

Please sign in to comment.