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_log_analytics_data_export_rule - fix destination_resource_id doesn't accept Event Hub Namespace #19868

Merged
merged 3 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,23 @@ func resourceOperationalinsightsDataExportCreateUpdate(d *pluginsdk.ResourceData
}

if strings.Contains(destinationId, "Microsoft.EventHub") {
eventhubId, err := eventhubs.ParseEventhubID(destinationId)
if err != nil {
return fmt.Errorf("parsing destination eventhub id error: %+v", err)
}
destinationId = namespaces.NewNamespaceID(eventhubId.SubscriptionId, eventhubId.ResourceGroupName, eventhubId.NamespaceName).ID()
parameters.Properties.Destination.ResourceId = destinationId
parameters.Properties.Destination.MetaData = &dataexport.DestinationMetaData{
EventHubName: utils.String(eventhubId.EventHubName),
_, err := eventhubs.ValidateNamespaceID(destinationId, "destination_resource_id")
if err == nil {
eventhubNamespace, err := eventhubs.ParseNamespaceID(destinationId)
if err != nil {
return fmt.Errorf("parsing destination eventhub namespaces id error: %+v", err)
}
parameters.Properties.Destination.ResourceId = eventhubNamespace.ID()
} else {
eventhubId, err := eventhubs.ParseEventhubID(destinationId)
if err != nil {
return fmt.Errorf("parsing destination eventhub id error: %+v", err)
}
destinationId = namespaces.NewNamespaceID(eventhubId.SubscriptionId, eventhubId.ResourceGroupName, eventhubId.NamespaceName).ID()
parameters.Properties.Destination.ResourceId = destinationId
parameters.Properties.Destination.MetaData = &dataexport.DestinationMetaData{
EventHubName: utils.String(eventhubId.EventHubName),
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ func TestAccLogAnalyticsDataExportRule_toEventhubs(t *testing.T) {
})
}

func TestAccLogAnalyticsDataExportRule_toEventhubNamespace(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_log_analytics_data_export_rule", "test")
r := LogAnalyticsDataExportRuleResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.toEventHubNamespace(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (t LogAnalyticsDataExportRuleResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := dataexport.ParseDataExportID(state.ID)
if err != nil {
Expand Down Expand Up @@ -229,3 +244,18 @@ resource "azurerm_log_analytics_data_export_rule" "test" {
}
`, r.template(data), data.RandomInteger)
}

func (r LogAnalyticsDataExportRuleResource) toEventHubNamespace(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_log_analytics_data_export_rule" "test" {
name = "acctest-DER-%d"
resource_group_name = azurerm_resource_group.test.name
workspace_resource_id = azurerm_log_analytics_workspace.test.id
destination_resource_id = azurerm_eventhub_namespace.test.id
table_names = ["Heartbeat"]
enabled = true
}
`, r.template(data), data.RandomInteger)
}