首页 > 解决方案 > 尝试从 VS Code 运行 Terraform Plan 时出错

问题描述

我正在尝试从 VS Code 登录到 Azure,以便我可以运行 Terraform 脚本。所以我按照以下命令创建了一个 SP。

$azureAplicationId ="Azure AD Application Id"  
$azureTenantId= "Your Tenant Id"  
$azurePassword = ConvertTo-SecureString "strong password" -AsPlainText -Force  
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)  
Add-AzAccount -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal   `enter code here`

运行 Add-AzAccount 后,它会显示帐户名称、订阅名称、租户 ID 和环境。

但是,当我现在尝试从我的 VS Code 运行 terraform plan 以便我可以检查将在我的 azure 环境中部署的所有内容时,它会在下面抛出这个错误:

Error: Error building account: Error getting authenticated object ID: Error parsing json result from 
the Azure CLI: Error waiting for the Azure CLI: exit status 1: AADSTS50076: Due to a configuration 
change made by your administrator, or because you moved to a new location, you must use multi-factor 
authentication to access '00000002-0000-0000-c000-000000000000'.
Trace ID: 19a89f14-0138-4fbd-8d67-5f30c95e5701
Correlation ID: 7d80e2b1-49cc-4f42-9010-401e4453d13e
Timestamp: 2021-02-05 16:39:03Z

我还尝试通过键入 Login-AzAccount 登录并使用 Multi Factor Auth 登录,但我仍然看到上述错误。即使我从 VS Code 登录到 Azure,在尝试运行 Terraform Plan 时仍然出现错误的任何原因

标签: azurepowershellterraform

解决方案


正如评论中所讨论的:

您需要使用 Azure CLI 并az login首先运行。引擎盖下的 Terraform 并未使用 Az-Powershell。


推荐阅读