|
| 1 | +name: "AWS NIC Apply" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + |
| 9 | +jobs: |
| 10 | + terraform_infra: |
| 11 | + name: "AWS Infra" |
| 12 | + runs-on: ubuntu-latest |
| 13 | + defaults: |
| 14 | + run: |
| 15 | + working-directory: ./infra |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + uses: actions/checkout@v3 |
| 19 | + |
| 20 | + - name: Setup Terraform |
| 21 | + uses: hashicorp/setup-terraform@v2 |
| 22 | + with: |
| 23 | + cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} |
| 24 | + |
| 25 | + - name: Setup Terraform Backend |
| 26 | + id: backend |
| 27 | + run: | |
| 28 | + cat > backend.tf << EOF |
| 29 | + terraform { |
| 30 | + cloud { |
| 31 | + organization = "${{ secrets.TF_CLOUD_ORGANIZATION }}" |
| 32 | + workspaces { |
| 33 | + name = "${{ secrets.TF_CLOUD_WORKSPACE_INFRA }}" |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + EOF |
| 38 | + |
| 39 | + - name: Terraform Init |
| 40 | + id: init |
| 41 | + run: terraform init |
| 42 | + |
| 43 | + - name: Terraform Validate |
| 44 | + id: validate |
| 45 | + run: terraform validate -no-color |
| 46 | + |
| 47 | + - name: Terraform Plan |
| 48 | + id: plan |
| 49 | + if: github.event_name == 'pull_request' |
| 50 | + run: terraform plan -no-color -input=false |
| 51 | + continue-on-error: true |
| 52 | + |
| 53 | + - uses: actions/github-script@v6 |
| 54 | + if: github.event_name == 'pull_request' |
| 55 | + env: |
| 56 | + PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" |
| 57 | + with: |
| 58 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + script: | |
| 60 | + const output = `#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` |
| 61 | + #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` |
| 62 | + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` |
| 63 | + <details><summary>Show Plan</summary> |
| 64 | + \`\`\`\n |
| 65 | + ${process.env.PLAN} |
| 66 | + \`\`\` |
| 67 | + </details> |
| 68 | + *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; |
| 69 | + github.rest.issues.createComment({ |
| 70 | + issue_number: context.issue.number, |
| 71 | + owner: context.repo.owner, |
| 72 | + repo: context.repo.repo, |
| 73 | + body: output |
| 74 | + }) |
| 75 | + - name: Terraform Plan Status |
| 76 | + if: steps.plan.outcome == 'failure' |
| 77 | + run: exit 1 |
| 78 | + |
| 79 | + - name: Terraform Apply |
| 80 | + if: github.ref == 'refs/heads/deploy-xcapi-nic' && github.event_name == 'push' |
| 81 | + run: terraform apply -auto-approve -input=false |
| 82 | + |
| 83 | + terraform_eks: |
| 84 | + name: "AWS EKS" |
| 85 | + runs-on: ubuntu-latest |
| 86 | + needs: terraform_infra |
| 87 | + defaults: |
| 88 | + run: |
| 89 | + working-directory: ./eks-cluster |
| 90 | + steps: |
| 91 | + - name: Checkout |
| 92 | + uses: actions/checkout@v3 |
| 93 | + |
| 94 | + - name: Setup Terraform |
| 95 | + uses: hashicorp/setup-terraform@v2 |
| 96 | + with: |
| 97 | + cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} |
| 98 | + |
| 99 | + - name: Setup Terraform Backend |
| 100 | + id: backend |
| 101 | + run: | |
| 102 | + cat > backend.tf << EOF |
| 103 | + terraform { |
| 104 | + cloud { |
| 105 | + organization = "${{ secrets.TF_CLOUD_ORGANIZATION }}" |
| 106 | + workspaces { |
| 107 | + name = "${{ secrets.TF_CLOUD_WORKSPACE_EKS }}" |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + EOF |
| 112 | +
|
| 113 | + - name: Terraform Init |
| 114 | + id: init |
| 115 | + run: terraform init |
| 116 | + |
| 117 | + - name: Terraform Validate |
| 118 | + id: validate |
| 119 | + run: terraform validate -no-color |
| 120 | + |
| 121 | + - name: Terraform Plan |
| 122 | + id: plan |
| 123 | + if: github.event_name == 'pull_request' |
| 124 | + run: terraform plan -no-color -input=false |
| 125 | + continue-on-error: true |
| 126 | + |
| 127 | + - uses: actions/github-script@v6 |
| 128 | + if: github.event_name == 'pull_request' |
| 129 | + env: |
| 130 | + PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" |
| 131 | + with: |
| 132 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 133 | + script: | |
| 134 | + const output = `#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` |
| 135 | + #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` |
| 136 | + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` |
| 137 | + <details><summary>Show Plan</summary> |
| 138 | + \`\`\`\n |
| 139 | + ${process.env.PLAN} |
| 140 | + \`\`\` |
| 141 | + </details> |
| 142 | + *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; |
| 143 | + github.rest.issues.createComment({ |
| 144 | + issue_number: context.issue.number, |
| 145 | + owner: context.repo.owner, |
| 146 | + repo: context.repo.repo, |
| 147 | + body: output |
| 148 | + }) |
| 149 | + - name: Terraform Plan Status |
| 150 | + if: steps.plan.outcome == 'failure' |
| 151 | + run: exit 1 |
| 152 | + |
| 153 | + - name: Terraform Apply |
| 154 | + if: github.ref == 'refs/heads/deploy-xcapi-nic' && github.event_name == 'push' |
| 155 | + run: terraform apply -auto-approve -input=false |
| 156 | + |
| 157 | + terraform_nic: |
| 158 | + name: "NGINX Ingress Controller" |
| 159 | + runs-on: ubuntu-latest |
| 160 | + needs: terraform_eks |
| 161 | + defaults: |
| 162 | + run: |
| 163 | + working-directory: ./nic |
| 164 | + steps: |
| 165 | + - name: Checkout |
| 166 | + uses: actions/checkout@v3 |
| 167 | + |
| 168 | + - name: Setup Terraform |
| 169 | + uses: hashicorp/setup-terraform@v2 |
| 170 | + with: |
| 171 | + cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} |
| 172 | + |
| 173 | + - name: Setup Terraform Backend |
| 174 | + id: backend |
| 175 | + run: | |
| 176 | + cat > backend.tf << EOF |
| 177 | + terraform { |
| 178 | + cloud { |
| 179 | + organization = "${{ secrets.TF_CLOUD_ORGANIZATION }}" |
| 180 | + workspaces { |
| 181 | + name = "${{ secrets.TF_CLOUD_WORKSPACE_NIC }}" |
| 182 | + } |
| 183 | + } |
| 184 | + } |
| 185 | + EOF |
| 186 | + echo ${{secrets.NGINX_JWT}} | base64 -d > nginx-repo.jwt |
| 187 | + - name: Terraform Init |
| 188 | + id: init |
| 189 | + run: terraform init |
| 190 | + |
| 191 | + - name: Terraform Validate |
| 192 | + id: validate |
| 193 | + run: terraform validate -no-color |
| 194 | + |
| 195 | + - name: Terraform Plan |
| 196 | + id: plan |
| 197 | + if: github.event_name == 'pull_request' |
| 198 | + run: terraform plan -no-color -input=false |
| 199 | + continue-on-error: true |
| 200 | + |
| 201 | + - uses: actions/github-script@v6 |
| 202 | + if: github.event_name == 'pull_request' |
| 203 | + env: |
| 204 | + PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" |
| 205 | + with: |
| 206 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 207 | + script: | |
| 208 | + const output = `#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` |
| 209 | + #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` |
| 210 | + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` |
| 211 | + <details><summary>Show Plan</summary> |
| 212 | + \`\`\`\n |
| 213 | + ${process.env.PLAN} |
| 214 | + \`\`\` |
| 215 | + </details> |
| 216 | + *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; |
| 217 | + github.rest.issues.createComment({ |
| 218 | + issue_number: context.issue.number, |
| 219 | + owner: context.repo.owner, |
| 220 | + repo: context.repo.repo, |
| 221 | + body: output |
| 222 | + }) |
| 223 | + - name: Terraform Plan Status |
| 224 | + if: steps.plan.outcome == 'failure' |
| 225 | + run: exit 1 |
| 226 | + |
| 227 | + - name: Terraform Apply |
| 228 | + if: github.ref == 'refs/heads/deploy-xcapi-nic' && github.event_name == 'push' |
| 229 | + run: terraform apply -auto-approve -input=false |
| 230 | + |
| 231 | + terraform_brewz: |
| 232 | + name: "Brewz Microservice" |
| 233 | + runs-on: ubuntu-latest |
| 234 | + needs: terraform_nic |
| 235 | + defaults: |
| 236 | + run: |
| 237 | + working-directory: ./brewz |
| 238 | + steps: |
| 239 | + - name: Checkout |
| 240 | + uses: actions/checkout@v3 |
| 241 | + |
| 242 | + - name: Setup Terraform |
| 243 | + uses: hashicorp/setup-terraform@v2 |
| 244 | + with: |
| 245 | + cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} |
| 246 | + |
| 247 | + - name: Setup Terraform Backend |
| 248 | + id: backend |
| 249 | + run: | |
| 250 | + cat > backend.tf << EOF |
| 251 | + terraform { |
| 252 | + cloud { |
| 253 | + organization = "${{ secrets.TF_CLOUD_ORGANIZATION }}" |
| 254 | + workspaces { |
| 255 | + name = "${{ secrets.TF_CLOUD_WORKSPACE_BREWZ }}" |
| 256 | + } |
| 257 | + } |
| 258 | + } |
| 259 | + EOF |
| 260 | + - name: Terraform Init |
| 261 | + id: init |
| 262 | + run: terraform init |
| 263 | + |
| 264 | + - name: Terraform Validate |
| 265 | + id: validate |
| 266 | + run: terraform validate -no-color |
| 267 | + |
| 268 | + - name: Terraform Plan |
| 269 | + id: plan |
| 270 | + if: github.event_name == 'pull_request' |
| 271 | + run: terraform plan -no-color -input=false |
| 272 | + continue-on-error: true |
| 273 | + |
| 274 | + - uses: actions/github-script@v6 |
| 275 | + if: github.event_name == 'pull_request' |
| 276 | + env: |
| 277 | + PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" |
| 278 | + with: |
| 279 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 280 | + script: | |
| 281 | + const output = `#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` |
| 282 | + #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` |
| 283 | + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` |
| 284 | + <details><summary>Show Plan</summary> |
| 285 | + \`\`\`\n |
| 286 | + ${process.env.PLAN} |
| 287 | + \`\`\` |
| 288 | + </details> |
| 289 | + *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; |
| 290 | + github.rest.issues.createComment({ |
| 291 | + issue_number: context.issue.number, |
| 292 | + owner: context.repo.owner, |
| 293 | + repo: context.repo.repo, |
| 294 | + body: output |
| 295 | + }) |
| 296 | + - name: Terraform Plan Status |
| 297 | + if: steps.plan.outcome == 'failure' |
| 298 | + run: exit 1 |
| 299 | + |
| 300 | + - name: Terraform Apply |
| 301 | + if: github.ref == 'refs/heads/deploy-xcapi-nic' && github.event_name == 'push' |
| 302 | + run: terraform apply -auto-approve -input=false |
0 commit comments