代码之家  ›  专栏  ›  技术社区  ›  bibi

如何在使用Github环境时配置地形图计划和申请之间的手动审批

  •  0
  • bibi  · 技术社区  · 4 年前

    在合并到我的master之前,我正在使用GitHub环境部署到我的测试帐户中。我已在工作流程中将环境关键字指定为“测试”。我的工作流程将在推送测试分支上触发,然后该分支将运行计划并应用于测试帐户。我希望在计划运行后进行手动批准,这样我就可以在批准部署到测试帐户之前看到输出。请说明我如何配置手动批准,以便在计划运行后,我可以在批准部署到我的测试帐户之前检查计划输出。

    name: Testing Environment
    
    on:
      push:
        branches:
          - test
    
    jobs:
      plan&apply:
        name: "Run Terragrunt Init,Plan and Apply"
        runs-on: ubuntu-20.04
        environment: testing
    
        defaults:
          run:
            working-directory: ${{ env.TERRAFORM_WORKING_DIR }}
        steps:
          - name: 'Checkout'
            uses: actions/checkout@v2
    
          - name: Setup Terraform
            uses: hashicorp/[email protected]
            with:
              terraform_version: ${{ env.TERRAFORM_VERSION }}
              terraform_wrapper: true
    
          - name: Setup Terragrunt
            uses: autero1/[email protected]
            with:
              terragrunt_version: ${{ env.TERRAGRUNT_VERSION }}
    
          - name: configure AWS credentials
            uses: aws-actions/[email protected]
            with:
              aws-region: us-east-1
              role-to-assume: ${{ env.ORCHESTRATION_ROLE_ARN }}
    
          - name: Terragrunt Init
            id: init
            run: terragrunt run-all init -no-color --terragrunt-non-interactive
    
          - name: Terragrunt Plan
            id: plan
            run: |
              terragrunt run-all plan -no-color --terragrunt-non-interactive >/dev/null -out=tfplan
    
         - name: terragrunt Apply
           id: apply
           run : terragrunt run-all apply -no-color --terragrunt-non-interactive
           continue-on-error:true
    
    0 回复  |  直到 4 年前
        1
  •  0
  •   Mahesh    4 年前

    有两种方法可以做到这一点。

    方法1:

    在GH操作环境设置中,添加审阅者。创建两个作业-计划和应用。然后,在申请工作中添加“需求”。这种方法还需要将计划输出作为工件上传,因为计划和应用是两个独立的作业。

    name: Testing Environment
    
    on:
      push:
        branches:
          - test
    
    jobs:
      plan:
        name: "Run Terragrunt Plan"
        runs-on: ubuntu-20.04
    
        defaults:
          run:
            working-directory: ${{ env.TERRAFORM_WORKING_DIR }}
        steps:
          - name: 'Checkout'
            uses: actions/checkout@v2
    
          - name: Setup Terraform
            uses: hashicorp/[email protected]
            with:
              terraform_version: ${{ env.TERRAFORM_VERSION }}
              terraform_wrapper: true
    
          - name: Setup Terragrunt
            uses: autero1/[email protected]
            with:
              terragrunt_version: ${{ env.TERRAGRUNT_VERSION }}
    
          - name: configure AWS credentials
            uses: aws-actions/[email protected]
            with:
              aws-region: us-east-1
              role-to-assume: ${{ env.ORCHESTRATION_ROLE_ARN }}
    
          - name: Terragrunt Init
            id: init
            run: terragrunt run-all init -no-color --terragrunt-non-interactive
         - name: Create Artifact Folder 
           shell: bash
           run: |
              sudo mkdir -p -m777 ${{ github.workspace }}/tfplanoutput
    
          - name: Terragrunt Plan
            id: plan
            run: |
              terragrunt run-all plan -no-color --terragrunt-non-interactive >/dev/null -out=${{ github.workspace }}/tfplanoutput/tf.plan
          
          - name: Upload Artifact
            uses: actions/upload-artifact@v3
            with:
             name: artifact
             path: ${{ github.workspace }}/tfplanoutput/
             if-no-files-found: error
    
    apply:
        name: "Run Terragrunt Apply"
        needs: plan
        runs-on: ubuntu-20.04
        environment: testing
    
          - name: 'Checkout'
            uses: actions/checkout@v2
    
          - name: Setup Terraform
            uses: hashicorp/[email protected]
            with:
              terraform_version: ${{ env.TERRAFORM_VERSION }}
              terraform_wrapper: true
    
          - name: Setup Terragrunt
            uses: autero1/[email protected]
            with:
              terragrunt_version: ${{ env.TERRAGRUNT_VERSION }}
    
          - name: configure AWS credentials
            uses: aws-actions/[email protected]
            with:
              aws-region: us-east-1
              role-to-assume: ${{ env.ORCHESTRATION_ROLE_ARN }}
    
          - name: Terragrunt Init
            id: init
            run: terragrunt run-all init -no-color --terragrunt-non-interactive
    
         - name: Download Build Artifact
           uses: actions/download-artifact@v3
           with:
            name: artifact
            path: ${{ github.workspace }}/tfplanoutput
    
          - name: terragrunt Apply
            run : terragrunt run-all apply tf.plan -no-color --terragrunt-non-interactive 
            continue-on-error:true
    

    方法2: 您可以创建复合操作-计划并应用与上面相同的操作。

    希望这能有所帮助!!!

    推荐文章