如何在 Github Actions 中使用 Terragrunt

Mat*_*.io 4 terraform terragrunt terraform-provider-gcp github-actions

我对创建自定义 github 操作工作流程还比较陌生。我正在尝试将 Terragrunt 与 Terraform 结合使用,使用 Github Actions 来自动化我的 CICD 工作流程,该操作在 GCP 帐户中配置资源。我已经让 Terraform Github Actions 可以工作,但我现在尝试使用 Terraform 周围的 Terragrunt 将其扩展为模块化方法。我已经在本地测试了我的 terragrunt 脚本,没有任何问题。但我在设置 Terragrunt Github Actions 时遇到问题workflow.yaml

在哪里可以找到usesTerragrunt 的“”存储库来设置 Terragrunt。我搜索了 Hasicorp 的 github 存储库,他们只列出了 Terraform。我只找到了仅适用于 Terragrunt 的 AWS 的旧工作流程。

这是我目前的workflow.yaml

name: 'Terragrunt CI'

on:
  push:
    branches:
    - main
  pull_request:

jobs:
  Terragrunt:
    name: 'Terragrunt'
    runs-on: ubuntu-latest

    # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
    defaults:
      run:
        shell: bash

    steps:
    # Checkout the repository to the GitHub Actions runner
    - name: Checkout
      uses: actions/checkout@v2

    # Install the latest version of Terragrunt CLI and configure the Terragrunt CLI configuration file with a Terragrunt Cloud user API token
    - name: Setup Terragrunt
      uses: #**TBD-hashicorp/setup-Terragrunt@v1**


    # Initialize a new or existing Terragrunt working directory by creating initial files, loading any remote state, downloading modules, etc.
    - name: Terragrunt Init
      run: terragrunt init --terragrunt-non-interactive
      env:
        GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}

    # Generates an execution plan for Terragrunt
    - name: Terragrunt Plan
      run: terragrunt run-all plan --terragrunt-non-interactive
      env:
        GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}

      # On push to main, build or change infrastructure according to Terragrunt configuration files
      # Note: It is recommended to set up a required "strict" status check in your repository for "Terragrunt Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks
    - name: Terragrunt Apply
      if: github.ref == 'refs/heads/main' && github.event_name == 'push'
      run: terragrunt apply-all --terragrunt-non-interactive
      env:
        GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
Run Code Online (Sandbox Code Playgroud)

Mat*_*.io 6

已确认,此工作流程已确认有效。

name: 'Terragrunt CI'

on:
  push:
    branches:
    - main
  pull_request:

jobs:
  Terragrunt:
    name: 'Terragrunt'
    runs-on: ubuntu-latest

    # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
    defaults:
      run:
        shell: bash

    steps:
    # Checkout the repository to the GitHub Actions runner
    - name: Checkout
      uses: actions/checkout@v2

    # Install the latest version of Terragrunt CLI and configure the Terragrunt CLI configuration file with a Terragrunt Cloud user API token
    - name: Setup Terraform v1.2.6
      uses: hashicorp/setup-Terraform@v1
      with:
        terraform_version: 1.2.6
        terraform_wrapper: true
    - name: Setup Terraform version
      run: terraform --version
    - name: Setup Terraform wrapper path
      run: which terraform

    - name: Setup Terragrunt v0.38.4
      run: |
        sudo wget -q -O /bin/terragrunt "https://github.com/gruntwork-io/terragrunt/releases/download/v0.38.4/terragrunt_linux_amd64"
        sudo chmod +x /bin/terragrunt
        terragrunt -v

    # Initialize a new or existing Terragrunt working directory by creating initial files, loading any remote state, downloading modules, etc.
    - name: Terragrunt Init
      run: terragrunt init --terragrunt-non-interactive
      env:
        GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}

    # Generates an execution plan for Terragrunt
    - name: Terragrunt Plan
      run: terragrunt run-all plan --terragrunt-non-interactive
      env:
        GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}

      # On push to main, build or change infrastructure according to Terragrunt configuration files
      # Note: It is recommended to set up a required "strict" status check in your repository for "Terragrunt Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks
    - name: Terragrunt Apply
      if: github.ref == 'refs/heads/main' && github.event_name == 'push'
      run: terragrunt run-all apply --terragrunt-non-interactive
      env:
        GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
Run Code Online (Sandbox Code Playgroud)