gpt4 book ai didi

azure - Visual Studio Code 中的 Terraform 解析错误

转载 作者:行者123 更新时间:2023-12-03 06:44:34 29 4
gpt4 key购买 nike

我是 Terraform 新手,我正在尝试使用文档中的示例部署资源组 here ,在 Visual Studio 代码中。我在尝试使用 terraform applyterraform plan 时收到 json 解析错误。命令terraform initterraform fmtterraform validate都工作正常。使用 az login 连接到 azure 也可以。

有关代码、版本控制和设置的信息如下所示。

错误


│ Error: building AzureRM Client: please ensure you have installed Azure CLI version 2.0.79 or newer. Error parsing json result from the Azure CLI: unmarshaling the result of Azure CLI: invalid character 'C' looking for beginning of value.

│ with provider["registry.terraform.io/hashicorp/azurerm"],
│ on main.tf line 10, in provider "azurerm":
│ 10: provider "azurerm" {


ma​​in.tf 中的代码

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.28.0"
}
}
}

provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "example" {
name = "example-resourcegroup"
location = "eu-west"
}

az --版本输出

azure-cli                         2.41.0

core 2.41.0
telemetry 1.0.8

Dependencies:
msal 1.20.0b1
azure-mgmt-resource 21.1.0b1

terraform --version 输出

Terraform v1.2.5
on windows_amd64
+ provider registry.terraform.io/hashicorp/azurerm v3.28.0

最佳答案

我尝试在我的环境中重现相同的问题并得到以下结果

用于在 Visual Studio 中安装 terraform refer this link 我们必须安装开发者 cli use this link to download and install

我已经安装了 Visual Studio Code 并安装了 terraform

请查找我使用过的版本

enter image description here

我已创建 terraform 文件

vi main.tf


terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.28.0"
}
}
}

provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "example23" {
name = "example-resourcegroup23"
location = "eastus"
}

我已按照一些命令运行该文件

  Terraform init

enter image description here

terraform plan

enter image description here

terraform apply

enter image description here

当我打开门户时,我能够看到新创建的资源组

enter image description here

注意:

1).为了使用 azure CLI,terraform 应该能够进行 azure cli 身份验证,为此我们必须添加 token 。

2).terraform 和 Azure cli 应位于同一路径

az account get-access-token { "accessToken": token_id", "expiresOn": <Date_with_time>, "subscription": "subscription_id", "tenant": "", "tokenType": "token_type" }***

3)。您也可以引用此链接here 了解问题

关于azure - Visual Studio Code 中的 Terraform 解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74220252/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com