- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Azure Pipeline 中面对(它接缝)重复出现的 pbm 来运行 terratest。
虽然资源被很好地创建和销毁,但当我调用 azure.ResourceGroupExists 函数(或其他 azure.xxx 函数)时,出现以下错误:
--- FAIL: TestTerraform_RM_resource_group (102.30s)
resourcegroup.go:15:
Error Trace: resourcegroup.go:15
RM_resource_group_test.go:108
Error: Received unexpected error:
Invoking Azure CLI failed with the following error: ERROR: Please run 'az login' to setup account.
Test: TestTerraform_RM_resource_group
FAIL
关于某些论坛,这似乎是一些配置问题,我遵循所有这些推荐的配置:
这是我关注的链接:
下面是我的管道代码,其中 TF_VAR_ARM_CLIENT_SECRET 是管道的 secret 变量
runOnce:
deploy:
steps:
- checkout: self
- 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: Go@0
displayName: 'Install Go Terratest module'
inputs:
command: get
arguments: '$(TF_LOG) github.com/gruntwork-io/terratest/modules/terraform'
- task: Go@0
displayName: 'Install Go Assert module'
inputs:
command: get
arguments: '$(TF_LOG) github.com/stretchr/testify/assert'
- task: Go@0
displayName: 'Install Go Terratest Azure module'
inputs:
command: get
arguments: '$(TF_LOG) github.com/gruntwork-io/terratest/modules/azure'
- task: Go@0
displayName: 'Install Go hashicorp/terraform-json module'
inputs:
command: get
arguments: '$(TF_LOG) github.com/hashicorp/terraform-json'
- task: Go@0
displayName: 'Install Go azure-sdk-for-go module'
inputs:
command: get
arguments: '$(TF_LOG) github.com/Azure/azure-sdk-for-go'
- task: AzureCLI@2
displayName: Azure CLI
inputs:
azureSubscription: $(serviceConnection)
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
az login --service-principal --username $(TF_VAR_ARM_CLIENT_ID) --password $(TF_VAR_ARM_CLIENT_SECRET) --tenant 'f5ff14e7-93c8-49f7-9706-7beea059bd32'
# Go test command
- task: Go@0
displayName: 'Run Go terratest for resource_Modules'
inputs:
command: test
arguments: '$(TF_LOG) $(pathToTerraformRootModule)\resource_group\'
env:
ARM_CLIENT_SECRET: $(TF_VAR_ARM_CLIENT_SECRET) #pipeline secret variable
ARM_CLIENT_ID: $(TF_VAR_ARM_CLIENT_ID)
ARM_SUBSCRIPTION_ID: $(TF_VAR_ARM_SUBSCRIPTION_ID)
ARM_TENANT_ID: $(TF_VAR_ARM_TENANT_ID)
TF_VAR_SERVICE_PRINCIPAL_ID: $(TF_VAR_ARM_CLIENT_ID)
TF_VAR_SERVICE_PRINCIPAL_SECRET: $(TF_VAR_ARM_CLIENT_ID)
resource_group_name: $(storageAccountResourceGroup)
storage_account_name: $(storageAccount)
container_name: $(stateBlobContainer)
key: '$(MODULE)-$(TF_VAR_APPLICATION)-${{ parameters.Environment }}.tfstate'
下面是我的 go terratest 代码:
package RM_resource_group_Test
import (
"testing"
"os"
"github.com/gruntwork-io/terratest/modules/azure"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
)
var (
globalBackendConf = make(map[string]interface{})
globalEnvVars = make(map[string]string)
)
func TestTerraform_RM_resource_group(t *testing.T) {
t.Parallel()
// terraform Directory
fixtureFolder := "./"
// input value
inputStage := "demo_we"
inputEnvironment := "DEMO"
inputApplication := "DEMO"
// expected value
expectedName := "z-adf-ftnd-shrd-dm-ew1-rgp42"
// getting enVars from environment variables
ARM_CLIENT_ID := os.Getenv("ARM_CLIENT_ID")
ARM_CLIENT_SECRET := os.Getenv("ARM_CLIENT_SECRET")
ARM_SUBSCRIPTION_ID := os.Getenv("ARM_SUBSCRIPTION_ID")
ARM_TENANT_ID := os.Getenv("ARM_TENANT_ID")
if ARM_CLIENT_ID != "" {
globalEnvVars["ARM_USE_MSI"] = "false"
globalEnvVars["ARM_CLIENT_ID"] = ARM_CLIENT_ID
globalEnvVars["ARM_CLIENT_SECRET"] = ARM_CLIENT_SECRET
globalEnvVars["ARM_SUBSCRIPTION_ID"] = ARM_SUBSCRIPTION_ID
globalEnvVars["ARM_TENANT_ID"] = ARM_TENANT_ID
}
// getting backend vars from environment variables
resource_group_name := os.Getenv("resource_group_name")
storage_account_name := os.Getenv("storage_account_name")
container_name := os.Getenv("container_name")
key := os.Getenv("key")
if resource_group_name != "" {
globalBackendConf["use_msi"] = false
globalBackendConf["resource_group_name"] = resource_group_name
globalBackendConf["storage_account_name"] = storage_account_name
globalBackendConf["container_name"] = container_name
globalBackendConf["key"] = key
}
// User Terratest to deploy the infrastructure
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
// The path to where our Terraform code is located
TerraformDir: fixtureFolder,
// Variables to pass to our Terraform code using -var options
Vars: map[string]interface{}{
"STAGE": inputStage,
"ENVIRONMENT": inputEnvironment,
"APPLICATION" : inputApplication,
},
EnvVars: globalEnvVars,
// backend values to set when initialziing Terraform
BackendConfig: globalBackendConf,
// Disable colors in Terraform commands so its easier to parse stdout/stderr
NoColor: true,
})
// website::tag::4::Clean up resources with "terraform destroy". Using "defer" runs the command at the end of the test, whether the test succeeds or fails.
// At the end of the test, run `terraform destroy` to clean up any resources that were created
defer terraform.Destroy(t, terraformOptions)
// website::tag::2::Run "terraform init" and "terraform apply".
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
terraform.InitAndApply(t, terraformOptions)
actualName := terraform.Output(t, terraformOptions, "tested_name")
actualReaderName := terraform.Output(t, terraformOptions, "tested_readerName")
assert.Equal(t, expectedName, actualName)
assert.Equal(t, expectedName, actualReaderName)
subscriptionID := terraform.Output(t, terraformOptions, "current_subscription_id")
exists := azure.ResourceGroupExists(t, expectedName, subscriptionID)
assert.True(t, exists, "Resource group does not exist")
}
我确信我在传递参数时错过了一些东西,在 Azure 中创建和销毁资源后,我总是遇到以下错误:
--- FAIL: TestTerraform_RM_resource_group (90.75s)
resourcegroup.go:15:
Error Trace: resourcegroup.go:15
RM_resource_group_test.go:108
Error: Received unexpected error:
Invoking Azure CLI failed with the following error: ERROR: Please run 'az login' to setup account.
Test: TestTerraform_RM_resource_group
请帮忙。
最佳答案
感谢您的回答..
正如我之前所发现的,这是一个配置错误,在对 Go Terratest Azure 模块进行了一些深入挖掘之后,我发现这些行给出了所有解释:
所以我将管道更改为:
# Go test command
- task: Go@0
displayName: 'Run Go terratest for resource_Modules'
inputs:
command: test
arguments: '$(TF_LOG) $(pathToTerraformRootModule)\...'
env:
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)
resource_group_name: $(storageAccountResourceGroup)
storage_account_name: $(storageAccount)
container_name: $(stateBlobContainer)
key: '$(MODULE)-$(TF_VAR_APPLICATION)-${{ parameters.Environment }}.tfstate'
我的 Go 代码(关于 envVariables 使用):
// getting enVars from environment variables
ARM_CLIENT_ID := os.Getenv("AZURE_CLIENT_ID")
ARM_CLIENT_SECRET := os.Getenv("AZURE_CLIENT_SECRET")
ARM_TENANT_ID := os.Getenv("AZURE_TENANT_ID")
ARM_SUBSCRIPTION_ID := os.Getenv("ARM_SUBSCRIPTION_ID")
// creating globalEnVars for terraform call through Terratest
if ARM_CLIENT_ID != "" {
//globalEnvVars["ARM_USE_MSI"] = "true"
globalEnvVars["ARM_CLIENT_ID"] = ARM_CLIENT_ID
globalEnvVars["ARM_CLIENT_SECRET"] = ARM_CLIENT_SECRET
globalEnvVars["ARM_SUBSCRIPTION_ID"] = ARM_SUBSCRIPTION_ID
globalEnvVars["ARM_TENANT_ID"] = ARM_TENANT_ID
}
// getting backend vars from environment variables
resource_group_name := os.Getenv("resource_group_name")
storage_account_name := os.Getenv("storage_account_name")
container_name := os.Getenv("container_name")
key := os.Getenv("key")
// creating globalBackendConf for terraform call through Terratest
if resource_group_name != "" {
//globalBackendConf["use_msi"] = true
globalBackendConf["resource_group_name"] = resource_group_name
globalBackendConf["storage_account_name"] = storage_account_name
globalBackendConf["container_name"] = container_name
globalBackendConf["key"] = key
}
// User Terratest to deploy the infrastructure
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
// website::tag::1::Set the path to the Terraform code that will be tested.
// The path to where our Terraform code is located
TerraformDir: fixtureFolder,
// Variables to pass to our Terraform code using -var options
Vars: map[string]interface{}{
"STAGE": inputStage,
"ENVIRONMENT": inputEnvironment,
"APPLICATION" : inputApplication,
//"configuration" : inputConfiguration,
},
// globalvariables for user account
EnvVars: globalEnvVars,
// backend values to set when initialziing Terraform
BackendConfig: globalBackendConf,
// Disable colors in Terraform commands so its easier to parse stdout/stderr
NoColor: true,
})
一切顺利!希望这可以帮助其他人。
再次感谢。
[编辑]更明确地说:
Go 和 Terraform 使用两种不同的 Azure 身份验证方法。
** Terraform 身份验证解释如下:
** Go 身份验证解释如下:
** Terratest 对于必须完成的工作使用两种身份验证方法:
因此这两种身份验证方法都必须实现
关于Azure管道-terratest-错误: Please run 'az login' to setup account,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67109139/
我刚刚克隆了 ProductHunt.com 网站,在处理 url 时,我收到了名称错误的错误!当我输入“localhost:8000/accounts/signup”时,它应该带我进入一个 html
我正在将 account.analytic.account 字段从销售订单传递到发票。意图是在确认销售订单时通过该字段。 def _prepare_invoice(self, cr, uid, ord
我有一个奇怪的问题,并不是真正的技术性问题,但我确实希望收集有意义的建议。 我正在构建一个大型 Web 应用程序,基本上是一个照片共享社区站点。作为该站点的一部分,登录用户可以转到他们的个人资料,从中
在 Google Play 开发者控制台中,我在启动前测试中收到警告,其中提到: java.lang.NullPointerException:尝试从字段“java.lang.String andro
我的网站抛出以下异常: IOException: The account used is a computer account. Use your global user account or loc
我在 test 模块下通过 stripe api 在 stripe 中创建了一个帐户。并与该账户绑定(bind)一个银行账户。转到 Stripe dashboard -> connect -> acc
我最近在 Play 商店中更新了我的第一个 android 应用程序,并且发布前报告报告了特定设备上的一个错误。提供的堆栈跟踪如下: FATAL EXCEPTION: main Process: co
我想显示类似的东西: 案例一:“以用户身份登录” @ UserName [ logout ] 这里没有问题,我只是这样做: @ {{ app.user.username}} [ 注销 ] 案例2:“以
为了能够测试 Android Market 许可的任何实现(例如 LVL、应用内结算),Google 建议创建一个 Google Checkout 测试账号 ,因为开发者无法使用自己的 Google
我的公司有一个 Apple 企业帐户,我们用它来为使用 MDM 的员工部署应用程序。工作正常。 我们正在与外部开发人员一起开发一款应用。这个应用程序可能会被放入 App Store。 我大致理解Ent
我有这个方法: @api.multi @api.depends('order_picking', 'order_picking.isbn', 'contract_worksheet', 'state'
我来自以太坊环境,Solana 概念有点令人困惑。我找到了各种指导代码步骤的教程,但并没有真正解释逻辑背后的概念。 我知道在 Solana 中我们有程序,它们不包含数据,只是逻辑 - 网络中的可执行实
我正在编写一个应用程序来访问 Office 365 中用户的数据(电子邮件、联系人、日历)。因此我需要为外部用户启用对我的访问。 我已按照此处的 Microsoft Office 说明 ( http:
我正在构建我的第一个 Meteor 应用程序,在配置accounts-ui/accounts-google 时,系统会提示我将授权重定向 URI 设置为:http://localhost:3000/_
我正在创建一个应该能够读取某个域的所有用户的市场应用程序。我请求访问这些范围: https://www.googleapis.com/auth/userinfo.email https://www.
几天来,我一直在努力显示数据集中表中的数据。当我不在 WHERE 中放置条件时,它会显示完整的表,但只需要表中满足条件的行。如果有更快查看的建议。多谢。 myConnectionString = pw
我正在尝试使用来自 qt c++ 代码的 android AccountManager。要添加帐户,我想创建一个 android.accounts.Account 的实例,我正在尝试使用以下代码执行此
出于某种原因,一小部分 iOS 10 用户无法从我的公共(public) iCloud 容器中读取数据。 CloudKit 返回的 localisedError 是“Account doesn't h
我刚刚开始使用 Stripe API,并且已经遇到了一些我不明白的事情: 我如何确定我自己的 Stripe 帐户的标识符(例如, acct_abcd1234blablabla )? 我在临时 Stri
需要从贷方和借方帐号相同的借方总额中减去贷方总额。如果一个值只存在于借记账号,没有什么可以减去的,只需要得到这个值。 名为 18_7_ChartOfAccounts 的表如下所示: ID | Acco
我是一名优秀的程序员,十分优秀!