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_diagnostic_setting - support partner_solution_id #19114

Merged
merged 2 commits into from
Nov 3, 2022
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 @@ -86,6 +86,12 @@ func resourceMonitorDiagnosticSetting() *pluginsdk.Resource {
ValidateFunc: storageValidate.StorageAccountID,
},

"partner_solution_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: azure.ValidateResourceID,
},

"log_analytics_destination_type": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -266,6 +272,12 @@ func resourceMonitorDiagnosticSettingCreateUpdate(d *pluginsdk.ResourceData, met
valid = true
}

partnerSolutionId := d.Get("partner_solution_id").(string)
if partnerSolutionId != "" {
parameters.Properties.MarketplacePartnerId = utils.String(partnerSolutionId)
valid = true
}

if v := d.Get("log_analytics_destination_type").(string); v != "" {
if workspaceId != "" {
parameters.Properties.LogAnalyticsDestinationType = &v
Expand All @@ -275,7 +287,7 @@ func resourceMonitorDiagnosticSettingCreateUpdate(d *pluginsdk.ResourceData, met
}

if !valid {
return fmt.Errorf("Either a `eventhub_authorization_rule_id`, `log_analytics_workspace_id` or `storage_account_id` must be set")
return fmt.Errorf("either a `eventhub_authorization_rule_id`, `log_analytics_workspace_id`, `partner_solution_id` or `storage_account_id` must be set")
}

if _, err := client.CreateOrUpdate(ctx, diagnosticSettingId, parameters); err != nil {
Expand Down Expand Up @@ -356,6 +368,12 @@ func resourceMonitorDiagnosticSettingRead(d *pluginsdk.ResourceData, meta interf
d.Set("storage_account_id", storageAccountId)
}

partnerSolutionId := ""
if props.MarketplacePartnerId != nil && *props.MarketplacePartnerId != "" {
partnerSolutionId = *props.MarketplacePartnerId
d.Set("partner_solution_id", partnerSolutionId)
}

d.Set("log_analytics_destination_type", resp.Model.Properties.LogAnalyticsDestinationType)

if err := d.Set("log", flattenMonitorDiagnosticLogs(resp.Model.Properties.Logs)); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ func TestAccMonitorDiagnosticSetting_logAnalyticsWorkspaceDedicated(t *testing.T
})
}

func TestAccMonitorDiagnosticSetting_partnerSolution(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_monitor_diagnostic_setting", "test")
r := MonitorDiagnosticSettingResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.partnerSolution(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("partner_solution_id").Exists(),
check.That(data.ResourceName).Key("log.#").HasValue("2"),
check.That(data.ResourceName).Key("metric.#").HasValue("1"),
),
},
data.ImportStep(),
})
}

func TestAccMonitorDiagnosticSetting_storageAccount(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_monitor_diagnostic_setting", "test")
r := MonitorDiagnosticSettingResource{}
Expand Down Expand Up @@ -545,6 +563,71 @@ resource "azurerm_monitor_diagnostic_setting" "test" {
`, data.RandomInteger, data.Locations.Primary)
}

func (MonitorDiagnosticSettingResource) partnerSolution(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

data "azurerm_client_config" "current" {
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%[2]s"
}

resource "azurerm_key_vault" "test" {
name = "acctest%[3]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
tenant_id = data.azurerm_client_config.current.tenant_id
sku_name = "standard"
}

resource "azurerm_elastic_cloud_elasticsearch" "test" {
name = "acctest-elastic%[3]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku_name = "ess-monthly-consumption_Monthly"
elastic_cloud_email_address = "[email protected]"
}

resource "azurerm_monitor_diagnostic_setting" "test" {
name = "acctest-DS-%[1]d"
target_resource_id = azurerm_key_vault.test.id
partner_solution_id = azurerm_elastic_cloud_elasticsearch.test.id

log {
category = "AuditEvent"
enabled = false

retention_policy {
enabled = false
}
}

log {
category = "AzurePolicyEvaluationDetails"
enabled = false

retention_policy {
days = 0
enabled = false
}
}

metric {
category = "AllMetrics"

retention_policy {
enabled = false
}
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomIntOfLength(17))
}

func (MonitorDiagnosticSettingResource) storageAccount(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
10 changes: 7 additions & 3 deletions website/docs/r/monitor_diagnostic_setting.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,32 @@ The following arguments are supported:

-> **NOTE:** This can be sourced from [the `azurerm_eventhub_namespace_authorization_rule` resource](eventhub_namespace_authorization_rule.html) and is different from [a `azurerm_eventhub_authorization_rule` resource](eventhub_authorization_rule.html).

-> **NOTE:** One of `eventhub_authorization_rule_id`, `log_analytics_workspace_id` and `storage_account_id` must be specified.
-> **NOTE:** One of `eventhub_authorization_rule_id`, `log_analytics_workspace_id`, `partner_solution_id` and `storage_account_id` must be specified.

* `log` - (Optional) One or more `log` blocks as defined below.

-> **NOTE:** At least one `log` or `metric` block must be specified.

* `log_analytics_workspace_id` - (Optional) Specifies the ID of a Log Analytics Workspace where Diagnostics Data should be sent.

-> **NOTE:** One of `eventhub_authorization_rule_id`, `log_analytics_workspace_id` and `storage_account_id` must be specified.
-> **NOTE:** One of `eventhub_authorization_rule_id`, `log_analytics_workspace_id`, `partner_solution_id` and `storage_account_id` must be specified.

* `metric` - (Optional) One or more `metric` blocks as defined below.

-> **NOTE:** At least one `log` or `metric` block must be specified.

* `storage_account_id` - (Optional) The ID of the Storage Account where logs should be sent. Changing this forces a new resource to be created.

-> **NOTE:** One of `eventhub_authorization_rule_id`, `log_analytics_workspace_id` and `storage_account_id` must be specified.
-> **NOTE:** One of `eventhub_authorization_rule_id`, `log_analytics_workspace_id`, `partner_solution_id` and `storage_account_id` must be specified.

* `log_analytics_destination_type` - (Optional) When set to 'Dedicated' logs sent to a Log Analytics workspace will go into resource specific tables, instead of the legacy AzureDiagnostics table.

-> **NOTE:** This setting will only have an effect if a `log_analytics_workspace_id` is provided, and the resource is available for resource-specific logs. As of July 2019, this only includes Azure Data Factory. Please [see the documentation](https://docs.microsoft.com/azure/azure-monitor/platform/diagnostic-logs-stream-log-store#azure-diagnostics-vs-resource-specific) for more information.

* `partner_solution_id` - (Optional) The ID of the market partner solution where Diagnostics Data should be sent. For potential partner integrations, [click to learn more about partner integration](https://learn.microsoft.com/en-us/azure/partner-solutions/overview).

-> **NOTE:** One of `eventhub_authorization_rule_id`, `log_analytics_workspace_id`, `partner_solution_id` and `storage_account_id` must be specified.

---

A `log` block supports the following:
Expand Down