|
| 1 | +# ============================================================================= |
| 2 | +# GitHub Actions Workflow: Terraform and Ansible Validation |
| 3 | +# ============================================================================= |
| 4 | +# Description: Validates Terraform configurations and Ansible playbooks |
| 5 | +# for syntax, security, and best practices. |
| 6 | +# |
| 7 | +# Author: RAG Modulo Team |
| 8 | +# Last Updated: 2025-01-13 |
| 9 | +# Version: 1.0 |
| 10 | +# |
| 11 | +# Triggers: |
| 12 | +# - Pull requests to main branch |
| 13 | +# - Push to main branch |
| 14 | +# - Manual trigger |
| 15 | +# |
| 16 | +# ============================================================================= |
| 17 | + |
| 18 | +name: "Terraform & Ansible Validation" |
| 19 | + |
| 20 | +on: |
| 21 | + push: |
| 22 | + branches: [ main ] |
| 23 | + paths: |
| 24 | + - 'deployment/**' |
| 25 | + - '.github/workflows/terraform-ansible-validation.yml' |
| 26 | + pull_request: |
| 27 | + branches: [ main ] |
| 28 | + paths: |
| 29 | + - 'deployment/**' |
| 30 | + - '.github/workflows/terraform-ansible-validation.yml' |
| 31 | + workflow_dispatch: |
| 32 | + |
| 33 | +env: |
| 34 | + TF_VERSION: "1.6.0" |
| 35 | + ANSIBLE_VERSION: "8.0.0" |
| 36 | + |
| 37 | +jobs: |
| 38 | + # ========================================================================== |
| 39 | + # TERRAFORM VALIDATION |
| 40 | + # ========================================================================== |
| 41 | + |
| 42 | + terraform-validate: |
| 43 | + name: "🔍 Terraform Validation" |
| 44 | + runs-on: ubuntu-latest |
| 45 | + defaults: |
| 46 | + run: |
| 47 | + working-directory: ./deployment/terraform |
| 48 | + |
| 49 | + steps: |
| 50 | + - name: "📥 Checkout code" |
| 51 | + uses: actions/checkout@v4 |
| 52 | + with: |
| 53 | + fetch-depth: 0 |
| 54 | + |
| 55 | + - name: "📦 Setup Terraform" |
| 56 | + uses: hashicorp/setup-terraform@v3 |
| 57 | + with: |
| 58 | + terraform_version: ${{ env.TF_VERSION }} |
| 59 | + |
| 60 | + - name: "🔍 Terraform Format Check" |
| 61 | + run: | |
| 62 | + echo "Checking Terraform formatting..." |
| 63 | + terraform fmt -check -recursive |
| 64 | + echo "✅ Terraform formatting is correct" |
| 65 | +
|
| 66 | + - name: "🔍 Terraform Init" |
| 67 | + run: | |
| 68 | + echo "Initializing Terraform..." |
| 69 | + terraform init -backend=false |
| 70 | + echo "✅ Terraform initialized successfully" |
| 71 | +
|
| 72 | + - name: "🔍 Terraform Validate" |
| 73 | + run: | |
| 74 | + echo "Validating Terraform configurations..." |
| 75 | + terraform validate |
| 76 | + echo "✅ Terraform validation passed" |
| 77 | +
|
| 78 | + - name: "🔍 Terraform Plan (Dry Run)" |
| 79 | + run: | |
| 80 | + echo "Running Terraform plan (dry run)..." |
| 81 | + terraform plan -var-file="environments/ibm/dev.tfvars" -out=tfplan |
| 82 | + echo "✅ Terraform plan completed successfully" |
| 83 | + env: |
| 84 | + TF_VAR_ibmcloud_api_key: "dummy-key-for-validation" |
| 85 | + TF_VAR_container_registry_password: "dummy-password-for-validation" |
| 86 | + TF_VAR_database_password: "dummy-database-password-for-validation" |
| 87 | + TF_VAR_minio_password: "dummy-minio-password-for-validation" |
| 88 | + |
| 89 | + - name: "🔍 Security Scan (tfsec)" |
| 90 | + uses: aquasecurity/tfsec-action@v1.0.3 |
| 91 | + with: |
| 92 | + working_directory: ./deployment/terraform |
| 93 | + soft_fail: true |
| 94 | + |
| 95 | + - name: "🔍 Security Scan (checkov)" |
| 96 | + uses: bridgecrewio/checkov-action@master |
| 97 | + with: |
| 98 | + directory: ./deployment/terraform |
| 99 | + framework: terraform |
| 100 | + soft_fail: true |
| 101 | + |
| 102 | + # ========================================================================== |
| 103 | + # ANSIBLE VALIDATION |
| 104 | + # ========================================================================== |
| 105 | + |
| 106 | + ansible-validate: |
| 107 | + name: "🔍 Ansible Validation" |
| 108 | + runs-on: ubuntu-latest |
| 109 | + defaults: |
| 110 | + run: |
| 111 | + working-directory: ./deployment/ansible |
| 112 | + |
| 113 | + steps: |
| 114 | + - name: "📥 Checkout code" |
| 115 | + uses: actions/checkout@v4 |
| 116 | + with: |
| 117 | + fetch-depth: 0 |
| 118 | + |
| 119 | + - name: "📦 Setup Python" |
| 120 | + uses: actions/setup-python@v4 |
| 121 | + with: |
| 122 | + python-version: "3.11" |
| 123 | + |
| 124 | + - name: "📦 Install Ansible" |
| 125 | + run: | |
| 126 | + echo "Installing Ansible..." |
| 127 | + pip install ansible==${{ env.ANSIBLE_VERSION }} |
| 128 | + ansible --version |
| 129 | + echo "✅ Ansible installed successfully" |
| 130 | +
|
| 131 | + - name: "📦 Install Ansible Collections" |
| 132 | + run: | |
| 133 | + echo "Installing Ansible collections..." |
| 134 | + ansible-galaxy collection install -r requirements.yml |
| 135 | + echo "✅ Ansible collections installed successfully" |
| 136 | +
|
| 137 | + - name: "🔍 Ansible Syntax Check" |
| 138 | + run: | |
| 139 | + echo "Checking Ansible playbook syntax..." |
| 140 | + ansible-playbook --syntax-check playbooks/deploy-rag-modulo.yml |
| 141 | + ansible-playbook --syntax-check playbooks/backup-rag-modulo.yml |
| 142 | + echo "✅ Ansible syntax check passed" |
| 143 | +
|
| 144 | + - name: "🔍 Ansible Lint" |
| 145 | + run: | |
| 146 | + echo "Installing ansible-lint..." |
| 147 | + pip install ansible-lint |
| 148 | +
|
| 149 | + echo "Running ansible-lint..." |
| 150 | + ansible-lint playbooks/deploy-rag-modulo.yml |
| 151 | + ansible-lint playbooks/backup-rag-modulo.yml |
| 152 | + echo "✅ Ansible lint check passed" |
| 153 | +
|
| 154 | + - name: "🔍 Ansible Dry Run" |
| 155 | + run: | |
| 156 | + echo "Running Ansible dry run..." |
| 157 | + ansible-playbook --check --diff playbooks/deploy-rag-modulo.yml -i inventories/ibm/hosts.yml |
| 158 | + echo "✅ Ansible dry run completed successfully" |
| 159 | +
|
| 160 | + # ========================================================================== |
| 161 | + # DOCUMENTATION VALIDATION |
| 162 | + # ========================================================================== |
| 163 | + |
| 164 | + docs-validate: |
| 165 | + name: "📚 Documentation Validation" |
| 166 | + runs-on: ubuntu-latest |
| 167 | + |
| 168 | + steps: |
| 169 | + - name: "📥 Checkout code" |
| 170 | + uses: actions/checkout@v4 |
| 171 | + with: |
| 172 | + fetch-depth: 0 |
| 173 | + |
| 174 | + - name: "📦 Setup Python" |
| 175 | + uses: actions/setup-python@v4 |
| 176 | + with: |
| 177 | + python-version: "3.11" |
| 178 | + |
| 179 | + - name: "📦 Install MkDocs" |
| 180 | + run: | |
| 181 | + echo "Installing MkDocs and plugins..." |
| 182 | + pip install mkdocs mkdocs-material mkdocs-mermaid2-plugin |
| 183 | + echo "✅ MkDocs installed successfully" |
| 184 | +
|
| 185 | + - name: "🔍 MkDocs Build" |
| 186 | + run: | |
| 187 | + echo "Building documentation..." |
| 188 | + mkdocs build --strict |
| 189 | + echo "✅ Documentation build completed successfully" |
| 190 | +
|
| 191 | + - name: "🔍 MkDocs Lint" |
| 192 | + run: | |
| 193 | + echo "Installing mkdocs-lint..." |
| 194 | + pip install mkdocs-lint |
| 195 | +
|
| 196 | + echo "Running mkdocs-lint..." |
| 197 | + mkdocs-lint |
| 198 | + echo "✅ MkDocs lint check passed" |
| 199 | +
|
| 200 | + # ========================================================================== |
| 201 | + # INTEGRATION VALIDATION |
| 202 | + # ========================================================================== |
| 203 | + |
| 204 | + integration-validate: |
| 205 | + name: "🔗 Integration Validation" |
| 206 | + runs-on: ubuntu-latest |
| 207 | + needs: [terraform-validate, ansible-validate, docs-validate] |
| 208 | + |
| 209 | + steps: |
| 210 | + - name: "📥 Checkout code" |
| 211 | + uses: actions/checkout@v4 |
| 212 | + with: |
| 213 | + fetch-depth: 0 |
| 214 | + |
| 215 | + - name: "🔍 Validate File Structure" |
| 216 | + run: | |
| 217 | + echo "Validating deployment file structure..." |
| 218 | +
|
| 219 | + # Check required directories exist |
| 220 | + test -d "deployment/terraform/modules/ibm-cloud/code-engine" || exit 1 |
| 221 | + test -d "deployment/terraform/environments/ibm" || exit 1 |
| 222 | + test -d "deployment/ansible/playbooks" || exit 1 |
| 223 | + test -d "deployment/ansible/inventories" || exit 1 |
| 224 | + test -d "deployment/scripts" || exit 1 |
| 225 | +
|
| 226 | + # Check required files exist |
| 227 | + test -f "deployment/terraform/modules/ibm-cloud/code-engine/main.tf" || exit 1 |
| 228 | + test -f "deployment/terraform/modules/ibm-cloud/code-engine/variables.tf" || exit 1 |
| 229 | + test -f "deployment/terraform/environments/ibm/main.tf" || exit 1 |
| 230 | + test -f "deployment/terraform/environments/ibm/dev.tfvars" || exit 1 |
| 231 | + test -f "deployment/ansible/playbooks/deploy-rag-modulo.yml" || exit 1 |
| 232 | + test -f "deployment/ansible/playbooks/backup-rag-modulo.yml" || exit 1 |
| 233 | + test -f "deployment/ansible/requirements.yml" || exit 1 |
| 234 | + test -f "deployment/scripts/backup-rag-modulo.sh" || exit 1 |
| 235 | + test -f "deployment/scripts/restore-rag-modulo.sh" || exit 1 |
| 236 | +
|
| 237 | + # Check inventory files exist |
| 238 | + test -f "deployment/ansible/inventories/ibm/hosts.yml" || exit 1 |
| 239 | + test -f "deployment/ansible/inventories/aws/hosts.yml" || exit 1 |
| 240 | + test -f "deployment/ansible/inventories/azure/hosts.yml" || exit 1 |
| 241 | + test -f "deployment/ansible/inventories/gcp/hosts.yml" || exit 1 |
| 242 | +
|
| 243 | + echo "✅ File structure validation passed" |
| 244 | +
|
| 245 | + - name: "🔍 Validate Script Permissions" |
| 246 | + run: | |
| 247 | + echo "Validating script permissions..." |
| 248 | +
|
| 249 | + # Check scripts are executable |
| 250 | + test -x "deployment/scripts/backup-rag-modulo.sh" || exit 1 |
| 251 | + test -x "deployment/scripts/restore-rag-modulo.sh" || exit 1 |
| 252 | +
|
| 253 | + echo "✅ Script permissions validation passed" |
| 254 | +
|
| 255 | + - name: "🔍 Validate Documentation Links" |
| 256 | + run: | |
| 257 | + echo "Validating documentation links..." |
| 258 | +
|
| 259 | + # Check if referenced documentation exists |
| 260 | + if [ -f "docs/deployment/terraform-ansible-architecture.md" ]; then |
| 261 | + echo "✅ Main documentation exists" |
| 262 | + else |
| 263 | + echo "⚠️ Main documentation missing" |
| 264 | + fi |
| 265 | +
|
| 266 | + echo "✅ Documentation validation completed" |
| 267 | +
|
| 268 | + - name: "📊 Validation Summary" |
| 269 | + run: | |
| 270 | + echo "🎉 All validation checks completed successfully!" |
| 271 | + echo "" |
| 272 | + echo "✅ Terraform validation passed" |
| 273 | + echo "✅ Ansible validation passed" |
| 274 | + echo "✅ Documentation validation passed" |
| 275 | + echo "✅ Integration validation passed" |
| 276 | + echo "" |
| 277 | + echo "🚀 Deployment configuration is ready for use!" |
0 commit comments