-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
2,067 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| .PHONY: all init validate test docs clean fmt pre-commit help | ||
|
|
||
| # Variables | ||
| SHELL := /bin/bash | ||
| TERRAFORM := terraform_current | ||
| EXAMPLES_DIR := examples | ||
| TEST_DIR := tests | ||
| MODULE_NAME := $(shell basename $(CURDIR)) | ||
|
|
||
| # Default target | ||
| all: init validate test | ||
|
|
||
| # Initialize Terraform | ||
| init: | ||
| @echo "Initializing Terraform..." | ||
| $(TERRAFORM) init -upgrade | ||
| @for dir in $(EXAMPLES_DIR)/*/ ; do \ | ||
| if [ -d "$$dir" ]; then \ | ||
| echo "Initializing $$dir..."; \ | ||
| cd "$$dir" && $(TERRAFORM) init -upgrade && cd ../..; \ | ||
| fi \ | ||
| done | ||
|
|
||
| # Format Terraform code | ||
| fmt: | ||
| @echo "Formatting Terraform code..." | ||
| $(TERRAFORM) fmt -recursive | ||
| @for dir in $(EXAMPLES_DIR)/*/ ; do \ | ||
| if [ -d "$$dir" ]; then \ | ||
| echo "Formatting $$dir..."; \ | ||
| cd "$$dir" && $(TERRAFORM) fmt -recursive && cd ../..; \ | ||
| fi \ | ||
| done | ||
|
|
||
| # Validate Terraform code | ||
| validate: fmt | ||
| @echo "Validating Terraform code..." | ||
| $(TERRAFORM) validate | ||
| @for dir in $(EXAMPLES_DIR)/*/ ; do \ | ||
| if [ -d "$$dir" ]; then \ | ||
| echo "Validating $$dir..."; \ | ||
| cd "$$dir" && $(TERRAFORM) validate && cd ../..; \ | ||
| fi \ | ||
| done | ||
|
|
||
| # Run tflint | ||
| lint: | ||
| @echo "Running tflint..." | ||
| tflint | ||
| @for dir in $(EXAMPLES_DIR)/*/ ; do \ | ||
| if [ -d "$$dir" ]; then \ | ||
| echo "Linting $$dir..."; \ | ||
| cd "$$dir" && tflint && cd ../..; \ | ||
| fi \ | ||
| done | ||
|
|
||
| # Run tests | ||
| test: init-go | ||
| @echo "Running tests..." | ||
| cd $(TEST_DIR) && go test -v ./unit/... ./integration/... -timeout 30m | ||
|
|
||
| # Initialize Go modules | ||
| init-go: | ||
| @echo "Initializing Go modules..." | ||
| cd $(TEST_DIR) && go mod tidy | ||
|
|
||
| # Generate documentation | ||
| docs: | ||
| @echo "Generating documentation..." | ||
| terraform-docs markdown table --output-file README.md --output-mode inject . | ||
| @for dir in $(EXAMPLES_DIR)/*/ ; do \ | ||
| if [ -d "$$dir" ]; then \ | ||
| echo "Generating docs for $$dir..."; \ | ||
| terraform-docs markdown table --output-file README.md --output-mode inject "$$dir"; \ | ||
| fi \ | ||
| done | ||
|
|
||
| # Clean up | ||
| clean: | ||
| @echo "Cleaning up..." | ||
| find . -type d -name ".terraform" -exec rm -rf {} + | ||
| find . -type f -name ".terraform.lock.hcl" -delete | ||
| find . -type f -name "terraform-debug..tfstate*" -delete | ||
| find . -type f -name "*.log" -delete | ||
|
|
||
| # Run pre-commit hooks | ||
| pre-commit: | ||
| @echo "Running pre-commit hooks..." | ||
| pre-commit run --all-files | ||
|
|
||
| # Version management | ||
| version: | ||
| @if [ -z "$(VERSION)" ]; then \ | ||
| echo "Please specify VERSION=x.x.x"; \ | ||
| exit 1; \ | ||
| fi | ||
| @echo "Updating version to $(VERSION)..." | ||
| sed -i 's/module_version = "[0-9]*\.[0-9]*\.[0-9]*"/module_version = "$(VERSION)"/' version.tf | ||
| git add version.tf | ||
| git commit -m "🔖 chore(release): v$(VERSION)" | ||
| git tag -a "v$(VERSION)" -m "Version $(VERSION)" | ||
|
|
||
| # Help | ||
| help: | ||
| @echo "Available targets:" | ||
| @echo " all : Run init, validate, and test" | ||
| @echo " init : Initialize Terraform" | ||
| @echo " fmt : Format Terraform code" | ||
| @echo " validate : Validate Terraform code" | ||
| @echo " lint : Run tflint" | ||
| @echo " test : Run unit and integration tests" | ||
| @echo " docs : Generate documentation" | ||
| @echo " clean : Clean up Terraform files" | ||
| @echo " pre-commit : Run pre-commit hooks" | ||
| @echo " version : Update module version (usage: make version VERSION=x.x.x)" | ||
| @echo " help : Show this help message" | ||
| @echo " init-go : Initialize Go modules for testing" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| module "eks-configuration" { | ||
| source = "../.." | ||
|
|
||
| cluster_name = var.cluster_name | ||
| operators_ns = var.operators_ns | ||
| vpc_id = var.vpc_id | ||
| subnets = var.subnets | ||
| tags = var.tags | ||
| security_group_all_worker_mgmt_id = var.security_group_all_worker_mgmt_id | ||
| release_version = var.release_version | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Testing tfmod-eks-configuration | ||
|
|
||
| This directory contains tests for the EKS configuration module. | ||
|
|
||
| ## Test Structure | ||
|
|
||
| ``` | ||
| tests/ | ||
| ├── fixtures/ # Test configurations | ||
| │ ├── complete/ # Complete example for integration tests | ||
| │ └── validation/ # Validation test cases | ||
| ├── integration/ # Integration tests | ||
| └── unit/ # Unit tests | ||
| ``` | ||
|
|
||
| ## Running Tests | ||
|
|
||
| ### Prerequisites | ||
| - Go 1.16 or later | ||
| - AWS credentials configured | ||
| - kubectl configured | ||
| - Existing EKS cluster | ||
|
|
||
| ### Unit Tests | ||
| Test input validation and parameter checking: | ||
| ```bash | ||
| cd tests/unit | ||
| go test -v ./... | ||
| ``` | ||
|
|
||
| ### Integration Tests | ||
| Test actual resource creation and configuration: | ||
| ```bash | ||
| cd tests/integration | ||
| go test -v ./... -timeout 30m | ||
| ``` | ||
|
|
||
| ## Test Cases | ||
|
|
||
| ### Unit Tests | ||
| - Input validation for VPC ID format | ||
| - Subnet count validation | ||
| - Namespace name validation | ||
| - Tag validation | ||
|
|
||
| ### Integration Tests | ||
| - Storage class creation and configuration | ||
| - EFS filesystem provisioning | ||
| - Network policy application | ||
| - Operator namespace setup | ||
|
|
||
| ## Adding New Tests | ||
|
|
||
| 1. Create test fixtures in `fixtures/` | ||
| 2. Add test cases in `unit/` or `integration/` | ||
| 3. Update test documentation | ||
| 4. Run tests locally before committing | ||
|
|
||
| ## Cleanup | ||
|
|
||
| The test framework automatically cleans up resources, but you can manually run: | ||
| ```bash | ||
| cd tests/fixtures/complete | ||
| terraform destroy | ||
| ``` |
Oops, something went wrong.