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

How to reference proper directory in a github actions workflows to call a module

我 运行 我的工作流程使用 GitHub 操作。当我创建将触发我的工作流程的 pull_request 时,我在问题底部收到错误消息。我想要做的是从我的 audit-account/prod-env 目录调用我的 infrastructure/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()
}

infrastructure/test main.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

您的基础结构模块的源路径在文件夹结构中的位置太靠前了。

假设您在存储库的根目录下有基础结构和审计帐户目录,您的源将是 ../../infrastructure/test。你让它从 audit-account/prod-env 向上查找 5 个文件夹,这将你放在工作区上方的 3 个文件夹,位于运行程序文件系统某处的文件夹中。