0
votes

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

2

2 Answers

5
votes

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

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

There seem to be a few issues here, but not necessarily a direct question, so I'll take a shot at each one. Note you don't NEED to fix warnings, only errors, though fixing both is recommended.

Warning: Interpolation-only expressions are deprecated

In newer versions of terraform, resource attributes should be passed directly rather than wrapping them in interpolation.

So do

resource "my_resource" "name" {
  some_attr = var.some_value
}

instead of

resource "my_resource" "name" {
  some_attr = "${var.some_value}"
}

unless string interpolation is actually necessary to build a string from other values.

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"

It looks like the module that you're depending on is not forwards-compatible with the version of terraform you're using (at least from a "Warning" perspective).

This specific complaint is because it uses quotes around the map type (e.g. "map" rather than just map). This can be seen it the module's source.

Your only real option here is to fork the module and fix the warnings/upgrade or open a PR and hope the maintainers merge (though it looks like that repo hasn't had activity for 2 years).

Error: "features": required field is not set

This is the real error I think you are probably looking to fix. The answer is simply that your provider is missing the required features block (this can even be empty).

So using the following should fix this error

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

I believe that the issue here is that the upgrade command expects the terraform that's being upgrade to be valid 0.11 code. And in 0.11, the type fields are expected to have string values (e.g. "map", "string", etc...).