我正在使用terratest来测试terraform,我想确保terraform创建资源组、容器注册表和AKS,当我进行测试时-v-Timeout 60M所有资源都被创建和销毁,但最后我不知道它为什么抛出

TestTerraformAzureResources 2024-02-09T18:45:51+05:00 logger.go:66: 
Destroy complete! Resources: 4 destroyed.
TestTerraformAzureResources 2024-02-09T18:45:51+05:00 logger.go:66: 
--- FAIL: TestTerraformAzureResources (691.95s)
FAIL
exit status 1
FAIL    my-terratest-project    691.996s

以下是我的terraform_test.go代码

package test

import (
"testing"

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

func TestTerraformAzureResources(t *testing.T) {
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
    TerraformDir: "../terraform scripts",
})

defer terraform.Destroy(t, terraformOptions)

terraform.InitAndApply(t, terraformOptions)

// Retrieve the outputs of the Terraform configuration
resourceGroupName := terraform.Output(t, terraformOptions, "resource_group_name")
acrName := terraform.Output(t, terraformOptions, "acr_name")
aksName := terraform.Output(t, terraformOptions, "aks_name")

// Define the expected values
expectedResourceGroupName := "microservice-deployment-demo-tf- 
scripttest"
expectedACRName := "microserviceimagestfscripttest"
expectedAKSName := "example-aks1-tf-scripttest"

// Compare the outputs with the expected values
assert.Equal(t, expectedResourceGroupName, resourceGroupName, "Resource 
group name does not match")
assert.Equal(t, expectedACRName, acrName, "Azure Container Registry name 
does not match")
assert.Equal(t, expectedAKSName, aksName, "Azure Kubernetes Cluster name 
does not match")
}

推荐答案

我通过调整outputs.tf文件解决了这个问题,将其配置为在变量中存储名为ak等的值.

Go相关问答推荐

Go汇编器命名为Constants

try 用GitHub操作中的release标签更新version. go文件,但失败了

消费者在NAT中是如何实现的

如何在使用中介资源时处理函数中的`defer`

困扰围棋官方巡回赛的S建议所有方法都使用同一类型的接收器

golang 的持久隐蔽服务

将这两个函数合二为一的惯用方法

Golang Fiber Render - 将数据发送到多个布局

Kusto Go API 从多个表查询

如何在 Go msgraph-sdk-go 中转发消息并包括抄送和/或密送收件人?

使用 unsafe.Pointer 将 struct point直接转换为另一个 struct 是否安全?

具有嵌套重复的正则表达式

从Go中的随机日期开始以天为单位获取时间

具有两个或多个模型的 GORM 查询

github.com/rs/zerolog 字段的延迟判断

此代码如何生成内存对齐切片?

当有多个同名包时如何在vscode中显示golang包完整路径?

为什么我不能使用来自 gocloak 中 Login() 的访问令牌在 KeyCloak 中创建新客户端?

gqlgen go,通过添加一个解析器来减少数据库调用

如何使用通用字段初始化匿名struct数组