简体   繁体   English

GitHub 操作中的 Terratest 失败

[英]Terratest in GitHub Action fails

when running terratest locally with an assertion it works as expected.当使用断言在本地运行 terratest 时,它按预期工作。 But when trying to run it via a github action i get the error below (removing the assertion has terratest running as expected):但是,当尝试通过 github 操作运行它时,出现以下错误(删除断言已按预期运行 terratest):

TestTerraform 2022-07-27T08:34:49Z logger.go:66: ::set-output name=exitcode::0
    output.go:19: 
            Error Trace:    output.go:19
                                        terraform_test.go:24
            Error:          Received unexpected error:
                            invalid character 'c' looking for beginning of value
            Test:           TestTerraform

The terratest file looks like: terratest 文件如下所示:

package test

import (
    "github.com/gruntwork-io/terratest/modules/terraform"
    "github.com/stretchr/testify/assert"
    "testing"
)

func TestTerraform(t *testing.T) {

    iam_arn_expected := "arn:aws:iam::xxx:role/terratest_iam"
    terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
        TerraformDir: "../examples/simple",
        Vars: map[string]interface{}{
            "iam_name": "terratest_iam",
            "region":   "eu-west-2",
        },
    })

    defer terraform.Destroy(t, terraformOptions)

    terraform.InitAndApply(t, terraformOptions)

    iam_arn := terraform.Output(t, terraformOptions, "iam_arn")

    assert.Equal(t, iam_arn_expected, iam_arn)
}

the github action looks like: github 动作看起来像:

jobs:
  terratest:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-go@v3.2.1
      - name: Install tfenv
        run: |
          git clone https://github.com/tfutils/tfenv.git ~/.tfenv
          echo "$HOME/.tfenv/bin" >> $GITHUB_PATH
      - name: Install Terraform
        working-directory: .
        run: |
          pwd
          tfenv install
          terraform --version
      - name: Download Go Modules
        working-directory: test
        run: go mod download
      - name: Run Terratest
        working-directory: test
        run: go test -v
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_PLAYGROUND_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PLAYGROUND_KEY }}

The solution is to use the HashiCorp setup-terraform action with the Terraform wrapper turned off in place of your "Install Terraform" step.解决方案是使用关闭 Terraform 包装器的 HashiCorp setup-terraform操作来代替“安装 Terraform”步骤。

  - name: Setup Terraform
    uses: hashicorp/setup-terraform@v2
    with:
      terraform_version: 1.3.6
      terraform_wrapper: false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM