"At least 1 "features" blocks are required" issue

Hi,
I’m working on deploy Azure Container Registry with Azure DevOps. Everything works fine till I added Private Endpoint block to my Terraform template. Then I getting error on terraform plan stage like below:

2022-09-19T16:07:51.7254270Z [command]/opt/hostedtoolcache/terraform/1.2.9/x64/terraform plan
2022-09-19T16:08:06.4506037Z e[0me[1mazurerm_container_registry.acr: Refreshing state... [id=/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/xxxxxxxxxxxxxxxxxxxxxxxxxx-003-rg/providers/Microsoft.ContainerRegistry/registries/crbabogtest2]e[0m
2022-09-19T16:08:07.3578116Z e[31m╷e[0me[0m
2022-09-19T16:08:07.3578884Z e[31m│e[0m e[0me[1me[31mError: e[0me[0me[1mInsufficient features blockse[0m
2022-09-19T16:08:07.3579344Z e[31m│e[0m e[0m
2022-09-19T16:08:07.3579766Z e[31m│e[0m e[0me[0m  on <empty> line 0:
2022-09-19T16:08:07.3580220Z e[31m│e[0m e[0m  (source code not available)
2022-09-19T16:08:07.3580635Z e[31m│e[0m e[0m
2022-09-19T16:08:07.3581085Z e[31m│e[0m e[0mAt least 1 "features" blocks are required.
2022-09-19T16:08:07.3581518Z e[31m╵e[0me[0m
2022-09-19T16:08:07.3613616Z ##[error]Terraform command 'plan' failed with exit code '1'.
2022-09-19T16:08:07.3666473Z ##[error]e[31m╷e[0me[0m
e[31m│e[0m e[0me[1me[31mError: e[0me[0me[1mInsufficient features blockse[0m
e[31m│e[0m e[0m
e[31m│e[0m e[0me[0m  on <empty> line 0:
e[31m│e[0m e[0m  (source code not available)
e[31m│e[0m e[0m
e[31m│e[0m e[0mAt least 1 "features" blocks are required.
e[31m╵e[0me[0m

2022-09-19T16:08:07.3672017Z ##[section]Finishing: terraform plan

After few days of tries, I’m a bit lost where I made mistake. Could I ask you for help?

MAIN.TF:
resource "azurerm_container_registry" "acr" {
  provider                      = azurerm.Test-001
  name                          = var.ACRNAME
  resource_group_name           = var.RESOURCEGROUPNAME
  location                      = var.region
  sku                           = "Premium"
  admin_enabled                 = true
  zone_redundancy_enabled       = false
  public_network_access_enabled = false
}

resource "azurerm_private_endpoint" "main" {
  name                = "${var.ACRNAME}-pe"
  resource_group_name = var.RESOURCEGROUPNAME
  location            = var.region
  subnet_id           = "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/xxxxxxxxxxxxxxxxxxxxxxxxxx/providers/Microsoft.Network/virtualNetworks/xxxxxxxxxxxxxxxxxxxxxxxxxx/subnets/xxxxxxxxxxxxxxxxxxxxxxxxxx-001-sub"
  
  private_dns_zone_group {
    name                 = "default"
    private_dns_zone_ids = ["/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/xxxxxxxxxxxxxxxxxxxxxxxxxx-001-rg/providers/Microsoft.Network/privateDnsZones/privatelink.azurecr.io"]
  }

  private_service_connection {
    is_manual_connection           = false
    private_connection_resource_id = azurerm_container_registry.acr.id
    name                           = "${var.ACRNAME}-psc"
    subresource_names              = ["registry"]
  }
}

PROVIDERS.TF:
terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=3.16.0"
    }
  }
}

provider "azurerm" {
  features {}
  subscription_id   = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
  alias             = "Test-001"
}

Thank you for all advices and suggestions.

Problem solved.

I added ‘terraform’ and ‘provider’ section to main.tf file.

That fix my issue. Cheers!

Thanks for confirming the solution, @bartosz.bogaczyk!

I just wanted to add some extra notes here in case someone with a similar problem finds this in future.


The hashicorp/azurerm provider requires a block of type features in every provider configuration.

If you declare a resource whose type name starts with azurerm_ then (unless you’ve overridden this using settings elsewhere) Terraform assumes that this resource belongs to the default (unaliased) configuration for hashicorp/azurerm.

If your configuration doesn’t include a default configuration for that provider, Terraform will automatically infer an empty one. But the Azure provider doesn’t consider an empty one as valid and so it returns an error. Terraform can’t show a source location for this error because the problem was with a fake block that Terraform generated for itself in memory!

This therefore requires either one of the following solutions:

  • Define an explicit default (unaliased) configuration for the provider, using a provider "azurerm" block that does not include the alias argument, OR
  • Add explicit provider arguments to all of the resources whose types belong to this provider, to explicitly associate them with a non-default (aliased) configuration. This will mean that no resource is associated with the default configuration and so Terraform won’t automatically generate an empty one.
1 Like