본문으로 이동
메뉴 여닫기
  • 22 문서
  • 1 파일
  • 1 사용자
  • 216 편집
terraform-github-tacos
환경 설정 메뉴 여닫기
개인 메뉴 여닫기
로그인하지 않음
지금 편집한다면 당신의 IP 주소가 공개될 수 있습니다.

시작하기

terraform-github-tacos
더 많은 작업
이 문서는 Get started 문서를 번역한 것이며 번역은 100% 완료했습니다.

이 문서는 변경 하나를 프로덕션까지 가져갑니다. 풀 리퀘스트에서 플랜하고, 머지하고, 승인받아 적용합니다. 예제 저장소에는 디렉터리마다 하나씩 network와 dns 두 워크스페이스가 있고, 상태는 원격 백엔드에 둡니다.

환경 만들기

워크스페이스마다 같은 이름의 GitHub 환경에서 적용하고, 그 환경의 필수 리뷰어가 적용을 승인할 수 있는 사람입니다. 환경은 모듈이 만듭니다.

module "tacos" {
  source = "github.com/femiwiki/terraform-github-tacos?ref=v0.7.0"

  repository     = "infra"
  environments   = ["network", "dns"]
  reviewer_teams = [github_team.deployer.id]
}

누가 승인할 수 있는지와 잡마다 필요한 권한은 승인에 있습니다.

워크플로 추가하기

이 워크플로를 .github/workflows/에 넣고, 워크스페이스 목록을 바꾸고, 자격 증명을 추가하세요. 전체 워크플로는 브랜치를 손으로 적용하는 방법과 지난 플랜 댓글을 숨기는 스텝까지 담고 있습니다.

name: tofu
on:
  pull_request:
  push:
    branches: [main]
permissions: {}
jobs:
  plan:
    name: ${{ matrix.workspace }} plan
    strategy:
      fail-fast: false
      matrix:
        workspace: [network, dns]
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    steps:
      - uses: femiwiki/terraform-github-tacos@v0.7.0
        with:
          step: plan
          workspace: ${{ matrix.workspace }}

      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0  # v7.0.0
        with:
          persist-credentials: false

      - uses: dflook/tofu-plan@c7416238983bdd94c5486fb856bb7358f2bcc935  # v3.1.0
        id: plan
        env:
          GITHUB_TOKEN: ${{ github.token }}
        with:
          path: ${{ matrix.workspace }}

      - uses: femiwiki/terraform-github-tacos@v0.7.0
        with:
          step: changes
          workspace: ${{ matrix.workspace }}
          changes: ${{ steps.plan.outputs.changes }}
          plan-json: ${{ steps.plan.outputs.json_plan_path }}

  pending:
    needs: plan
    if: github.event_name == 'push'
    runs-on: ubuntu-latest
    permissions:
      actions: write
      checks: read
    outputs:
      workspaces: ${{ steps.pending.outputs.workspaces }}
    steps:
      - uses: femiwiki/terraform-github-tacos@v0.7.0
        id: pending
        with:
          step: pending

  apply:
    name: ${{ matrix.workspace }} apply
    needs: pending
    if: needs.pending.outputs.workspaces != '[]'
    strategy:
      fail-fast: false
      matrix:
        workspace: ${{ fromJSON(needs.pending.outputs.workspaces) }}
    runs-on: ubuntu-latest
    environment: ${{ matrix.workspace }}
    permissions:
      actions: read
      contents: read
      pull-requests: write
    steps:
      - uses: femiwiki/terraform-github-tacos@v0.7.0
        id: approver
        with:
          step: apply
          workspace: ${{ matrix.workspace }}

      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0  # v7.0.0
        with:
          persist-credentials: false

      - uses: dflook/tofu-apply@e3e5dfc8f935d4b152c767801046f63abf8a77d3  # v3.1.0
        id: apply
        env:
          GITHUB_TOKEN: ${{ github.token }}
        with:
          path: ${{ matrix.workspace }}

      - uses: femiwiki/terraform-github-tacos@v0.7.0
        if: always()
        with:
          step: result
          workspace: ${{ matrix.workspace }}
          outcome: ${{ steps.apply.outcome }}
          plan-json: ${{ steps.apply.outputs.json_plan_path }}
          approver: ${{ steps.approver.outputs.approver }}

  # Make this the one required check
  gate:
    name: tofu gate
    needs: plan
    if: always() && github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    permissions: {}
    steps:
      - uses: femiwiki/terraform-github-tacos@v0.7.0
        with:
          step: gate
          needs: ${{ toJSON(needs) }}

모듈이 규칙 세트로 게이트 잡의 이름 tofu gate를 기본 브랜치의 필수 검사로 지정합니다. 그러면 플랜이 실패한 풀 리퀘스트는 머지할 수 없습니다. 게이트 잡 이름을 다르게 지었다면 그 이름을 모듈의 gate_check에 주세요.

풀 리퀘스트 열기

network 안의 파일을 고치고 풀 리퀘스트를 여세요. 워크스페이스마다 플랜이 돌고, 플랜이 풀 리퀘스트에 댓글로 달립니다. 아직 적용되는 것은 없습니다.

머지하고 승인하기

풀 리퀘스트를 머지하세요. 푸시로 시작된 실행이 모든 워크스페이스를 다시 플랜하고, network apply 잡이 환경의 승인을 기다립니다. 리뷰어가 실행 페이지를 열어 "Review deployments"에서 배포를 승인합니다.

적용할 때 플랜을 새로 만들어서, 승인받은 플랜과 같을 때만 적용합니다. 누가 승인했고 무엇이 바뀌었는지는 잡 요약에 나옵니다.

다음

  • 실행에 워크플로의 스텝마다 하는 일이 있습니다.
  • 자동 적용은 고른 워크스페이스의 승인을 건너뜁니다.
  • 머지 전 적용은 풀 리퀘스트를 머지하기 전에 적용합니다.