# Test suite for custom resource group configurations # Tests override functionality and custom values # Test 1: Custom resource group with specific CPU/Memory settings run "custom_resource_group_config" { command = plan variables { resource_groups = { high_priority = { name = "High Priority" cpu_reservation = 2000 cpu_limit = 4000 cpu_shares = "high" memory_reservation = 4096 memory_limit = 8192 memory_shares = "high" } } } # Verify custom CPU configuration assert { condition = vsphere_resource_pool.resource_groups["high_priority"].cpu_reservation == 2000 error_message = "CPU reservation should be 2000 MHz" } assert { condition = vsphere_resource_pool.resource_groups["high_priority"].cpu_limit == 4000 error_message = "CPU limit should be 4000 MHz" } assert { condition = vsphere_resource_pool.resource_groups["high_priority"].cpu_shares == 2000 error_message = "CPU shares should be 2000 (high priority)" } # Verify custom memory configuration assert { condition = vsphere_resource_pool.resource_groups["high_priority"].memory_reservation == 4096 error_message = "Memory reservation should be 4096 MB" } assert { condition = vsphere_resource_pool.resource_groups["high_priority"].memory_limit == 8192 error_message = "Memory limit should be 8192 MB" } assert { condition = vsphere_resource_pool.resource_groups["high_priority"].memory_shares == 2000 error_message = "Memory shares should be 2000 (high priority)" } } # Test 2: Low priority resource group run "low_priority_resource_group" { command = plan variables { resource_groups = { low_priority = { name = "Low Priority" cpu_shares = "low" memory_shares = "low" } } } # Verify low priority shares assert { condition = vsphere_resource_pool.resource_groups["low_priority"].cpu_shares == 500 error_message = "CPU shares should be 500 (low priority)" } assert { condition = vsphere_resource_pool.resource_groups["low_priority"].memory_shares == 500 error_message = "Memory shares should be 500 (low priority)" } } # Test 3: Non-expandable resource group (fixed resources) run "non_expandable_resource_group" { command = plan variables { resource_groups = { fixed_resources = { name = "Fixed Resources" cpu_reservation = 1000 cpu_expandable = false cpu_limit = 1000 memory_reservation = 2048 memory_expandable = false memory_limit = 2048 } } } # Verify non-expandable configuration assert { condition = vsphere_resource_pool.resource_groups["fixed_resources"].cpu_expandable == false error_message = "CPU should not be expandable" } assert { condition = vsphere_resource_pool.resource_groups["fixed_resources"].memory_expandable == false error_message = "Memory should not be expandable" } # Verify reservation matches limit (fixed allocation) assert { condition = ( vsphere_resource_pool.resource_groups["fixed_resources"].cpu_reservation == vsphere_resource_pool.resource_groups["fixed_resources"].cpu_limit ) error_message = "For fixed resources, CPU reservation should equal CPU limit" } assert { condition = ( vsphere_resource_pool.resource_groups["fixed_resources"].memory_reservation == vsphere_resource_pool.resource_groups["fixed_resources"].memory_limit ) error_message = "For fixed resources, memory reservation should equal memory limit" } } # Test 4: Multiple custom resource groups run "multiple_custom_resource_groups" { command = plan variables { resource_groups = { web_tier = { name = "Web Tier" cpu_shares = "high" } app_tier = { name = "Application Tier" cpu_shares = "normal" } db_tier = { name = "Database Tier" cpu_shares = "high" } } } # Verify correct number of resource groups assert { condition = length(vsphere_resource_pool.resource_groups) == 3 error_message = "Should create exactly 3 resource pools" } # Verify each resource group is created assert { condition = alltrue([ contains(keys(vsphere_resource_pool.resource_groups), "web_tier"), contains(keys(vsphere_resource_pool.resource_groups), "app_tier"), contains(keys(vsphere_resource_pool.resource_groups), "db_tier") ]) error_message = "All three custom resource groups should be created" } # Verify correct share levels assert { condition = ( vsphere_resource_pool.resource_groups["web_tier"].cpu_shares == 2000 && vsphere_resource_pool.resource_groups["app_tier"].cpu_shares == 1000 && vsphere_resource_pool.resource_groups["db_tier"].cpu_shares == 2000 ) error_message = "Share levels should be correctly mapped (high=2000, normal=1000)" } } # Test 5: Environment-specific configuration run "environment_specific_config" { command = plan variables { environment = "dev" resource_groups = { development = { name = "Development Resources" } } } # Verify environment tag assert { condition = vsphere_tag.environment.name == "dev" error_message = "Environment tag should be 'dev'" } # Verify environment tag description assert { condition = vsphere_tag.environment.description == "Environment tag for dev" error_message = "Environment tag description should reference 'dev'" } } # Test 6: Edge case - single resource group run "single_resource_group" { command = plan variables { resource_groups = { production = { name = "Production Only" } } } assert { condition = length(vsphere_resource_pool.resource_groups) == 1 error_message = "Should create exactly 1 resource pool" } assert { condition = length(vsphere_tag.resource_group) == 1 error_message = "Should create exactly 1 resource group tag" } }