terraform 计划错误 "features":未设置必填字段
terraform plan error "features": required field is not set
terraform init
初始化成功,下面是我的main.tf
############################################################################
# VARIABLES
#############################################################################
variable "resource_group_name" {
type = string
}
variable "location" {
type = string
default = "eastus"
}
variable "vnet_cidr_range" {
type = string
default = "10.0.0.0/16"
}
variable "subnet_prefixes" {
type = list(string)
default = ["10.0.0.0/24", "10.0.1.0/24"]
}
variable "subnet_names" {
type = list(string)
default = ["web", "database"]
}
#############################################################################
# PROVIDERS
#############################################################################
provider "azurerm" {
}
#############################################################################
# RESOURCES
#############################################################################
module "vnet-main" {
source = "Azure/vnet/azurerm"
resource_group_name = var.resource_group_name
location = var.location
vnet_name = var.resource_group_name
address_space = var.vnet_cidr_range
subnet_prefixes = var.subnet_prefixes
subnet_names = var.subnet_names
nsg_ids = {}
tags = {
environment = "dev"
costcenter = "it"
}
}
#############################################################################
# OUTPUTS
#############################################################################
output "vnet_id" {
value = module.vnet-main.vnet_id
}
当我运行terraform plan -var resource_group_name=vnet-main -out vnet.tfplan
低于警告:
Warning: Interpolation-only expressions are deprecated
on
.terraform/modules/vnet-main/Azure-terraform-azurerm-vnet-e0b9155/main.tf
line 3, in resource "azurerm_resource_group" "vnet": 3: name
= "${var.resource_group_name}"
Warning: Quoted type constraints are deprecated
on
.terraform/modules/vnet-main/Azure-terraform-azurerm-vnet-e0b9155/variables.tf
line 39, in variable "nsg_ids": 39: type = "map"
终于遇到以下错误:
Error: "features": required field is not set
根据下面 Whosebug 文章中提到的建议,如果我 运行 升级命令 (terraform 0.12upgrade
) 升级到 0.12,出现以下错误:
Error: Syntax error in configuration file
on main.tf line 6, in variable "resource_group_name": 6: type
= string
Error while parsing: At 6:11: Unknown token: 6:11 IDENT string
这里似乎有一些问题,但不一定是直接的问题,所以我会针对每一个问题进行分析。请注意,您不需要修复警告,只需修复错误,但建议同时修复两者。
Warning: Interpolation-only expressions are deprecated
在较新版本的 terraform 中,资源属性应直接传递,而不是将它们包装在插值中。
也一样
resource "my_resource" "name" {
some_attr = var.some_value
}
而不是
resource "my_resource" "name" {
some_attr = "${var.some_value}"
}
除非字符串插值实际上是从其他值构建字符串所必需的。
Warning: Quoted type constraints are deprecated
on .terraform/modules/vnet-main/Azure-terraform-azurerm-vnet-e0b9155/variables.tf line 39, in variable "nsg_ids": 39: type = "map"
看起来您所依赖的模块与您正在使用的 terraform 版本不向前兼容(至少从 "Warning" 的角度来看)。
这个具体的投诉是因为它在 map
类型周围使用了引号(例如 "map"
而不仅仅是 map
)。这个可以看出来吧module's source.
你唯一真正的选择是 fork 模块并修复 warnings/upgrade 或打开 PR 并希望维护者合并(尽管看起来 repo 没有 activity for 2年)。
Error: "features": required field is not set
这是 真正的 错误我认为您可能正在寻求修复。答案很简单,您的提供商缺少 required features
block(甚至可以为空)。
因此使用以下内容应该可以修复此错误
provider "azurerm" {
features {}
}
Error: Syntax error in configuration file
on main.tf line 6, in variable "resource_group_name": 6: type = string
Error while parsing: At 6:11: Unknown token: 6:11 IDENT string
我认为这里的问题是升级命令期望正在升级的 terraform 是有效的 0.11
代码。在 0.11
中,type
字段应具有 string
值(例如 "map"
、"string"
等...)。
您好,您必须像下面这样指定 features
块才能解决问题
provider "azurerm" {
version = "=2.4.0"
features {}
}
terraform init
初始化成功,下面是我的main.tf
############################################################################
# VARIABLES
#############################################################################
variable "resource_group_name" {
type = string
}
variable "location" {
type = string
default = "eastus"
}
variable "vnet_cidr_range" {
type = string
default = "10.0.0.0/16"
}
variable "subnet_prefixes" {
type = list(string)
default = ["10.0.0.0/24", "10.0.1.0/24"]
}
variable "subnet_names" {
type = list(string)
default = ["web", "database"]
}
#############################################################################
# PROVIDERS
#############################################################################
provider "azurerm" {
}
#############################################################################
# RESOURCES
#############################################################################
module "vnet-main" {
source = "Azure/vnet/azurerm"
resource_group_name = var.resource_group_name
location = var.location
vnet_name = var.resource_group_name
address_space = var.vnet_cidr_range
subnet_prefixes = var.subnet_prefixes
subnet_names = var.subnet_names
nsg_ids = {}
tags = {
environment = "dev"
costcenter = "it"
}
}
#############################################################################
# OUTPUTS
#############################################################################
output "vnet_id" {
value = module.vnet-main.vnet_id
}
当我运行terraform plan -var resource_group_name=vnet-main -out vnet.tfplan
低于警告:
Warning: Interpolation-only expressions are deprecated
on .terraform/modules/vnet-main/Azure-terraform-azurerm-vnet-e0b9155/main.tf line 3, in resource "azurerm_resource_group" "vnet": 3: name
= "${var.resource_group_name}"Warning: Quoted type constraints are deprecated
on .terraform/modules/vnet-main/Azure-terraform-azurerm-vnet-e0b9155/variables.tf line 39, in variable "nsg_ids": 39: type = "map"
终于遇到以下错误:
Error: "features": required field is not set
根据下面 Whosebug 文章中提到的建议,如果我 运行 升级命令 (terraform 0.12upgrade
) 升级到 0.12,出现以下错误:
Error: Syntax error in configuration file
on main.tf line 6, in variable "resource_group_name": 6: type = string
Error while parsing: At 6:11: Unknown token: 6:11 IDENT string
这里似乎有一些问题,但不一定是直接的问题,所以我会针对每一个问题进行分析。请注意,您不需要修复警告,只需修复错误,但建议同时修复两者。
Warning: Interpolation-only expressions are deprecated
在较新版本的 terraform 中,资源属性应直接传递,而不是将它们包装在插值中。
也一样
resource "my_resource" "name" {
some_attr = var.some_value
}
而不是
resource "my_resource" "name" {
some_attr = "${var.some_value}"
}
除非字符串插值实际上是从其他值构建字符串所必需的。
Warning: Quoted type constraints are deprecated
on .terraform/modules/vnet-main/Azure-terraform-azurerm-vnet-e0b9155/variables.tf line 39, in variable "nsg_ids": 39: type = "map"
看起来您所依赖的模块与您正在使用的 terraform 版本不向前兼容(至少从 "Warning" 的角度来看)。
这个具体的投诉是因为它在 map
类型周围使用了引号(例如 "map"
而不仅仅是 map
)。这个可以看出来吧module's source.
你唯一真正的选择是 fork 模块并修复 warnings/upgrade 或打开 PR 并希望维护者合并(尽管看起来 repo 没有 activity for 2年)。
Error: "features": required field is not set
这是 真正的 错误我认为您可能正在寻求修复。答案很简单,您的提供商缺少 required features
block(甚至可以为空)。
因此使用以下内容应该可以修复此错误
provider "azurerm" {
features {}
}
Error: Syntax error in configuration file
on main.tf line 6, in variable "resource_group_name": 6: type = string
Error while parsing: At 6:11: Unknown token: 6:11 IDENT string
我认为这里的问题是升级命令期望正在升级的 terraform 是有效的 0.11
代码。在 0.11
中,type
字段应具有 string
值(例如 "map"
、"string"
等...)。
您好,您必须像下面这样指定 features
块才能解决问题
provider "azurerm" {
version = "=2.4.0"
features {}
}