hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.51k stars 4.6k forks source link

Support resource azurerm_resource_provider_registration import for Unregistered Providers. #23915

Open jkroepke opened 9 months ago

jkroepke commented 9 months ago

Is there an existing issue for this?

Community Note

Description

Some resource that I manage via terraform requires Providers which a not enabled by default, e.g. Microsoft.Communication

I would like to integrate the provider registration into Terraform, using:

resource "azurerm_resource_provider_registration" "Communication" {
  name = "Microsoft.Communication"
}

This is working fine for new subscription, but for existing subscription a import (of the provider) is needed.

Since 1.6.0, I can use plannable import to avoid such steps.

import {
  to = azurerm_resource_provider_registration.Communication
  id = "/subscriptions/${data.azurerm_client_config.this.subscription_id}/providers/Microsoft.Communication"
}

This is working fine for existing subscription only, for new subscriptions, I get an error:

Error: importing Microsoft.Communication: Resource Provider must be registered to be imported

https://github.com/hashicorp/terraform-provider-azurerm/blob/b10a6dbc8400ea21a6169a72824287347d8ed2de/internal/services/resource/resource_provider_registration_resource.go#L360

It would be great, if import of unregistered Providers is supported. This would finally solve the issue for registered Preview Features of Providers that are already registered by Terraform

New or Affected Resource(s)/Data Source(s)

azurerm_resource_provider_registration

Potential Terraform Configuration

import {
  to = azurerm_resource_provider_registration.Communication
  id = "/subscriptions/${data.azurerm_client_config.this.subscription_id}/providers/Microsoft.Communication"
}

References

No response

jkroepke commented 9 months ago

https://github.com/hashicorp/terraform-provider-azurerm/blob/b10a6dbc8400ea21a6169a72824287347d8ed2de/internal/services/resource/resource_provider_registration_resource.go#L371-L388

May needs a rework, too. With plannable imports, providers registered by Terraform are not a big issue any more.