成功登录后的Terraform计划返回以下错误。不确定为什么Terraform在刷新状态时会抱怨无效的凭据,即使凭据已成功执行。
terraform plan
`[0m[1mRefreshing Terraform state in-memory prior to plan...[0m The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage.
[0m
[31m
[1m[31mError: [0m[0m[1mError refreshing state: 1 error occurred:
* provider.azurerm: Error building AzureRM Client: Error populating Client ID from the Azure CLI: No Authorization Tokens were found - please re-authenticate using ` `az login`.发布于 2019-08-01 10:47:55
为了在Terraform for Azure中进行身份验证,Azure CLI和Azure服务主体是我们通常使用的两种方式。
要使用Azure CLI,通常我们不会在terraform中设置provider块,或者只像下面这样设置provider:
provider "azurerm" {
version = "=1.28.0"
}我建议您不要在Terraform文件中设置提供程序。如果租户有多个订阅,您还可以在通过Azure CLI登录时设置特殊订阅。
要使用Azure服务主体,您需要在terraform中设置提供程序块,如下所示:
provider "azurerm" {
version = "=1.28.0"
subscription_id = "00000000-0000-0000-0000-000000000000"
client_id = "00000000-0000-0000-0000-000000000000"
client_secret = "xxxxxxx"
tenant_id = "00000000-0000-0000-0000-000000000000"
}我认为,该错误可能显示您在Terraform提供程序中设置了客户端Id,并且它与您成功登录的CLI不同。
正如您所说,您已经通过Azure CLI成功登录,所以最简单的方法就是删除Terraform文件中的提供者。
https://stackoverflow.com/questions/57300090
复制相似问题