Some checks failed
Code Quality & Security Scan / TFLint (push) Successful in 24s
Code Quality & Security Scan / Terraform Destroy (push) Has been skipped
Code Quality & Security Scan / Tfsec Security Scan (push) Successful in 29s
Code Quality & Security Scan / Checkov Security Scan (push) Successful in 44s
Code Quality & Security Scan / Terraform Tests (push) Failing after 35s
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
- Implemented 21 test cases across 3 test suites: * resource_groups.tftest.hcl (7 tests): Default behavior and validation * custom_configuration.tftest.hcl (6 tests): Custom configurations * variable_validation.tftest.hcl (8 tests): Input validation and edge cases - Updated CI/CD pipeline (.gitea/workflows/sonarqube.yaml): * Added terraform-test job with format check and test execution * Generates and uploads test reports (30-day retention) * Runs after security scanning, before deployment - Added comprehensive documentation: * TESTING.md: Complete testing guide with best practices * TEST_SUMMARY.md: Implementation summary and statistics * TESTING_QUICK_START.md: Quick reference for developers * TESTING_WORKFLOW.md: Visual workflow diagrams - Updated existing documentation: * README.md: Added testing section with examples * CLAUDE.md: Added test commands to workflow - Test coverage includes: * Resource creation and configuration validation * Tag category and tag management * Variable validation and defaults * Custom configurations and overrides * Edge cases and error handling * Output generation verification Tests use mock credentials for infrastructure-independent execution. Requires Terraform >= 1.6.0 for native testing framework.
105 lines
2.8 KiB
Markdown
105 lines
2.8 KiB
Markdown
# Terraform vSphere Resource Groups Module
|
|
|
|
This Terraform module manages vSphere resource pools (resource groups) with CPU/memory allocation controls and integrated tagging for organization and management.
|
|
|
|
## Purpose
|
|
|
|
Creates and manages vSphere resource pools with configurable resource allocation policies, reservations, limits, and shares. Includes automated tagging for environment and resource group classification.
|
|
|
|
## What It Does
|
|
|
|
1. Creates resource pools under vSphere cluster
|
|
2. Configures CPU reservations, limits, and shares
|
|
3. Configures memory reservations, limits, and shares
|
|
4. Creates tag categories for Environment and ResourceGroupType
|
|
5. Applies tags to resource pools for organization
|
|
|
|
## Usage
|
|
|
|
```hcl
|
|
module "vsphere_resource_groups" {
|
|
source = "./terraform-vsphere-resourcegroups"
|
|
|
|
datacenter = "DC1"
|
|
cluster_name = "Cluster01"
|
|
environment = "prod"
|
|
|
|
role_id = var.vault_role_id
|
|
secret_id = var.vault_secret_id
|
|
|
|
resource_groups = {
|
|
kubernetes = {
|
|
name = "Kubernetes"
|
|
cpu_reservation = 4000
|
|
cpu_shares = "high"
|
|
memory_reservation = 8192
|
|
memory_shares = "high"
|
|
}
|
|
docker = {
|
|
name = "Docker"
|
|
cpu_shares = "normal"
|
|
memory_shares = "normal"
|
|
}
|
|
infra = {
|
|
name = "Infrastructure"
|
|
cpu_shares = "low"
|
|
memory_shares = "low"
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## Key Features
|
|
|
|
- **Resource Allocation**: CPU and memory reservations, limits, shares
|
|
- **Shares Mapping**: Automatic conversion of low/normal/high to vSphere values (500/1000/2000)
|
|
- **Tagging System**: Environment and resource group type tags
|
|
- **Flexible Configuration**: Optional parameters with sensible defaults
|
|
- **Expandable Resources**: Allow resources to grow beyond reservations
|
|
|
|
## Default Resource Groups
|
|
|
|
- **Kubernetes**: For Kubernetes infrastructure
|
|
- **Docker**: For Docker containers
|
|
- **Infra**: For infrastructure services
|
|
|
|
## Prerequisites
|
|
|
|
- VMware vSphere with compute cluster
|
|
- Vault with vSphere credentials
|
|
- Terraform >= 1.6.0 (required for testing framework)
|
|
|
|
## Testing
|
|
|
|
This module includes comprehensive Terraform tests to ensure code quality and correctness. Tests cover:
|
|
|
|
- Default resource group creation
|
|
- Custom configuration scenarios
|
|
- Variable validation and edge cases
|
|
- Tag management
|
|
- Output generation
|
|
|
|
### Running Tests Locally
|
|
|
|
```bash
|
|
# Run all tests
|
|
terraform test
|
|
|
|
# Run tests with verbose output
|
|
terraform test -verbose
|
|
|
|
# Run specific test file
|
|
terraform test -filter=tests/resource_groups.tftest.hcl
|
|
```
|
|
|
|
For detailed testing documentation, see [TESTING.md](TESTING.md).
|
|
|
|
### CI/CD Integration
|
|
|
|
Tests are automatically executed in the CI/CD pipeline:
|
|
1. Code formatting validation (`terraform fmt -check`)
|
|
2. Test execution with verbose output
|
|
3. Test report generation and artifact upload
|
|
|
|
The test job runs after security scanning and before infrastructure deployment.
|