使用 Go Task 的 Yaml Azure 管道安装 Terratest 的问题

我在通过 azure yaml 管道安装 terratest 时遇到了这个问题:


C:\hostedtoolcache\windows\go\1.17.1\x64\bin\go.exe install -v github.com/gruntwork-io/terratest@v0.40.6

go: downloading github.com/gruntwork-io/terratest v0.40.6

go install: github.com/gruntwork-io/terratest@v0.40.6: module github.com/gruntwork-io/terratest@v0.40.6 found, but does not contain package github.com/gruntwork-io/terratest

##[error]The Go task failed with an error: Error: The process 'C:\hostedtoolcache\windows\go\1.17.1\x64\bin\go.exe' failed with exit code 1

Finishing: Install Go Terratest module - v0.40.6


我的安装代码如下:


            - task: Go@0

              displayName: Install Go Terratest module - v$(TERRATEST_VERSION)

              inputs:

                command: custom

                customCommand: install

                arguments: $(TF_LOG) github.com/gruntwork-io/terratest@v$(TERRATEST_VERSION)

                workingDirectory: $(pipeline_artefact_folder_extract)/$(pathToTerraformRootModule)

但是很明显我在使用 terratest 时犯了错误。


长风秋雁
浏览 100回答 1
1回答

慕沐林林

我将再次回答我自己的问题。:D所以,现在,使用以下版本:-- 治理:1.17.1-- 地形版本:1.1.7-- TERRATEST_VERSION:0.40.6文件夹层次结构已更改以下内容,关于 terratest 测试:我不再尝试导入我的 Terratest 模块。(所以上面的第 1 点很明显)我现在只需要:修改我的每个 terratest 模块使用脚本一个一个地触发它们中的每一个所以我的管道变成了以下内容:    - task: ms-devlabs.custom-terraform-tasks.custom-terraform-installer-task.TerraformInstaller@0      displayName: Install Terraform $(TERRAFORM_VERSION)      inputs:         terraformVersion: $(TERRAFORM_VERSION)    - task: GoTool@0      displayName: 'Use Go $(GOVERSION)'      inputs:        version: $(GOVERSION)        goPath: $(GOPATH)        goBin: $(GOBIN)    - task: PowerShell@2      displayName: run Terratest for $(pathToTerraformRootModule)      inputs:        targettype : 'filePath'        filePath: $(pipeline_artefact_folder_extract)/$(pathToTerraformRootModule)/$(Run_Terratest_script)        workingDirectory: $(pipeline_artefact_folder_extract)/$(pathToTerraformRootModule)      env:        # see https://learn.microsoft.com/en-us/azure/developer/go/azure-sdk-authorization#use-environment-based-authentication        # for Azure authentification with Go        ARM_SUBSCRIPTION_ID: $(TF_VAR_ARM_SUBSCRIPTION_ID)        AZURE_CLIENT_ID: $(TF_VAR_ARM_CLIENT_ID)        AZURE_TENANT_ID: $(TF_VAR_ARM_TENANT_ID)        AZURE_CLIENT_SECRET: $(TF_VAR_ARM_CLIENT_SECRET) # set as pipeline secret        resource_group_name: $(storageAccountResourceGroup)        storage_account_name: $(storageAccount)        container_name: $(stateBlobContainer)        key: '$(MODULE)-$(TF_VAR_APPLICATION)-$(TF_VAR_ENVIRONMENT).tfstate'        GO111MODULE: 'auto'在我的 terratest 子文件夹的主文件夹中,我有run_terratests.ps1脚本和Terratests列表文件,如下所示:run_terratests.ps1# this file is based on https://github.com/google/go-cloud/blob/master/internal/testing/runchecks.sh## This script runs all go Terratest suites,# compatibility checks, consistency checks, Wire, etc.$moduleListFile = "./Terratests"# regex to filter : not began with #$regexFilter = "^[^#]"# read the ModuleListFile[object] $arrayFromFile = Get-Content -Path $moduleListFile | Where-Object { $_ -match $regexFilter} | ConvertFrom-String -PropertyNames folder, totest$result = 0 # set no error by default# get the actual folder $main_path = Get-Location | select -ExpandProperty "Path"#read the array to show if to be tested !foreach ($line in $arrayFromFile) {    # write-Host $line    if ($line.totest -eq "yes") {        $path = $line.folder        set-location $main_path\$path        $myPath = Get-Location        # Write-Host $myPath        # trigger terratest for files        Go test ./...    }    if ($false -eq $?)    {        $result = 1    }    }# back to school :Dset-location $main_pathif ($result -eq 1){    Write-Error "Msbuild exit code indicate test failure."    Write-Host "##vso[task.logissue type=error]Msbuild exit code indicate test failure."    exit(1)}编码  if ($false -eq $?)    {        $result = 1    }  对于使管道因测试错误而失败而不逃避其他测试很有用。地测# this file lists all the modules to be tested in the "Tests_Unit_ConfigHelpers" repository.# it us used by the "run_terratest.ps1" powershell script to trigger terratest for each test.## Any line that doesn't begin with a '#' character and isn't empty is treated# as a path relative to the top of the repository that has a module in it.# The 'tobetested' field specifies whether this is a module that have to be tested.## this file is based on https://github.com/google/go-cloud/blob/master/allmodules# module-directory              tobetestedazure_constants                     yesconfigure_app_srv_etc               yesconfigure_frontdoor_etc             yesconfigure_hostnames                 yesconstants                           yesFrontEnd_AppService_slots/_main     yesFrontEnd_AppService_slots/settings  yesmerge_maps_of_strings               yesname                                yesname_template                       yesnetwork/hostname_generator          yesnetwork/hostnames_generator         yesreplace_2vars_into_string_etc       yesreplace_var_into_string_etc         yessorting_map_with_an_other_map       yes每个 terratest 文件夹的变化是我将添加 go.mod 和 go.sum 文件:$ go mod init mytestgo: creating new go.mod: module mytestgo: to add module requirements and sums:go mod tidy和$ go mod tidy# link each of the go modules needed for your terratest module因此,go test ./...powershell 脚本将下载所需的 go 模块并运行该特定测试的测试。感谢阅读,如果您认为有帮助,请投票:)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go