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.46k stars 4.54k forks source link

Resource Provider 'Microsoft.IoTCentral' not registering automatically #24684

Open dansiviter opened 5 months ago

dansiviter commented 5 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.6.0

AzureRM Provider Version

3.87.0

Affected Resource(s)/Data Source(s)

azurerm_iotcentral_application

Terraform Configuration Files

resource "azurerm_resource_group" "iot" {
  name     = "iot"
  location = local.default_location
}

resource "azurerm_iotcentral_application" "iot" {
  name                = "foo"
  resource_group_name = azurerm_resource_group.iot.name
  location            = azurerm_resource_group.iot.location
  sub_domain          = "foo"

  display_name = "Foo"
  sku          = "ST0"

  tags = {
    environment = local.environment
  }
}

### Debug Output/Panic Output

```shell
azurerm_iotcentral_application.iot: Creating...
╷
│ Error: creating Iot App (Subscription: "***"
│ Resource Group Name: "iot"
│ Iot App Name: "foo"): performing CreateOrUpdate: Put "https://management.azure.com/subscriptions/***/resourceGroups/iot/providers/Microsoft.IoTCentral/iotApps/foo?api-version=2021-11-01-preview": The Resource Provider was not registered
│ 
│ Resource Providers (APIs) in Azure need to be registered before they can be used - however the Resource
│ Provider was not registered, and calling the API returned the following error:
│ 
│ The subscription is not registered to use namespace 'Microsoft.IoTCentral'. See https://aka.ms/rps-not-found for how to register subscriptions. >
│ 
│ The Azure Provider by default will automatically register certain Resource Providers at launch-time,
│ whilst it's possible to opt-out of this (which you may have done) 
│ 
│ Please ensure that this Resource Provider is properly registered, you can do this using the Azure CLI
│ for example to register the Resource Provider "Some.ResourceProvider" is registered run:
│ 
│ > az provider register --namespace "Some.ResourceProvider"
│ 
│ Resource Providers can take a while to register, you can check the status by running:
│ 
│ > az provider show --namespace "Some.ResourceProvider" --query "registrationState"
│ 
│ Once this outputs "Registered" the Resource Provider is available for use and you can re-run Terraform.
│ 
│ 
│   with azurerm_iotcentral_application.iot,
│   on main.tf line 32, in resource "azurerm_iotcentral_application" "iot":
│   32: resource "azurerm_iotcentral_application" "iot" {


### Expected Behaviour

`Microsoft.IoTCentral` should be managed and registered automatically.

### Actual Behaviour

It fails with an error.

### Steps to Reproduce

1. Create a new Subscription that does not have `Microsoft.IoTCentral` registered,
2. Create a `azurerm_iotcentral_application` resource on the new subscription,
3. Apply changes.

### Important Factoids

_No response_

### References

_No response_
rcskosir commented 5 months ago

@dansiviter Thank you for taking the time to open this issue. Can you clarify for me if this is a new behavior? Meaning, on previous versions were you able to have the Resource Provider 'Microsoft.IoTCentral' register automatically, but now it is not? Or is this the first provider version in which you are trying to get it to register? I'm trying to see if this is a new behavior or existing behavior, thanks!

dansiviter commented 5 months ago

@rcskosir I've not tried other versions, however it seems the IoTC terraform functionality is pretty new and by far from complete so I assume something has been missed. I did manage to work around it by creating the azurerm_resource_provider_registration first and using depends_on :

resource "azurerm_resource_provider_registration" "iot-central" {
  name = "Microsoft.IoTCentral"
}

resource "azurerm_iotcentral_application" "iot" {
  ...

  depends_on = [
    azurerm_resource_provider_registration.iot-central
  ]
}