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

time_series_insights_event_source_iothub consistently recreated due to naming inconsistency #16284

Closed craigbryson closed 11 months ago

craigbryson commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.0.11

AzureRM Provider Version

2.99

Affected Resource(s)/Data Source(s)

time_series_insights_event_source_iothub

Terraform Configuration Files

See below + https://gist.github.com/craigbryson/6f1fd310c98e1812a7323ea88e97a026

Debug Output/Panic Output

<->

Expected Behaviour

time_series_insights_event_source_iothub is not recreated

Actual Behaviour

This is related to my previous issue: https://github.com/hashicorp/terraform-provider-azurerm/issues/14832

We've noticed that even if a time_series_insights_event_source_iothub is created using terraform - subsequent plans will report that it must be destroyed and recreated due to the environment_id changing - the change appears to be that resourceGroups is to become resourcegroups (changing the case of the G)

To answer @myc2h6o question from the previous issue

terraform state show module.iot_edge.azurerm_iot_time_series_insights_event_source_iothub.tsi_event_source
# module.iot_edge.azurerm_iot_time_series_insights_event_source_iothub.tsi_event_source:
resource "azurerm_iot_time_series_insights_event_source_iothub" "tsi_event_source" {
    consumer_group_name      = "tsi"
    environment_id           = "/subscriptions/xxxxx/resourceGroups/yyyyyy/providers/Microsoft.TimeSeriesInsights/environments/zzzzz"

Steps to Reproduce

Create an event source (and accompanying resources) such as:


resource "azurerm_iot_time_series_insights_gen2_environment" "tsi" {
  name                           = var.tsi_environment_name
  location                       = azurerm_resource_group.rg.location
  resource_group_name            = azurerm_resource_group.rg.name
  sku_name                       = var.tsi_sku_name
  warm_store_data_retention_time = "P30D"
  id_properties                  = ["timeSeries"]
  storage {
    name = azurerm_storage_account.tsi_sa.name
    key  = azurerm_storage_account.tsi_sa.primary_access_key
  }
}

resource "azurerm_iot_time_series_insights_event_source_iothub" "tsi_event_source" {
  name                     = var.tsi_event_source
  location                 = azurerm_resource_group.rg.location
  environment_id           = azurerm_iot_time_series_insights_gen2_environment.tsi.id
  iothub_name              = azurerm_iothub.iot.name
  shared_access_key        = azurerm_iothub.iot.shared_access_policy.0.primary_key
  shared_access_key_name   = azurerm_iothub.iot.shared_access_policy.0.key_name
  consumer_group_name      = azurerm_iothub_consumer_group.iot_consumer_group.name
  event_source_resource_id = azurerm_iothub.iot.id
  timestamp_property_name  = "timestamp"
}

terraform apply

wait a few minutes

plan again - our environment_id attribute changes

Important Factoids

No response

References

No response

craigbryson commented 2 years ago

A little further investigation - we're beginning to wonder if there is something specific to the TSI environment - we have a lot of these setups and some exhibit this behaviour, some don't.

myc2h6o commented 2 years ago

Hi @craigbryson as described in #14832, the environment_id, and the id of azurerm_iot_time_series_insights_gen2_environment is generated by the provider itself instead of the result returned by Azure API, so I think there may be some issue locally. I would suggest check the state file to see if the case is corrupted there somehow. And would you be able to share the plan diff? It would be helpful with the troubleshooting.

rcskosir commented 11 months ago

Thanks for opening this issue. This was a problem in the 2.x version of the provider which is no longer actively maintained. If this is still an issue with the 3.x version of the provider please do let us know by opening a new issue and providing the information requested by @myc2h6o, thanks!

github-actions[bot] commented 4 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.