From 77b80324b73c8ac116d3cb71464939c243cd2728 Mon Sep 17 00:00:00 2001 From: LamSut Date: Wed, 16 Oct 2024 10:07:23 +0700 Subject: [PATCH] beta --- .github/workflows/main.yml | 69 ++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 547f94f..9c332be 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,32 +1,51 @@ -name: Terraform AWS +name: Terraform CI/CD on: push: - branches: - - main + branches: [ main ] jobs: - tf_fmt: - name: Deploy Site - runs-on: ubuntu-latest + terraform: + runs-on: ubuntu-latest + + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }} + AWS_DEFAULT_REGION: "us-east-1" + steps: + - uses: actions/checkout@v3 + + - name: Use Terraform Cache + uses: actions/cache@v3 + with: + path: ~/.terraform + key: ${{ runner.os }}-terraform-${{ hashFiles('**/.terraform.lock') }} + restore-keys: | + ${{ runner.os }}-terraform- + + - name: Install Terraform + uses: hashicorp/setup-terraform@v2 + + - name: Terraform Version + run: terraform --version + + - name: Initialize Terraform + run: terraform init + + - name: Terraform Validate + run: terraform validate + + - id: plan + name: Terraform Plan + run: terraform plan -out=planfile + + - name: Upload Plan (Optional) + uses: actions/upload-artifact@v3 + with: + name: planfile + path: planfile + if: success() - - name: Checkout Repo - uses: actions/checkout@v1 - - - name: Terraform Init - uses: hashicorp/terraform-github-actions/init@v0.4.0 - env: - TF_ACTION_WORKING_DIR: 'terraform' - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - - - name: Terraform Validate - uses: hashicorp/terraform-github-actions/validate@v0.3.7 - - - name: Terraform Apply - uses: hashicorp/terraform-github-actions/apply@v0.4.0 - env: - TF_ACTION_WORKING_DIR: 'terraform' - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + - name: Apply Terraform + run: terraform apply -input=false planfile \ No newline at end of file