Skip to content

Commit 95034a2

Browse files
authored
provider - change resource_provider_registrations default to none in v5.0 (hashicorp#31679)
1 parent 2d84667 commit 95034a2

4 files changed

Lines changed: 75 additions & 6 deletions

File tree

internal/provider/framework/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ func (p *ProviderConfig) Load(ctx context.Context, data *ProviderModel, tfVersio
538538

539539
client.StopContext = ctx
540540

541-
resourceProviderRegistrationSet := getEnvStringOrDefault(data.ResourceProviderRegistrations, "ARM_RESOURCE_PROVIDER_REGISTRATIONS", resourceproviders.ProviderRegistrationsCore)
541+
resourceProviderRegistrationSet := getEnvStringOrDefault(data.ResourceProviderRegistrations, "ARM_RESOURCE_PROVIDER_REGISTRATIONS", resourceproviders.ProviderRegistrationsNone)
542542
if !providerfeatures.FivePointOh() {
543543
resourceProviderRegistrationSet = getEnvStringOrDefault(data.ResourceProviderRegistrations, "ARM_RESOURCE_PROVIDER_REGISTRATIONS", resourceproviders.ProviderRegistrationsLegacy)
544544
}

internal/provider/provider.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1818
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1919
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
20+
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
2021
"github.com/hashicorp/terraform-provider-azurerm/internal/resourceproviders"
2122
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
2223
"github.com/hashicorp/terraform-provider-azurerm/utils"
@@ -339,7 +340,7 @@ func azureProvider(supportLegacyTestSuite bool) *schema.Provider {
339340
"resource_provider_registrations": {
340341
Type: schema.TypeString,
341342
Optional: true,
342-
DefaultFunc: schema.EnvDefaultFunc("ARM_RESOURCE_PROVIDER_REGISTRATIONS", resourceproviders.ProviderRegistrationsLegacy),
343+
DefaultFunc: schema.EnvDefaultFunc("ARM_RESOURCE_PROVIDER_REGISTRATIONS", resourceproviders.ProviderRegistrationsNone),
343344
Description: "The set of Resource Providers which should be automatically registered for the subscription.",
344345
ValidateFunc: validation.StringInSlice([]string{
345346
resourceproviders.ProviderRegistrationsCore,
@@ -383,6 +384,10 @@ func azureProvider(supportLegacyTestSuite bool) *schema.Provider {
383384

384385
p.ConfigureContextFunc = providerConfigure(p)
385386

387+
if !features.FivePointOh() {
388+
p.Schema["resource_provider_registrations"].DefaultFunc = schema.EnvDefaultFunc("ARM_RESOURCE_PROVIDER_REGISTRATIONS", resourceproviders.ProviderRegistrationsLegacy)
389+
}
390+
386391
return p
387392
}
388393

website/docs/5.0-upgrade-guide.html.markdown

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,83 @@ Azure Resource Manager: 5.0 Upgrade Guide
1010

1111
## Azure Provider Version 5.0
1212

13-
TODO
13+
Version 5.0 of the Azure Provider is a major release that includes breaking changes and behavioural differences. This guide covers the most significant changes and explains how to upgrade from v4.x to v5.0.
1414

1515
### Pinning your Provider Version
1616

17-
TODO
17+
We recommend pinning the version of each Provider you use in Terraform. You can do this using the `version` attribute within the `required_providers` block:
18+
19+
```hcl
20+
terraform {
21+
required_providers {
22+
azurerm = {
23+
source = "hashicorp/azurerm"
24+
version = "=5.0.0"
25+
}
26+
}
27+
}
28+
29+
provider "azurerm" {
30+
features {}
31+
}
32+
```
33+
34+
More information on [how to pin the version of a Terraform Provider being used can be found on the Terraform Website](https://developer.hashicorp.com/terraform/language/providers/requirements#require-providers).
35+
36+
---
1837

1938
## What's available in Version 5.0 of the Azure Provider?
2039

40+
* [Resource Provider Registration Changes](#resource-provider-registration-changes)
2141
* [Removed Resources](#removed-resources)
2242
* [Removed Data Sources](#removed-data-sources)
2343
* [Breaking Changes in Resources](#breaking-changes-in-resources)
2444
* [Breaking Changes in Data Sources](#breaking-changes-in-data-sources)
2545

46+
## Resource Provider Registration Changes
47+
48+
In version 5.0, the default behaviour for Resource Provider registration has changed. The `resource_provider_registrations` property now defaults to `none` instead of `legacy`.
49+
50+
### What this means
51+
52+
Previously, the provider would automatically attempt to register a large set of Azure Resource Providers (~60 RPs) when initializing. This could:
53+
54+
* Add delay to provider startup due to sequential RP registration checks
55+
* Cause permission errors for users with restricted access to their subscription
56+
* Register RPs that users may not need or want
57+
58+
In v5.0, no Resource Providers are registered by default. This gives users full control over RP registration and avoids potential permission issues.
59+
60+
### Registering specific Resource Providers
61+
62+
The recommendation is to only register the specific Resource Providers that your configuration requires, using the `resource_providers_to_register` property:
63+
64+
```hcl
65+
provider "azurerm" {
66+
resource_providers_to_register = [
67+
"Microsoft.Compute",
68+
"Microsoft.Network",
69+
"Microsoft.Storage",
70+
]
71+
72+
features {}
73+
}
74+
```
75+
### How to replicate the previous behaviour
76+
77+
If you want to maintain the v4.x behaviour and automatically register the same set of Resource Providers as before, explicitly set `resource_provider_registrations` to the `legacy` resource provider set in your provider block:
78+
79+
```hcl
80+
provider "azurerm" {
81+
resource_provider_registrations = "legacy"
82+
features {}
83+
}
84+
```
85+
86+
For more information, see the [Resource Provider Registrations](index.html#resource-provider-registrations) section in the provider documentation.
87+
88+
---
89+
2690

2791
## Removed Resources
2892

website/docs/index.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ For some advanced scenarios, such as where more granular permissions are necessa
197197

198198
* `auxiliary_tenant_ids` - (Optional) Contains a list of (up to 3) other Tenant IDs used for cross-tenant and multi-tenancy scenarios with multiple AzureRM provider definitions. The list of `auxiliary_tenant_ids` in a given AzureRM provider definition contains the other, remote Tenants and should not include its own `subscription_id` (or `ARM_SUBSCRIPTION_ID` Environment Variable).
199199

200-
* `resource_provider_registrations` - (Optional) Specifies a pre-determined set of [Azure Resource Providers](https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-providers-and-types) to automatically register when initializing the AzureRM Provider. Allowed values for this property are `core`, `extended`, `all`, or `none`. This can also be sourced from the `ARM_RESOURCE_PROVIDER_REGISTRATIONS` environment variable. For more information about which resource providers each set contains, see the [Resource Provider Registrations](#resource-provider-registrations) section below.
200+
* `resource_provider_registrations` - (Optional) Specifies a pre-determined set of [Azure Resource Providers](https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-providers-and-types) to automatically register when initializing the AzureRM Provider. Allowed values for this property are `core`, `extended`, `all`, `legacy`, or `none`. This can also be sourced from the `ARM_RESOURCE_PROVIDER_REGISTRATIONS` environment variable. For more information about which resource providers each set contains, see the [Resource Provider Registrations](#resource-provider-registrations) section below. Defaults to `legacy` in v4.x and `none` in v5.0+.
201201

202202
* `resource_providers_to_register` - (Optional) A list of arbitrary [Azure Resource Providers](https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-providers-and-types) to automatically register when initializing the AzureRM Provider. Can be used in combination with the `resource_provider_registrations` property. For more information, see the [Resource Provider Registrations](#resource-provider-registrations) section below.
203203

204-
-> **Note:** By default, Terraform will attempt to register any Resource Providers that it supports, even if they're not used in your configurations, to be able to display more helpful error messages. If you're running in an environment with restricted permissions, or wish to manage Resource Provider Registration outside of Terraform you may wish to disable this by setting `resource_provider_registrations` to `none`; however, please note that the error messages returned from Azure may be confusing as a result.
204+
-> **Note:** In version 5.0 and later, the default value for `resource_provider_registrations` is `none`, meaning no Resource Providers will be automatically registered. If you're upgrading from v4.x and want to maintain the previous behaviour, set `resource_provider_registrations = "legacy"` in your provider block. If you're running in an environment with restricted permissions, or wish to manage Resource Provider Registration outside of Terraform, `none` is the recommended setting.
205205

206206
* `storage_use_azuread` - (Optional) Should the AzureRM Provider use AzureAD to connect to the Storage Blob & Queue APIs, rather than the SharedKey from the Storage Account? This can also be sourced from the `ARM_STORAGE_USE_AZUREAD` Environment Variable. Defaults to `false`.
207207

0 commit comments

Comments
 (0)