Patrick de Ruiter 560200bb3c
Initial commit: Terraform vSphere resource groups module
- Add vSphere resource pool management
- Configure CPU and memory allocation controls
- Implement tagging system for organization
- Add comprehensive documentation
2025-11-01 06:18:59 +01:00

64 lines
1.7 KiB
HCL

locals {
shares_mapping = {
"low" = 500
"normal" = 1000
"high" = 2000
}
}
resource "vsphere_resource_pool" "resource_groups" {
for_each = var.resource_groups
name = each.value.name
parent_resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id
cpu_reservation = each.value.cpu_reservation
cpu_expandable = each.value.cpu_expandable
cpu_limit = each.value.cpu_limit
cpu_shares = lookup(local.shares_mapping, each.value.cpu_shares, 1000)
memory_reservation = each.value.memory_reservation
memory_expandable = each.value.memory_expandable
memory_limit = each.value.memory_limit
memory_shares = lookup(local.shares_mapping, each.value.memory_shares, 1000)
tags = [
vsphere_tag.environment.id,
vsphere_tag.resource_group[each.key].id
]
}
resource "vsphere_tag_category" "environment" {
name = "Environment"
description = "Environment category for resource groups"
cardinality = "SINGLE"
associable_types = [
"ResourcePool",
]
}
resource "vsphere_tag" "environment" {
name = var.environment
category_id = vsphere_tag_category.environment.id
description = "Environment tag for ${var.environment}"
}
resource "vsphere_tag_category" "resource_group_type" {
name = "ResourceGroupType"
description = "Resource group type category"
cardinality = "SINGLE"
associable_types = [
"ResourcePool",
]
}
resource "vsphere_tag" "resource_group" {
for_each = var.resource_groups
name = each.key
category_id = vsphere_tag_category.resource_group_type.id
description = "Resource group tag for ${each.value.name}"
}