|
| 1 | +--- |
| 2 | +name: "Terraform Project: Generate Plan" |
| 3 | + |
| 4 | +"on": |
| 5 | + workflow_call: |
| 6 | + secrets: |
| 7 | + GH_TOKEN: |
| 8 | + description: "Github PAT. Used for managing Github ressources beyond the scope of short-live token (organization, other repositories, etc)" |
| 9 | + required: false |
| 10 | + TFE_TOKEN: |
| 11 | + description: "Terraform Cloud Token. Used for backend's authentication and ressource management" |
| 12 | + required: false |
| 13 | +jobs: |
| 14 | + terraform: |
| 15 | + name: "Terraform Project" |
| 16 | + runs-on: ubuntu-latest |
| 17 | + concurrency: |
| 18 | + group: ${{ github.repository }} |
| 19 | + cancel-in-progress: false |
| 20 | + steps: |
| 21 | + - id: repo_checkout |
| 22 | + name: "Repository: Checkout" |
| 23 | + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 |
| 24 | + - id: tf_version |
| 25 | + name: "Terraform: Get version" |
| 26 | + run: | |
| 27 | + TF_VERSION=$(cat .terraform-version 2>/dev/null || echo latest) |
| 28 | + echo "TF_VERSION=$TF_VERSION" >> $GITHUB_OUTPUT |
| 29 | + - id: tf_setup |
| 30 | + name: "Terraform: Setup" |
| 31 | + uses: hashicorp/setup-terraform@97f030cf6dc0b4f5e0da352c7bca9cca34579800 # v3.1.0 |
| 32 | + with: |
| 33 | + cli_config_credentials_token: ${{ secrets.TFE_TOKEN }} |
| 34 | + terraform_version: ${{steps.tf_version.outputs.TF_VERSION}} |
| 35 | + - id: tf_fmt |
| 36 | + name: "Terraform: Check formatting" |
| 37 | + run: terraform fmt -check -diff -recursive ./ |
| 38 | + - name: "Terraform: Cache providers directory" |
| 39 | + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 |
| 40 | + with: |
| 41 | + path: ./.terraform/providers |
| 42 | + key: tf-${{ steps.tf_version.outputs.TF_VERSION }}-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.terraform.lock.hcl') }} |
| 43 | + - id: tf_init |
| 44 | + name: "Terraform: Prepare working directory" |
| 45 | + run: terraform init |
| 46 | + - id: tf_validate |
| 47 | + name: "Terraform: Check configuration is valid" |
| 48 | + run: terraform validate |
| 49 | + - id: tf_plan |
| 50 | + name: "Terraform: Generate terraform plan" |
| 51 | + run: terraform plan -input=false -no-color |
| 52 | + env: |
| 53 | + TFE_TOKEN: ${{ secrets.TFE_TOKEN }} |
| 54 | + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
| 55 | + tflint: |
| 56 | + name: "Project linting" |
| 57 | + runs-on: ubuntu-latest |
| 58 | + steps: |
| 59 | + - id: repo_checkout |
| 60 | + name: "Repository: Checkout" |
| 61 | + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 |
| 62 | + - id: tflint_cache |
| 63 | + name: "TFLint: Update cache" |
| 64 | + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 |
| 65 | + with: |
| 66 | + path: ~/.tflint.d/plugins |
| 67 | + key: tflint-${{ hashFiles('.tflint.hcl') }} |
| 68 | + - id: tflint_setup |
| 69 | + name: "TFLint: Setup" |
| 70 | + uses: terraform-linters/setup-tflint@19a52fbac37dacb22a09518e4ef6ee234f2d4987 # v4.0.0 |
| 71 | + - id: tflint_init |
| 72 | + name: "TFLint: Install plugins" |
| 73 | + run: tflint --init |
| 74 | + - id: tflint_inspect |
| 75 | + name: "TFLint: Inspect code" |
| 76 | + run: tflint -f compact --call-module-type=local |
0 commit comments