Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_monitor_action_group_data_source constructs incorrect event_hub_id #17091

Closed
1 task done
nlighten opened this issue Jun 3, 2022 · 1 comment · Fixed by #17335
Closed
1 task done

azurerm_monitor_action_group_data_source constructs incorrect event_hub_id #17091

nlighten opened this issue Jun 3, 2022 · 1 comment · Fixed by #17335
Labels

Comments

@nlighten
Copy link

nlighten commented Jun 3, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

v1.1.9

AzureRM Provider Version

3.9.0

Affected Resource(s)/Data Source(s)

azurerm_monitor_action_group_data_source

Terraform Configuration Files

resource "azurerm_resource_group" "eventhub" {
  name     = "rg-eventhub"
  location = "westeurope"
}

resource "azurerm_eventhub_namespace" "eventhub" {
  name                = "action-group-namespace"
  location            = azurerm_resource_group.eventhub.location
  resource_group_name = azurerm_resource_group.eventhub.name
  sku                 = "Basic"
}

resource "azurerm_eventhub" "eventhub" {
  name                = "action-group"
  namespace_name      = azurerm_eventhub_namespace.eventhub.name
  resource_group_name = azurerm_resource_group.eventhub.name
  partition_count     = 2
  message_retention   = 1
}

resource "azurerm_resource_group" "action_group" {
  name     = "rg-action-group"
  location = "westeurope"
}


resource "azurerm_monitor_action_group" "service_health" {
  name                = "service-health"
  resource_group_name = azurerm_resource_group.action_group.name
  short_name          = "sh"
  event_hub_receiver {
    name                    = "ServiceHealthAlert"
    event_hub_id            = azurerm_eventhub.eventhub.id
    use_common_alert_schema = false
  }
}

Debug Output/Panic Output

Second apply results in changes detected due to incorrect event_hub_id being constructed.

terraform apply
azurerm_resource_group.eventhub: Refreshing state... [id=/subscriptions/f0128488-bc19-4cfe-9097-3bac2863762b/resourceGroups/rg-eventhub]
azurerm_resource_group.action_group: Refreshing state... [id=/subscriptions/f0128488-bc19-4cfe-9097-3bac2863762b/resourceGroups/rg-action-group]
azurerm_eventhub_namespace.eventhub: Refreshing state... [id=/subscriptions/f0128488-bc19-4cfe-9097-3bac2863762b/resourceGroups/rg-eventhub/providers/Microsoft.EventHub/namespaces/action-group-namespace]

Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the last "terraform apply":

  # azurerm_eventhub_namespace.eventhub has changed
  ~ resource "azurerm_eventhub_namespace" "eventhub" {
        id                                  = "/subscriptions/f0128488-bc19-4cfe-9097-3bac2863762b/resourceGroups/rg-eventhub/providers/Microsoft.EventHub/namespaces/action-group-namespace"
        name                                = "action-group-namespace"
      + tags                                = {}
        # (12 unchanged attributes hidden)
    }

  # azurerm_resource_group.action_group has changed
  ~ resource "azurerm_resource_group" "action_group" {
        id       = "/subscriptions/f0128488-bc19-4cfe-9097-3bac2863762b/resourceGroups/rg-action-group"
        name     = "rg-action-group"
      + tags     = {}
        # (1 unchanged attribute hidden)
    }

  # azurerm_resource_group.eventhub has changed
  ~ resource "azurerm_resource_group" "eventhub" {
        id       = "/subscriptions/f0128488-bc19-4cfe-9097-3bac2863762b/resourceGroups/rg-eventhub"
        name     = "rg-eventhub"
      + tags     = {}
        # (1 unchanged attribute hidden)
    }

Expected Behaviour

When I apply the same terraform configuration files for the second time no changes should be detected.

Actual Behaviour

The data source incorrect uses the resource group of the monitor action group to construct the event_hub_id. This is incorrect as in the provided configuration the event hub is in another resource group.

The problem seems to originate from the way the event_hub_receiver is modelled. The Terraform AzureRM provider uses a resource id event_hub_id as input. Azure RM itself does not expect a full Eventhub resource id but only uses tenantId, subscriptionId, eventHubNameSpace, eventHubName. See API definition. As a result the azurerm_monitor_action_group_data_source cannot reconstruct a full resource id that is expected by event_hub_id.

The current implementation uses the resource group of the action group to construct the resource id, but this is only correct if the eventhub and action group are in the same resource group which will be rarely the case.

Wouldn't it be better to use the same input as Azure RM uses for event_hub_receiver? So instead of a single event_hub_id allow the input of tenant_id, subscription_id, event_hub_name_space and event_hub_name.

Steps to Reproduce

  1. terraform apply
  2. terraform apply

Important Factoids

No response

References

No response

@nlighten nlighten added the bug label Jun 3, 2022
@github-actions github-actions bot removed the bug label Jun 3, 2022
@nlighten nlighten changed the title azurerm_monitor_action_group_data_source constructs incorrect event_hub_id azurerm_monitor_action_group_data_source constructs incorrect event_hub_id Jun 3, 2022
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
2 participants