Getting errors when I run Terraform on VS Code : features required field is not set

i am trying to create a resource group in VS Code:

provider “azurerm” {

version = “=2.0”
}

resource “azurerm_resource_group” “rg” {
name = “Terraform-Test”
location = “West US”
tags = {

environment = "test"

}

}

When i run: Azure Terraform:Plan
I get an error

Error: “features”: required field is not set

I tried everything can someone help me.
Thanks

Try this module
provider “azurerm” {
version = “~> 1.44”
}

That worked, but can you explain why I had to use version 1.44, instead of 2.0.0. I am learning this. thx

Hi,

From 2.0 you need to use a features block.

You also can fix with this
provider “azurerm” {

version = “=2.0”
features {}
}

Thanks that really helped. Your the best. :slight_smile:

hi I updated my code as below still i’m getting error like Error: “features”: required field is not set

provider “azurerm” {
version = “~>2.0.0”
features {}
}
can you please help me

Hi Avani129
Can you try with ‘=’ please?

provider “azurerm” {
version = “=2.0.0”
features {}
}

like that. And let me know what’s the outcome, please.
Cheers
G

I did and didn’t work
I see same error no matter what change I made.When I publish artifacts. I could see those changes were part of the code.

Starting: TerraformCLI

Task : Terraform CLI
Description : Execute terraform cli commands
Version : 0.5.2
Author : Charles Zipp
Help :

/usr/local/bin/terraform version
Terraform v0.12.23

  • provider.azurerm v2.3.0

Your version of Terraform is out of date! The latest version
is 0.12.24. You can update by downloading from https://www.terraform.io/downloads.html

/usr/local/bin/terraform apply -auto-approve -var client_id=() -var client_secret=(client_secret -var ssh_public_key=/home/vsts/work/_temp/azure_rsa.pub
Acquiring state lock. This may take a few moments…

Error: “features”: required field is not set

Releasing state lock. This may take a few moments…

##[error]Terraform command ‘apply’ failed with exit code ‘1’.: “features”: required field is not set
Finishing: TerraformCLI

Hi there,
Shouldn’t you need to re run terraform init in order to download the new version of the provider?
Sorry if I’m wrong

Hi all.

I already have the empty features block, as per the below, but I continue to receive the error when running terraform plan:

provider "azurerm" {
features {}
version = ">=2.0.0"
}

I have also tried pinning the provider version with “=2.0.0”; “=2.1.0”; “=2.2.0”; “=2.3.0”; “=2.4.0”, and each time deleting the .terraform directory, and doing a fresh init, and plan each time. but still get same error every time

Normally I’ve been using “>=2.0.0” ever since the 2.0 AzureRm Provider got released, and I originally added the features block without issue, but now with this error that tells me there is no features block, when in fact I do have a features block - that’s why I’ve been trying all these different version combinations but without luck.

I’ve also tried all of the above with different versions of terraform.exe (0.12.19; 0.12.21; 0.12.24), also deleting the .terraform directory with each new version.

Error: “features”: required field is not set

Any advice would be appreciated. Thank you

Tested all the above on Windows 10 v1809

I have managed to get passed the error. I moved the provider block to main.tf, and I had to create a 2nd provider block for the sub I was accessing. It does not work with just one:

#Azure Provider/s
provider "azurerm" {
  features {}
  version  = ">=2.0.0"
}
 
provider "azurerm" { 
  features {} 
  alias = "cloud_operations"
  subscription_id = var.provider_ids.operations
  skip_provider_registration = "true"
}

Terraform.exe = 0.12.24
AzureRM Provider = 2.4.0

1 Like

Thank you so much @darrens280!!! Worked for me.

2 Likes

Hi Darren,
How do you use azuread provider? As per the documentation, I followed this:

provider "azuread" {
  # Whilst version is optional, we /strongly recommend/ using it to pin the version of the Provider being used
  version = "=0.10.0"
}

But terraform enterprise is expecting a features block, so I added it. But the next run says, features block is not expected here. Quite confused the way this azuread and azurerm providers work with features block. Please assist, thank you!

Hi. Unfortunately I’ve never used the “azuread” provider, so won’t be much assistance. Sorry about that.

Hi darrens,
I tried using the above in main.tf file but still getting the error, please assist.

provider “azurerm” {
features {}
version = “>=2.0.0”
}

provider “azurerm” {
features {}
alias = “cloud_operations”
subscription_id = “xxxxxxxx”
skip_provider_registration = “true”
}

Logs:

Initializing provider plugins…

August 16th 2020 23:02:04

Info

  • Finding hashicorp/azurerm versions matching “>= 2.0.0”…

August 16th 2020 23:02:05

Info

  • Installing hashicorp/azurerm v2.23.0…

August 16th 2020 23:02:10

Info

  • Installed hashicorp/azurerm v2.23.0 (signed by HashiCorp)

August 16th 2020 23:02:12

Info

Terraform has been successfully initialized!

August 16th 2020 23:02:24

Info

“terraform.exe” apply -no-color -auto-approve -target=module.databricks_DEVOPS-1238

August 16th 2020 23:02:24

Error

Error: “features”: required field is not set

Terraform.exe is v0.13.0

  1. What happens if you try merge the two azurerm provider sections into one? Having them separated worked for me. Also try move it back to variables.tf to see if that helps…

provider “azurerm” {
features {}
version = “>=2.0.0”
alias = “cloud_operations”
subscription_id = “xxxxxxxx”
skip_provider_registration = “true”
}

  1. Check the double quotes you’re using. I’ve seen this before where copying/pasting quotes causes problems - see screenshot below - 1st set of quotes does not work. 2nd set does work. (perhaps it’s just the way it got pasted here in the forum, but still worth a check)
    quotes

  2. Perhaps the version of Terraform (0.13 vs 0.12) ?

If you are already on 2.x.x and do have “features{}” in your provider double check if you recently added any new resource blocks and did not include a provider attribute. I recently got that error and had missed the provider in a new resource I created.

resource "azurerm_sql_firewall_rule" "my_rule" {
name                = "MyRule"
resource_group_name = var.rg
server_name         = azurerm_sql_server.sqlserver.name
start_ip_address    = "0.0.0.0"
end_ip_address      = "0.0.0.0"

provider   = azurerm.myazure  <----
}