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

如何在github操作工作流中引用正确的目录来调用模块

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

    我正在使用GitHub Actions运行我的工作流。当我创建一个pull_request来触发我的工作流程时,我会在问题的底部收到错误消息。我想做的是从我的审计帐户/prod-env目录中调用我的基础设施/test/main.tf。我需要在目录的Env部分更改什么

    # deploy.yml
    
    name: 'GitHub OIDC workflow'
    on:
      pull_request:
           branches:
             - prod
    env:
      tf_version: 'latest'
      tg_version: 'latest'
      tf_working_dir: './audit-account/prod-env'
    permissions:
        id-token: write
        contents: read
    jobs:
      deploy:
        name: 'Build and Deploy'
        runs-on: ubuntu-latest
    
        steps:
          - name: 'checkout'
            uses: actions/checkout@v2
    
          - name: configure AWS credentials
            uses: aws-actions/configure-aws-credentials@master
            with:
              aws-region: us-east-1
              role-to-assume: arn:aws:iam::123456789012:role/GitHubActions_Workflow_role
              role-duration-seconds: 3600
    
          - name: 'Terragrunt Init'
            uses: the-commons-project/terragrunt-github-actions@master
            with:
              tf_actions_version: ${{ env.tf_version }}
              tg_actions_version: ${{ env.tg_version }}
              tf_actions_subcommand: 'init'
              tf_actions_working_dir: ${{ env.tf_working_dir }}
              tf_actions_comment: true
            env:
              TF_INPUT: false
    
    # audit-account/prod-env/terragrunt.hcl
    
    terraform {
      source = "../../../../..//infrastructure/test"
    }
    
    include {
      path = find_in_parent_folders()
    }
    

    基础设施/测试 主.tf

    resource "aws_vpc" "test-vpc" {
      cidr_block       = "10.0.0.0/16"
      instance_tenancy = "default"
    
      tags = {
        Name = "OIDC"
      }
    }
    

    错误消息:

    init: info: initializing Terragrunt configuration in /audit-account/prod-env
    init: error: failed to initialize Terragrunt configuration in /audit-account/prod-env
    time=2021-11-17T23:55:54Z level=error msg=Working dir infrastructure/test from source file:///github/workspace/audit-account/prod-env does not exist
    
    0 回复  |  直到 4 年前
        1
  •  1
  •   Blastomatic    4 年前

    基础结构模块的源路径在文件夹结构中太靠上了。

    假设您在存储库的根目录中有基础结构和审核帐户目录,那么您的源将是 ../../infrastructure/test 。你有5个文件夹 audit-account/prod-env ,这会将您的3个文件夹放在runner文件系统某个位置的文件夹中的工作区上方。