Some checks failed
Code Quality & Security Scan / TFLint (push) Successful in 18s
Code Quality & Security Scan / Terraform Destroy (push) Has been skipped
Code Quality & Security Scan / Tfsec Security Scan (push) Successful in 24s
Code Quality & Security Scan / Checkov Security Scan (push) Successful in 38s
Code Quality & Security Scan / Terraform Tests (push) Failing after 1m27s
Code Quality & Security Scan / SonarQube Trigger (push) Has been skipped
Code Quality & Security Scan / Terraform Init (push) Has been skipped
Code Quality & Security Scan / Terraform Apply (push) Has been skipped
- Removed assertions that check resource IDs (not available during plan) - Kept resource_pool_names output test (based on variables) - Added verification for expected resource group keys in output - Fixes: "Unknown condition value" error in verify_outputs test Resource IDs are only known after apply, so they can't be validated during plan phase. The remaining tests verify output structure using variable-based data that is available during plan.
167 lines
5.2 KiB
HCL
167 lines
5.2 KiB
HCL
# Test suite for vSphere Resource Groups module
|
|
# Tests resource pool creation, tagging, and configuration validation
|
|
|
|
# Test 1: Verify default resource groups are created correctly
|
|
run "verify_default_resource_groups" {
|
|
command = plan
|
|
|
|
# Verify that all default resource groups are present
|
|
assert {
|
|
condition = length(var.resource_groups) == 5
|
|
error_message = "Expected 5 default resource groups (kubernetes, docker, infra, databases, app-servers)"
|
|
}
|
|
|
|
# Verify resource pools are created for each resource group
|
|
assert {
|
|
condition = length(vsphere_resource_pool.resource_groups) == 5
|
|
error_message = "Should create 5 resource pools"
|
|
}
|
|
}
|
|
|
|
# Test 2: Validate shares mapping logic
|
|
run "validate_shares_mapping" {
|
|
command = plan
|
|
|
|
# Verify shares mapping is correctly defined
|
|
assert {
|
|
condition = alltrue([
|
|
local.shares_mapping["low"] == 500,
|
|
local.shares_mapping["normal"] == 1000,
|
|
local.shares_mapping["high"] == 2000
|
|
])
|
|
error_message = "Shares mapping values are incorrect"
|
|
}
|
|
}
|
|
|
|
# Test 3: Verify tag categories are created
|
|
run "verify_tag_categories" {
|
|
command = plan
|
|
|
|
# Environment tag category
|
|
assert {
|
|
condition = vsphere_tag_category.environment.name == "Environment"
|
|
error_message = "Environment tag category name should be 'Environment'"
|
|
}
|
|
|
|
assert {
|
|
condition = vsphere_tag_category.environment.cardinality == "SINGLE"
|
|
error_message = "Environment tag category should have SINGLE cardinality"
|
|
}
|
|
|
|
# Resource group type tag category
|
|
assert {
|
|
condition = vsphere_tag_category.resource_group_type.name == "ResourceGroupType"
|
|
error_message = "Resource group type tag category name should be 'ResourceGroupType'"
|
|
}
|
|
|
|
assert {
|
|
condition = vsphere_tag_category.resource_group_type.cardinality == "SINGLE"
|
|
error_message = "Resource group type tag category should have SINGLE cardinality"
|
|
}
|
|
}
|
|
|
|
# Test 4: Verify tags are created for each resource group
|
|
run "verify_resource_group_tags" {
|
|
command = plan
|
|
|
|
assert {
|
|
condition = length(vsphere_tag.resource_group) == 5
|
|
error_message = "Should create 5 resource group tags"
|
|
}
|
|
|
|
# Verify environment tag is created
|
|
assert {
|
|
condition = vsphere_tag.environment.name == var.environment
|
|
error_message = "Environment tag name should match environment variable"
|
|
}
|
|
}
|
|
|
|
# Test 5: Verify resource pool default configurations
|
|
run "verify_default_resource_pool_config" {
|
|
command = plan
|
|
|
|
# Check kubernetes resource group defaults
|
|
assert {
|
|
condition = vsphere_resource_pool.resource_groups["kubernetes"].cpu_reservation == 0
|
|
error_message = "Default CPU reservation should be 0"
|
|
}
|
|
|
|
assert {
|
|
condition = vsphere_resource_pool.resource_groups["kubernetes"].cpu_expandable == true
|
|
error_message = "CPU should be expandable by default"
|
|
}
|
|
|
|
assert {
|
|
condition = vsphere_resource_pool.resource_groups["kubernetes"].cpu_limit == -1
|
|
error_message = "Default CPU limit should be -1 (unlimited)"
|
|
}
|
|
|
|
assert {
|
|
condition = vsphere_resource_pool.resource_groups["kubernetes"].memory_reservation == 0
|
|
error_message = "Default memory reservation should be 0"
|
|
}
|
|
|
|
assert {
|
|
condition = vsphere_resource_pool.resource_groups["kubernetes"].memory_expandable == true
|
|
error_message = "Memory should be expandable by default"
|
|
}
|
|
|
|
assert {
|
|
condition = vsphere_resource_pool.resource_groups["kubernetes"].memory_limit == -1
|
|
error_message = "Default memory limit should be -1 (unlimited)"
|
|
}
|
|
}
|
|
|
|
# Test 6: Verify outputs structure is correct
|
|
run "verify_outputs" {
|
|
command = plan
|
|
|
|
# Resource pool names output (based on variables, available during plan)
|
|
assert {
|
|
condition = length(keys(output.resource_pool_names)) == 5
|
|
error_message = "Should output 5 resource pool names"
|
|
}
|
|
|
|
# Verify the output contains expected resource group keys
|
|
assert {
|
|
condition = alltrue([
|
|
contains(keys(output.resource_pool_names), "kubernetes"),
|
|
contains(keys(output.resource_pool_names), "docker"),
|
|
contains(keys(output.resource_pool_names), "infra"),
|
|
contains(keys(output.resource_pool_names), "databases"),
|
|
contains(keys(output.resource_pool_names), "app-servers")
|
|
])
|
|
error_message = "Output should contain all expected resource group keys"
|
|
}
|
|
}
|
|
|
|
# Test 7: Verify resource pool naming
|
|
run "verify_resource_pool_names" {
|
|
command = plan
|
|
|
|
assert {
|
|
condition = vsphere_resource_pool.resource_groups["kubernetes"].name == "Kubernetes"
|
|
error_message = "Kubernetes resource pool should be named 'Kubernetes'"
|
|
}
|
|
|
|
assert {
|
|
condition = vsphere_resource_pool.resource_groups["docker"].name == "Docker"
|
|
error_message = "Docker resource pool should be named 'Docker'"
|
|
}
|
|
|
|
assert {
|
|
condition = vsphere_resource_pool.resource_groups["infra"].name == "Infra"
|
|
error_message = "Infra resource pool should be named 'Infra'"
|
|
}
|
|
|
|
assert {
|
|
condition = vsphere_resource_pool.resource_groups["databases"].name == "Databases"
|
|
error_message = "Databases resource pool should be named 'Databases'"
|
|
}
|
|
|
|
assert {
|
|
condition = vsphere_resource_pool.resource_groups["app-servers"].name == "Application Servers"
|
|
error_message = "App Servers resource pool should be named 'Application Servers'"
|
|
}
|
|
}
|