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

Error: in event_hub_receiver, exactly one of event_hub_id or (event_hub_namespace, event_hub_name) must be set #20146

Closed
1 task done
mpjtaylor opened this issue Jan 21, 2023 · 6 comments · Fixed by #21735
Closed
1 task done

Comments

@mpjtaylor
Copy link

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

1.2.7

AzureRM Provider Version

3.35.0

Affected Resource(s)/Data Source(s)

azurerm_monitor_action_group

Terraform Configuration Files

resource "azurerm_monitor_action_group" "support" {
  name                = "AlertsAction"
  resource_group_name = data.azurerm_resource_group.support.name
  short_name          = "alerts"

  event_hub_receiver {
    name                    = "s-alerts"
    event_hub_namespace     = local.management_monitor_namespace_name
    event_hub_name          = "e-alerts"
    subscription_id         = local.management_subscriptionid
    use_common_alert_schema = true
  }
  tags = local.common_tags
}

Debug Output/Panic Output

Error: in event_hub_receiver, exactly one of event_hub_id or (event_hub_namespace, event_hub_name) must be set
with module.terraform-azure_support.azurerm_monitor_action_group.support
on .terraform/modules/terraform-azure_support/log_analytics_workspace.tf line 11, in resource "azurerm_monitor_action_group" "support":

Expected Behaviour

Plan and apply should not change anything nor fail this seems to be random issue, sometimes i need to delete the azurerm_monitor_action_group in the portal and then let it recreate.

Actual Behaviour

Error: in event_hub_receiver, exactly one of event_hub_id or (event_hub_namespace, event_hub_name) must be set

Steps to Reproduce

terraform plan
terraform apply
terraform plan
terraform apply

Important Factoids

No response

References

#18322

@nlighten
Copy link

nlighten commented May 9, 2023

We consistently get this issue as soon as we change something to an azurerm_monitor_action_group that contains an event_hub_receiver. The initial create works but any update fails with

Error: in event_hub_receiver, exactly one of event_hub_id or (event_hub_namespace, event_hub_name) must be set ....

The bug seems to be related to the following change:

https://github.com/hashicorp/terraform-provider-azurerm/pull/17335/files

In the flattenMonitorActionGroupEventHubReceiver function the event_hub_id is always added when the FourPointOhBeta feature toggle equals false. So event_hub_id, event_hub_namespace, event_hub_name and subscription_id are all returned:

if !features.FourPointOhBeta() {
val["event_hub_id"] = eventhubs.NewEventhubID(subscriptionId, resourceGroup, eventHubNamespace, eventHubName).ID()
}

But the expandMonitorActionGroupEventHubReceiver throws the error we see when the FourPointOhBeta feature toggle equals false and all four items exist:

if !features.FourPointOhBeta() {
if eventHubNameSpace == "" && eventHubName == "" && subId == "" && val["event_hub_id"].(string) != "" {
eventHubId, err := eventhubs.ParseEventhubID(*utils.String(val["event_hub_id"].(string)))
if err != nil {
return nil, err
}
eventHubNameSpace, eventHubName, subId = eventHubId.NamespaceName, eventHubId.EventhubName, eventHubId.SubscriptionId
} else if val["event_hub_id"].(string) != "" || eventHubNameSpace == "" || eventHubName == "" {
return nil, fmt.Errorf("in event_hub_receiver, exactly one of event_hub_id or (event_hub_namespace, event_hub_name) must be set")
}

At a first glance it seems that adding the event_hub_id in flattenMonitorActionGroupEventHubReceiver can be removed from function flattenMonitorActionGroupEventHubReceiver but I am not sure.

@teowa I am not sure if you remember the change. If you do, I would appreciate your thoughts on the above.

@teowa
Copy link
Contributor

teowa commented May 10, 2023

Hi @mpjtaylor @nlighten, thanks for raising this, I have sent PR to fix this issue.

@DevopsMercenary
Copy link

any work around in the mean time ?

@mpjtaylor
Copy link
Author

Delete it and let it be recreated.

@mbfrahry mbfrahry added this to the v3.56.0 milestone May 10, 2023
@github-actions
Copy link

This functionality has been released in v3.56.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

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 May 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.