首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Github操作Terraform初始化空目录

Github操作Terraform初始化空目录
EN

Stack Overflow用户
提问于 2022-07-21 11:57:09
回答 1查看 413关注 0票数 0

我是新的使用Github动作和编码到YAML文件。

目前,我为我的Datadog POC设置了Terraform Github操作。

我来到这个问题上:

代码语言:javascript
复制
terraform init
/home/runner/work/_temp/85297372-6fed-4b1d-88f8-3c6b5527569f/terraform-bin init
Terraform initialized in an empty directory!
The directory has no Terraform configuration files. You may begin working
with Terraform immediately by creating Terraform configuration files.

当前的github操作yaml文件是:

代码语言:javascript
复制
I use the terraform github actions yaml file

name: 'Terraform'

on:
  push:
    branches:
    - "main"
  pull_request:

permissions:
  contents: read

jobs:
  terraform:
    name: 'Terraform'
    runs-on: ubuntu-latest
    environment: production

    # 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@v3

    # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
    - name: Setup Terraform
      uses: hashicorp/setup-terraform@v1
      with:
        cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}

    # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
    - name: Terraform Init
      run: terraform init

    # Checks that all Terraform configuration files adhere to a canonical format
    - name: Terraform Format
      run: terraform fmt -check

    # Generates an execution plan for Terraform
    - name: Terraform Plan
      run: terraform plan -input=false

      # On push to "main", build or change infrastructure according to Terraform configuration files
      # Note: It is recommended to set up a required "strict" status check in your repository for "Terraform 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: Terraform Apply
      if: github.ref == 'refs/heads/"main"' && github.event_name == 'push'
      run: terraform apply -auto-approve -input=false

在这里我该做什么补救措施?

我试图将terraform init中包含的目录更改为

运行:working目录:./DataDog/terraform,但我也收到了错误。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2022-07-21 12:01:09

您必须将cd放入包含所有terraform文件的目录中。就像这样

代码语言:javascript
复制
- name: Build Docker image
    run: |
      cd dir

或者,您也可以像这样设置工作目录

代码语言:javascript
复制
   steps:
      - uses: actions/checkout@v1
      - name: Setup and run tests
        working-directory: ./app
        run: |
          cp .env .env

代码语言:javascript
复制
jobs:
  unit:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./app
    steps:
      - uses: actions/checkout@v1
      - name: Do stuff

https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsrun

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73065738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档