Search code examples
terraforminfrastructure-as-code

terraform plan error "features": required field is not set


terraform init initialize successfully, below is my 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
}

When I run terraform plan -var resource_group_name=vnet-main -out vnet.tfplan getting below warnings:

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"

finally getting below error:

Error: "features": required field is not set

As per suggestion mentioned in below stackoverflow article if I run upgrade command (terraform 0.12upgrade) to upgrade to 0.12 getting below error:

Fix "Interpolation-only expressions are deprecated" warning in Terraform

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


Solution

  • Hey you have to specify features block like following to fix the issue

    provider "azurerm" {
      version = "=2.4.0"
      features {}
    }