-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
108 lines (90 loc) · 4.04 KB
/
Copy pathMakefile
File metadata and controls
108 lines (90 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
.PHONY: help setup install-hooks install-tools fmt lint validate security check plan apply destroy clean
# Default target
help: ## Show this help message
@echo "Mattermost Ops Kit Infrastructure - Development Commands"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
setup: install-tools install-hooks ## Complete development environment setup
install-tools: ## Install required tools (OpenTofu, pre-commit, linters)
@echo "Installing required tools..."
@command -v tofu >/dev/null 2>&1 || { echo "Please install OpenTofu: https://opentofu.org/docs/intro/install/"; exit 1; }
@command -v pre-commit >/dev/null 2>&1 || pip install pre-commit
@command -v tflint >/dev/null 2>&1 || { echo "Installing TFLint..."; curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash; }
@command -v trivy >/dev/null 2>&1 || { echo "Installing Trivy..."; brew install trivy || { echo "Please install Trivy manually: https://aquasecurity.github.io/trivy/"; exit 1; }; }
@command -v checkov >/dev/null 2>&1 || pip install checkov
@command -v shellcheck >/dev/null 2>&1 || { echo "Please install shellcheck: https://github.com/koalaman/shellcheck#installing"; }
@command -v shfmt >/dev/null 2>&1 || { echo "Please install shfmt: https://github.com/mvdan/sh#shfmt"; }
@cd tofu && tflint --init
@echo "✓ Tools installed successfully"
install-hooks: ## Install pre-commit hooks
@echo "Installing pre-commit hooks..."
@pre-commit install
@pre-commit install --hook-type commit-msg
@echo "✓ Pre-commit hooks installed"
fmt: ## Format all code (OpenTofu, shell scripts)
@echo "Formatting OpenTofu files..."
@cd tofu && tofu fmt -recursive
@echo "Formatting shell scripts..."
@shfmt -i 2 -ci -w tofu/user-data.sh
@echo "✓ Formatting complete"
lint: ## Run all linters
@echo "Running TFLint..."
@cd tofu && tflint --recursive
@echo "Running ShellCheck..."
@shellcheck tofu/user-data.sh
@echo "✓ Linting complete"
validate: ## Validate OpenTofu configuration
@echo "Initializing OpenTofu..."
@cd tofu && tofu init -backend=false
@echo "Validating OpenTofu..."
@cd tofu && tofu validate
@echo "✓ Validation complete"
security: ## Run security scans (Trivy, Checkov)
@echo "Running Trivy..."
@cd tofu && trivy config --exit-code 1 .
@echo "Running Checkov..."
@cd tofu && checkov -d . --quiet --framework terraform
@echo "✓ Security scan complete"
check: fmt lint validate security ## Run all checks (format, lint, validate, security)
@echo "✓ All checks passed"
pre-commit: ## Run pre-commit on all files
@echo "Running pre-commit hooks..."
@pre-commit run --all-files
@echo "✓ Pre-commit checks complete"
pre-commit-update: ## Update pre-commit hooks to latest versions
@echo "Updating pre-commit hooks..."
@pre-commit autoupdate
@echo "✓ Pre-commit hooks updated"
# OpenTofu commands
init: ## Initialize OpenTofu
@cd tofu && tofu init
plan: ## Create OpenTofu execution plan
@cd tofu && tofu plan
apply: ## Apply OpenTofu changes
@cd tofu && tofu apply
destroy: ## Destroy OpenTofu resources (WARNING: This will delete everything!)
@cd tofu && tofu destroy
# Utility commands
clean: ## Clean temporary files and caches
@echo "Cleaning temporary files..."
@find . -type d -name ".terraform" -exec rm -rf {} + 2>/dev/null || true
@find . -type f -name "*.tfstate" -delete 2>/dev/null || true
@find . -type f -name "*.tfstate.backup" -delete 2>/dev/null || true
@find . -type f -name ".terraform.lock.hcl" -delete 2>/dev/null || true
@rm -rf .tflint.d/
@echo "✓ Cleanup complete"
docs: ## Generate OpenTofu documentation
@echo "Generating OpenTofu documentation..."
@cd tofu && terraform-docs markdown table --output-file README.md --output-mode inject .
@echo "✓ Documentation generated"
test-ci: ## Run CI tests locally
@echo "Running CI tests locally..."
@make fmt
@make lint
@make validate
@make security
@make pre-commit
@echo "✓ All CI tests passed"