diff --git a/internal/services/monitor/client/client.go b/internal/services/monitor/client/client.go index 7a7c55be64fe..1c6616d4f1ae 100644 --- a/internal/services/monitor/client/client.go +++ b/internal/services/monitor/client/client.go @@ -8,6 +8,8 @@ import ( newActionGroupClient "github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-09-01-preview/insights" "github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-04-01/datacollectionendpoints" "github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-04-01/datacollectionrules" + diagnosticSettingClient "github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings" + diagnosticCategoryClient "github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories" "github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-08-01/scheduledqueryrules" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) @@ -29,8 +31,8 @@ type Client struct { AlertRulesClient *classic.AlertRulesClient DataCollectionRulesClient *datacollectionrules.DataCollectionRulesClient DataCollectionEndpointsClient *datacollectionendpoints.DataCollectionEndpointsClient - DiagnosticSettingsClient *classic.DiagnosticSettingsClient - DiagnosticSettingsCategoryClient *classic.DiagnosticSettingsCategoryClient + DiagnosticSettingsClient *diagnosticSettingClient.DiagnosticSettingsClient + DiagnosticSettingsCategoryClient *diagnosticCategoryClient.DiagnosticSettingsCategoriesClient LogProfilesClient *classic.LogProfilesClient MetricAlertsClient *classic.MetricAlertsClient PrivateLinkScopesClient *classic.PrivateLinkScopesClient @@ -61,16 +63,13 @@ func NewClient(o *common.ClientOptions) *Client { AlertRulesClient := classic.NewAlertRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&AlertRulesClient.Client, o.ResourceManagerAuthorizer) - DataCollectionEndpointsClient := datacollectionendpoints.NewDataCollectionEndpointsClientWithBaseURI(o.ResourceManagerEndpoint) - o.ConfigureClient(&DataCollectionEndpointsClient.Client, o.ResourceManagerAuthorizer) - DataCollectionRulesClient := datacollectionrules.NewDataCollectionRulesClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&DataCollectionRulesClient.Client, o.ResourceManagerAuthorizer) - DiagnosticSettingsClient := classic.NewDiagnosticSettingsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + DiagnosticSettingsClient := diagnosticSettingClient.NewDiagnosticSettingsClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&DiagnosticSettingsClient.Client, o.ResourceManagerAuthorizer) - DiagnosticSettingsCategoryClient := classic.NewDiagnosticSettingsCategoryClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + DiagnosticSettingsCategoryClient := diagnosticCategoryClient.NewDiagnosticSettingsCategoriesClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&DiagnosticSettingsCategoryClient.Client, o.ResourceManagerAuthorizer) LogProfilesClient := classic.NewLogProfilesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) @@ -100,7 +99,6 @@ func NewClient(o *common.ClientOptions) *Client { ActivityLogAlertsClient: &ActivityLogAlertsClient, AlertRulesClient: &AlertRulesClient, DataCollectionRulesClient: &DataCollectionRulesClient, - DataCollectionEndpointsClient: &DataCollectionEndpointsClient, DiagnosticSettingsClient: &DiagnosticSettingsClient, DiagnosticSettingsCategoryClient: &DiagnosticSettingsCategoryClient, LogProfilesClient: &LogProfilesClient, diff --git a/internal/services/monitor/monitor_diagnostic_categories_data_source.go b/internal/services/monitor/monitor_diagnostic_categories_data_source.go index e95e3d2bdc80..6bf806fa63f2 100644 --- a/internal/services/monitor/monitor_diagnostic_categories_data_source.go +++ b/internal/services/monitor/monitor_diagnostic_categories_data_source.go @@ -5,15 +5,17 @@ import ( "strings" "time" - "github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-07-01-preview/insights" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" ) func dataSourceMonitorDiagnosticCategories() *pluginsdk.Resource { - return &pluginsdk.Resource{ + resource := &pluginsdk.Resource{ Read: dataSourceMonitorDiagnosticCategoriesRead, Timeouts: &pluginsdk.ResourceTimeout{ @@ -27,7 +29,14 @@ func dataSourceMonitorDiagnosticCategories() *pluginsdk.Resource { ValidateFunc: azure.ValidateResourceID, }, - "logs": { + "log_category_types": { + Type: pluginsdk.TypeSet, + Elem: &pluginsdk.Schema{Type: pluginsdk.TypeString}, + Set: pluginsdk.HashString, + Computed: true, + }, + + "log_category_groups": { Type: pluginsdk.TypeSet, Elem: &pluginsdk.Schema{Type: pluginsdk.TypeString}, Set: pluginsdk.HashString, @@ -42,6 +51,18 @@ func dataSourceMonitorDiagnosticCategories() *pluginsdk.Resource { }, }, } + + if !features.FourPointOhBeta() { + resource.Schema["logs"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeSet, + Elem: &pluginsdk.Schema{Type: pluginsdk.TypeString}, + Set: pluginsdk.HashString, + Computed: true, + Deprecated: "`logs` will be removed in favour of the property `log_category_types` in version 4.0 of the AzureRM Provider.", + } + } + + return resource } func dataSourceMonitorDiagnosticCategoriesRead(d *pluginsdk.ResourceData, meta interface{}) error { @@ -49,50 +70,71 @@ func dataSourceMonitorDiagnosticCategoriesRead(d *pluginsdk.ResourceData, meta i ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - actualResourceId := d.Get("resource_id").(string) + actualResourceId := commonids.NewScopeID(d.Get("resource_id").(string)) // trim off the leading `/` since the CheckExistenceByID / List methods don't expect it - resourceId := strings.TrimPrefix(actualResourceId, "/") + resourceId := strings.TrimPrefix(actualResourceId.Scope, "/") + resourceIdToList, err := commonids.ParseScopeID(resourceId) + if err != nil { + return fmt.Errorf("parsing resource id error: %+v", err) + } // then retrieve the possible Diagnostics Categories for this Resource - categories, err := categoriesClient.List(ctx, resourceId) + categories, err := categoriesClient.DiagnosticSettingsCategoryList(ctx, *resourceIdToList) if err != nil { return fmt.Errorf("retrieving Diagnostics Categories for Resource %q: %+v", actualResourceId, err) } - if categories.Value == nil { + if categories.Model == nil && categories.Model.Value == nil { return fmt.Errorf("retrieving Diagnostics Categories for Resource %q: `categories.Value` was nil", actualResourceId) } - d.SetId(actualResourceId) - val := *categories.Value + d.SetId(actualResourceId.ID()) + val := *categories.Model.Value metrics := make([]string, 0) logs := make([]string, 0) + categoryGroups := make([]string, 0) for _, v := range val { if v.Name == nil { continue } - if category := v.DiagnosticSettingsCategory; category != nil { - switch category.CategoryType { - case insights.CategoryTypeLogs: - logs = append(logs, *v.Name) - case insights.CategoryTypeMetrics: - metrics = append(metrics, *v.Name) - default: - return fmt.Errorf("Unsupported category type %q", string(category.CategoryType)) + if category := v.Properties; category != nil { + if category.CategoryGroups != nil { + for _, item := range *category.CategoryGroups { + categoryGroups = append(categoryGroups, item) + } + } + if category.CategoryType != nil { + switch *category.CategoryType { + case diagnosticsettingscategories.CategoryTypeLogs: + logs = append(logs, *v.Name) + case diagnosticsettingscategories.CategoryTypeMetrics: + metrics = append(metrics, *v.Name) + default: + return fmt.Errorf("Unsupported category type %q", string(*category.CategoryType)) + } } } } - if err := d.Set("logs", logs); err != nil { - return fmt.Errorf("setting `logs`: %+v", err) + if err := d.Set("log_category_types", logs); err != nil { + return fmt.Errorf("setting `log_category_types`: %+v", err) + } + + if !features.FourPointOhBeta() { + if err := d.Set("logs", logs); err != nil { + return fmt.Errorf("setting `log`: %+v", err) + } } if err := d.Set("metrics", metrics); err != nil { return fmt.Errorf("setting `metrics`: %+v", err) } + if err := d.Set("log_category_groups", categoryGroups); err != nil { + return fmt.Errorf("setting `log_category_groups`: %+v", err) + } return nil } diff --git a/internal/services/monitor/monitor_diagnostic_categories_data_source_test.go b/internal/services/monitor/monitor_diagnostic_categories_data_source_test.go index 50a045b45581..c93f9c2a940f 100644 --- a/internal/services/monitor/monitor_diagnostic_categories_data_source_test.go +++ b/internal/services/monitor/monitor_diagnostic_categories_data_source_test.go @@ -20,6 +20,8 @@ func TestAccDataSourceMonitorDiagnosticCategories_appService(t *testing.T) { Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("metrics.#").Exists(), check.That(data.ResourceName).Key("logs.#").Exists(), + check.That(data.ResourceName).Key("log_category_types.#").Exists(), + check.That(data.ResourceName).Key("log_category_groups.#").Exists(), ), }, }) @@ -35,6 +37,8 @@ func TestAccDataSourceMonitorDiagnosticCategories_storageAccount(t *testing.T) { Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("metrics.#").Exists(), check.That(data.ResourceName).Key("logs.#").Exists(), + check.That(data.ResourceName).Key("log_category_types.#").Exists(), + check.That(data.ResourceName).Key("log_category_groups.#").Exists(), ), }, }) diff --git a/internal/services/monitor/monitor_diagnostic_setting_resource.go b/internal/services/monitor/monitor_diagnostic_setting_resource.go index 7a57158dc53a..eebceddeb3db 100644 --- a/internal/services/monitor/monitor_diagnostic_setting_resource.go +++ b/internal/services/monitor/monitor_diagnostic_setting_resource.go @@ -1,15 +1,16 @@ package monitor import ( + "bytes" "context" "fmt" "log" "strings" "time" - "github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-07-01-preview/insights" "github.com/hashicorp/go-azure-helpers/lang/response" authRuleParse "github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/authorizationrulesnamespaces" + "github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" @@ -103,7 +104,12 @@ func resourceMonitorDiagnosticSetting() *pluginsdk.Resource { Schema: map[string]*pluginsdk.Schema{ "category": { Type: pluginsdk.TypeString, - Required: true, + Optional: true, + }, + + "category_group": { + Type: pluginsdk.TypeString, + Optional: true, }, "enabled": { @@ -133,6 +139,7 @@ func resourceMonitorDiagnosticSetting() *pluginsdk.Resource { }, }, }, + Set: resourceMonitorDiagnosticLogSettingHash, }, "metric": { @@ -172,6 +179,7 @@ func resourceMonitorDiagnosticSetting() *pluginsdk.Resource { }, }, }, + Set: resourceMonitorDiagnosticMetricsSettingHash, }, }, } @@ -185,17 +193,18 @@ func resourceMonitorDiagnosticSettingCreateUpdate(d *pluginsdk.ResourceData, met name := d.Get("name").(string) actualResourceId := d.Get("target_resource_id").(string) + diagnosticSettingId := diagnosticsettings.NewScopedDiagnosticSettingID(actualResourceId, name) if d.IsNewResource() { - existing, err := client.Get(ctx, actualResourceId, name) + existing, err := client.Get(ctx, diagnosticSettingId) if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Monitor Diagnostic Setting %q for Resource %q: %s", name, actualResourceId, err) + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing Monitor Diagnostic Setting %q for Resource %q: %s", diagnosticSettingId.Name, diagnosticSettingId.ResourceUri, err) } } - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_monitor_diagnostic_setting", fmt.Sprintf("%s|%s", actualResourceId, name)) + if existing.Model != nil && existing.Model.Id != nil && *existing.Model.Id != "" { + return tf.ImportAsExistsError("azurerm_monitor_diagnostic_setting", *existing.Model.Id) } } @@ -212,14 +221,14 @@ func resourceMonitorDiagnosticSettingCreateUpdate(d *pluginsdk.ResourceData, met // also if there's none enabled valid := false for _, v := range logs { - if v.Enabled != nil && *v.Enabled { + if v.Enabled { valid = true break } } if !valid { for _, v := range metrics { - if v.Enabled != nil && *v.Enabled { + if v.Enabled { valid = true break } @@ -230,8 +239,8 @@ func resourceMonitorDiagnosticSettingCreateUpdate(d *pluginsdk.ResourceData, met return fmt.Errorf("At least one `log` or `metric` must be enabled") } - properties := insights.DiagnosticSettingsResource{ - DiagnosticSettings: &insights.DiagnosticSettings{ + parameters := diagnosticsettings.DiagnosticSettingsResource{ + Properties: &diagnosticsettings.DiagnosticSettings{ Logs: &logs, Metrics: &metrics, }, @@ -241,26 +250,26 @@ func resourceMonitorDiagnosticSettingCreateUpdate(d *pluginsdk.ResourceData, met eventHubAuthorizationRuleId := d.Get("eventhub_authorization_rule_id").(string) eventHubName := d.Get("eventhub_name").(string) if eventHubAuthorizationRuleId != "" { - properties.DiagnosticSettings.EventHubAuthorizationRuleID = utils.String(eventHubAuthorizationRuleId) - properties.DiagnosticSettings.EventHubName = utils.String(eventHubName) + parameters.Properties.EventHubAuthorizationRuleId = utils.String(eventHubAuthorizationRuleId) + parameters.Properties.EventHubName = utils.String(eventHubName) valid = true } workspaceId := d.Get("log_analytics_workspace_id").(string) if workspaceId != "" { - properties.DiagnosticSettings.WorkspaceID = utils.String(workspaceId) + parameters.Properties.WorkspaceId = utils.String(workspaceId) valid = true } storageAccountId := d.Get("storage_account_id").(string) if storageAccountId != "" { - properties.DiagnosticSettings.StorageAccountID = utils.String(storageAccountId) + parameters.Properties.StorageAccountId = utils.String(storageAccountId) valid = true } if v := d.Get("log_analytics_destination_type").(string); v != "" { if workspaceId != "" { - properties.DiagnosticSettings.LogAnalyticsDestinationType = &v + parameters.Properties.LogAnalyticsDestinationType = &v } else { return fmt.Errorf("`log_analytics_workspace_id` must be set for `log_analytics_destination_type` to be used") } @@ -270,18 +279,16 @@ func resourceMonitorDiagnosticSettingCreateUpdate(d *pluginsdk.ResourceData, met return fmt.Errorf("Either a `eventhub_authorization_rule_id`, `log_analytics_workspace_id` or `storage_account_id` must be set") } - // the Azure SDK prefixes the URI with a `/` such this makes a bad request if we don't trim the `/` - targetResourceId := strings.TrimPrefix(actualResourceId, "/") - if _, err := client.CreateOrUpdate(ctx, targetResourceId, properties, name); err != nil { + if _, err := client.CreateOrUpdate(ctx, diagnosticSettingId, parameters); err != nil { return fmt.Errorf("creating Monitor Diagnostics Setting %q for Resource %q: %+v", name, actualResourceId, err) } - read, err := client.Get(ctx, targetResourceId, name) + read, err := client.Get(ctx, diagnosticSettingId) if err != nil { return err } - if read.ID == nil { - return fmt.Errorf("Cannot read ID for Monitor Diagnostics %q for Resource ID %q", name, actualResourceId) + if read.Model == nil && read.Model.Id == nil { + return fmt.Errorf("Cannot read ID for Monitor Diagnostics %q for Resource ID %q", diagnosticSettingId.Name, diagnosticSettingId.ResourceUri) } d.SetId(fmt.Sprintf("%s|%s", actualResourceId, name)) @@ -299,11 +306,10 @@ func resourceMonitorDiagnosticSettingRead(d *pluginsdk.ResourceData, meta interf return err } - actualResourceId := id.ResourceID - targetResourceId := strings.TrimPrefix(actualResourceId, "/") - resp, err := client.Get(ctx, targetResourceId, id.Name) + actualResourceId := id.ResourceUri + resp, err := client.Get(ctx, *id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { log.Printf("[WARN] Monitor Diagnostics Setting %q was not found for Resource %q - removing from state!", id.Name, actualResourceId) d.SetId("") return nil @@ -313,51 +319,54 @@ func resourceMonitorDiagnosticSettingRead(d *pluginsdk.ResourceData, meta interf } d.Set("name", id.Name) - d.Set("target_resource_id", id.ResourceID) - - d.Set("eventhub_name", resp.EventHubName) - eventhubAuthorizationRuleId := "" - if resp.EventHubAuthorizationRuleID != nil && *resp.EventHubAuthorizationRuleID != "" { - authRuleId := utils.NormalizeNilableString(resp.EventHubAuthorizationRuleID) - parsedId, err := authRuleParse.ParseAuthorizationRuleIDInsensitively(authRuleId) - if err != nil { - return err - } - - eventhubAuthorizationRuleId = parsedId.ID() - } - d.Set("eventhub_authorization_rule_id", eventhubAuthorizationRuleId) + d.Set("target_resource_id", id.ResourceUri) + + if model := resp.Model; model != nil { + if props := model.Properties; props != nil { + d.Set("eventhub_name", props.EventHubName) + eventhubAuthorizationRuleId := "" + if props.EventHubAuthorizationRuleId != nil && *props.EventHubAuthorizationRuleId != "" { + authRuleId := utils.NormalizeNilableString(props.EventHubAuthorizationRuleId) + parsedId, err := authRuleParse.ParseAuthorizationRuleIDInsensitively(authRuleId) + if err != nil { + return err + } + eventhubAuthorizationRuleId = parsedId.ID() + } + d.Set("eventhub_authorization_rule_id", eventhubAuthorizationRuleId) - workspaceId := "" - if resp.WorkspaceID != nil && *resp.WorkspaceID != "" { - parsedId, err := logAnalyticsParse.LogAnalyticsWorkspaceID(*resp.WorkspaceID) - if err != nil { - return err - } + workspaceId := "" + if props.WorkspaceId != nil && *props.WorkspaceId != "" { + parsedId, err := logAnalyticsParse.LogAnalyticsWorkspaceID(*props.WorkspaceId) + if err != nil { + return err + } - workspaceId = parsedId.ID() - } - d.Set("log_analytics_workspace_id", workspaceId) + workspaceId = parsedId.ID() + } + d.Set("log_analytics_workspace_id", workspaceId) - storageAccountId := "" - if resp.StorageAccountID != nil && *resp.StorageAccountID != "" { - parsedId, err := storageParse.StorageAccountID(*resp.StorageAccountID) - if err != nil { - return err - } + storageAccountId := "" + if props.StorageAccountId != nil && *props.StorageAccountId != "" { + parsedId, err := storageParse.StorageAccountID(*props.StorageAccountId) + if err != nil { + return err + } - storageAccountId = parsedId.ID() - } - d.Set("storage_account_id", storageAccountId) + storageAccountId = parsedId.ID() + d.Set("storage_account_id", storageAccountId) + } - d.Set("log_analytics_destination_type", resp.LogAnalyticsDestinationType) + d.Set("log_analytics_destination_type", resp.Model.Properties.LogAnalyticsDestinationType) - if err := d.Set("log", flattenMonitorDiagnosticLogs(resp.Logs)); err != nil { - return fmt.Errorf("setting `log`: %+v", err) - } + if err := d.Set("log", flattenMonitorDiagnosticLogs(resp.Model.Properties.Logs)); err != nil { + return fmt.Errorf("setting `log`: %+v", err) + } - if err := d.Set("metric", flattenMonitorDiagnosticMetrics(resp.Metrics)); err != nil { - return fmt.Errorf("setting `metric`: %+v", err) + if err := d.Set("metric", flattenMonitorDiagnosticMetrics(resp.Model.Properties.Metrics)); err != nil { + return fmt.Errorf("setting `metric`: %+v", err) + } + } } return nil @@ -373,37 +382,36 @@ func resourceMonitorDiagnosticSettingDelete(d *pluginsdk.ResourceData, meta inte return err } - targetResourceId := strings.TrimPrefix(id.ResourceID, "/") - resp, err := client.Delete(ctx, targetResourceId, id.Name) + resp, err := client.Delete(ctx, *id) if err != nil { - if !response.WasNotFound(resp.Response) { - return fmt.Errorf("deleting Monitor Diagnostics Setting %q for Resource %q: %+v", id.Name, targetResourceId, err) + if !response.WasNotFound(resp.HttpResponse) { + return fmt.Errorf("deleting Monitor Diagnostics Setting %q for Resource %q: %+v", id.Name, id.ResourceUri, err) } } // API appears to be eventually consistent (identified during tainting this resource) - log.Printf("[DEBUG] Waiting for Monitor Diagnostic Setting %q for Resource %q to disappear", id.Name, id.ResourceID) + log.Printf("[DEBUG] Waiting for Monitor Diagnostic Setting %q for Resource %q to disappear", id.Name, id.ResourceUri) stateConf := &pluginsdk.StateChangeConf{ Pending: []string{"Exists"}, Target: []string{"NotFound"}, - Refresh: monitorDiagnosticSettingDeletedRefreshFunc(ctx, client, targetResourceId, id.Name), + Refresh: monitorDiagnosticSettingDeletedRefreshFunc(ctx, client, *id), MinTimeout: 15 * time.Second, ContinuousTargetOccurence: 5, Timeout: d.Timeout(pluginsdk.TimeoutDelete), } if _, err = stateConf.WaitForStateContext(ctx); err != nil { - return fmt.Errorf("waiting for Monitor Diagnostic Setting %q for Resource %q to become available: %s", id.Name, id.ResourceID, err) + return fmt.Errorf("waiting for Monitor Diagnostic Setting %q for Resource %q to become available: %s", id.Name, id.ResourceUri, err) } return nil } -func monitorDiagnosticSettingDeletedRefreshFunc(ctx context.Context, client *insights.DiagnosticSettingsClient, targetResourceId string, name string) pluginsdk.StateRefreshFunc { +func monitorDiagnosticSettingDeletedRefreshFunc(ctx context.Context, client *diagnosticsettings.DiagnosticSettingsClient, targetResourceId diagnosticsettings.ScopedDiagnosticSettingId) pluginsdk.StateRefreshFunc { return func() (interface{}, string, error) { - res, err := client.Get(ctx, targetResourceId, name) + res, err := client.Get(ctx, targetResourceId) if err != nil { - if utils.ResponseWasNotFound(res.Response) { + if response.WasNotFound(res.HttpResponse) { return "NotFound", "NotFound", nil } return nil, "", fmt.Errorf("issuing read request in monitorDiagnosticSettingDeletedRefreshFunc: %s", err) @@ -413,31 +421,36 @@ func monitorDiagnosticSettingDeletedRefreshFunc(ctx context.Context, client *ins } } -func expandMonitorDiagnosticsSettingsLogs(input []interface{}) []insights.LogSettings { - results := make([]insights.LogSettings, 0) +func expandMonitorDiagnosticsSettingsLogs(input []interface{}) []diagnosticsettings.LogSettings { + results := make([]diagnosticsettings.LogSettings, 0) for _, raw := range input { v := raw.(map[string]interface{}) category := v["category"].(string) + categoryGroup := v["category_group"].(string) enabled := v["enabled"].(bool) policiesRaw := v["retention_policy"].([]interface{}) - var retentionPolicy *insights.RetentionPolicy + var retentionPolicy *diagnosticsettings.RetentionPolicy if len(policiesRaw) != 0 { policyRaw := policiesRaw[0].(map[string]interface{}) retentionDays := policyRaw["days"].(int) retentionEnabled := policyRaw["enabled"].(bool) - retentionPolicy = &insights.RetentionPolicy{ - Days: utils.Int32(int32(retentionDays)), - Enabled: utils.Bool(retentionEnabled), + retentionPolicy = &diagnosticsettings.RetentionPolicy{ + Days: int64(retentionDays), + Enabled: retentionEnabled, } } - output := insights.LogSettings{ - Category: utils.String(category), - Enabled: utils.Bool(enabled), + output := diagnosticsettings.LogSettings{ + Enabled: enabled, RetentionPolicy: retentionPolicy, } + if category != "" { + output.Category = utils.String(category) + } else { + output.CategoryGroup = utils.String(categoryGroup) + } results = append(results, output) } @@ -445,7 +458,7 @@ func expandMonitorDiagnosticsSettingsLogs(input []interface{}) []insights.LogSet return results } -func flattenMonitorDiagnosticLogs(input *[]insights.LogSettings) []interface{} { +func flattenMonitorDiagnosticLogs(input *[]diagnosticsettings.LogSettings) []interface{} { results := make([]interface{}, 0) if input == nil { return results @@ -458,22 +471,20 @@ func flattenMonitorDiagnosticLogs(input *[]insights.LogSettings) []interface{} { output["category"] = *v.Category } - if v.Enabled != nil { - output["enabled"] = *v.Enabled + if v.CategoryGroup != nil { + output["category_group"] = *v.CategoryGroup } + output["enabled"] = v.Enabled + policies := make([]interface{}, 0) if inputPolicy := v.RetentionPolicy; inputPolicy != nil { outputPolicy := make(map[string]interface{}) - if inputPolicy.Days != nil { - outputPolicy["days"] = int(*inputPolicy.Days) - } + outputPolicy["days"] = int(inputPolicy.Days) - if inputPolicy.Enabled != nil { - outputPolicy["enabled"] = *inputPolicy.Enabled - } + outputPolicy["enabled"] = inputPolicy.Enabled policies = append(policies, outputPolicy) } @@ -486,8 +497,8 @@ func flattenMonitorDiagnosticLogs(input *[]insights.LogSettings) []interface{} { return results } -func expandMonitorDiagnosticsSettingsMetrics(input []interface{}) []insights.MetricSettings { - results := make([]insights.MetricSettings, 0) +func expandMonitorDiagnosticsSettingsMetrics(input []interface{}) []diagnosticsettings.MetricSettings { + results := make([]diagnosticsettings.MetricSettings, 0) for _, raw := range input { v := raw.(map[string]interface{}) @@ -496,19 +507,19 @@ func expandMonitorDiagnosticsSettingsMetrics(input []interface{}) []insights.Met enabled := v["enabled"].(bool) policiesRaw := v["retention_policy"].([]interface{}) - var retentionPolicy *insights.RetentionPolicy + var retentionPolicy *diagnosticsettings.RetentionPolicy if len(policiesRaw) > 0 && policiesRaw[0] != nil { policyRaw := policiesRaw[0].(map[string]interface{}) retentionDays := policyRaw["days"].(int) retentionEnabled := policyRaw["enabled"].(bool) - retentionPolicy = &insights.RetentionPolicy{ - Days: utils.Int32(int32(retentionDays)), - Enabled: utils.Bool(retentionEnabled), + retentionPolicy = &diagnosticsettings.RetentionPolicy{ + Days: int64(retentionDays), + Enabled: retentionEnabled, } } - output := insights.MetricSettings{ + output := diagnosticsettings.MetricSettings{ Category: utils.String(category), - Enabled: utils.Bool(enabled), + Enabled: enabled, RetentionPolicy: retentionPolicy, } @@ -518,7 +529,7 @@ func expandMonitorDiagnosticsSettingsMetrics(input []interface{}) []insights.Met return results } -func flattenMonitorDiagnosticMetrics(input *[]insights.MetricSettings) []interface{} { +func flattenMonitorDiagnosticMetrics(input *[]diagnosticsettings.MetricSettings) []interface{} { results := make([]interface{}, 0) if input == nil { return results @@ -531,22 +542,16 @@ func flattenMonitorDiagnosticMetrics(input *[]insights.MetricSettings) []interfa output["category"] = *v.Category } - if v.Enabled != nil { - output["enabled"] = *v.Enabled - } + output["enabled"] = v.Enabled policies := make([]interface{}, 0) if inputPolicy := v.RetentionPolicy; inputPolicy != nil { outputPolicy := make(map[string]interface{}) - if inputPolicy.Days != nil { - outputPolicy["days"] = int(*inputPolicy.Days) - } + outputPolicy["days"] = int(inputPolicy.Days) - if inputPolicy.Enabled != nil { - outputPolicy["enabled"] = *inputPolicy.Enabled - } + outputPolicy["enabled"] = inputPolicy.Enabled policies = append(policies, outputPolicy) } @@ -559,20 +564,60 @@ func flattenMonitorDiagnosticMetrics(input *[]insights.MetricSettings) []interfa return results } -type monitorDiagnosticId struct { - ResourceID string - Name string -} - -func ParseMonitorDiagnosticId(monitorId string) (*monitorDiagnosticId, error) { +func ParseMonitorDiagnosticId(monitorId string) (*diagnosticsettings.ScopedDiagnosticSettingId, error) { v := strings.Split(monitorId, "|") if len(v) != 2 { return nil, fmt.Errorf("Expected the Monitor Diagnostics ID to be in the format `{resourceId}|{name}` but got %d segments", len(v)) } - identifier := monitorDiagnosticId{ - ResourceID: v[0], - Name: v[1], + identifier := diagnosticsettings.ScopedDiagnosticSettingId{ + ResourceUri: v[0], + Name: v[1], } return &identifier, nil } + +func resourceMonitorDiagnosticLogSettingHash(input interface{}) int { + var buf bytes.Buffer + if rawData, ok := input.(map[string]interface{}); ok { + if category, ok := rawData["category"]; ok { + buf.WriteString(fmt.Sprintf("%s-", category.(string))) + } + if categoryGroup, ok := rawData["category_group"]; ok { + buf.WriteString(fmt.Sprintf("%s-", categoryGroup.(string))) + } + if enabled, ok := rawData["enabled"]; ok { + buf.WriteString(fmt.Sprintf("%t-", enabled.(bool))) + } + if policy, ok := rawData["retention_policy"].(map[string]interface{}); ok { + if policyEnabled, ok := policy["enabled"]; ok { + buf.WriteString(fmt.Sprintf("%t-", policyEnabled.(bool))) + } + if days, ok := policy["days"]; ok { + buf.WriteString(fmt.Sprintf("%d-", days.(int))) + } + } + } + return pluginsdk.HashString(buf.String()) +} + +func resourceMonitorDiagnosticMetricsSettingHash(input interface{}) int { + var buf bytes.Buffer + if rawData, ok := input.(map[string]interface{}); ok { + if category, ok := rawData["category"]; ok { + buf.WriteString(fmt.Sprintf("%s-", category.(string))) + } + if enabled, ok := rawData["enabled"]; ok { + buf.WriteString(fmt.Sprintf("%t-", enabled.(bool))) + } + if policy, ok := rawData["retention_policy"].(map[string]interface{}); ok { + if policyEnabled, ok := policy["enabled"]; ok { + buf.WriteString(fmt.Sprintf("%t-", policyEnabled.(bool))) + } + if days, ok := policy["days"]; ok { + buf.WriteString(fmt.Sprintf("%d-", days.(int))) + } + } + } + return pluginsdk.HashString(buf.String()) +} diff --git a/internal/services/monitor/monitor_diagnostic_setting_resource_test.go b/internal/services/monitor/monitor_diagnostic_setting_resource_test.go index b0d910a18aa1..6b815a82b277 100644 --- a/internal/services/monitor/monitor_diagnostic_setting_resource_test.go +++ b/internal/services/monitor/monitor_diagnostic_setting_resource_test.go @@ -3,7 +3,6 @@ package monitor_test import ( "context" "fmt" - "strings" "testing" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" @@ -34,6 +33,24 @@ func TestAccMonitorDiagnosticSetting_eventhub(t *testing.T) { }) } +func TestAccMonitorDiagnosticSetting_CategoryGroup(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_monitor_diagnostic_setting", "test") + r := MonitorDiagnosticSettingResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.categoryGroup(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("eventhub_name").Exists(), + check.That(data.ResourceName).Key("eventhub_authorization_rule_id").Exists(), + check.That(data.ResourceName).Key("log.#").HasValue("2"), + check.That(data.ResourceName).Key("metric.#").HasValue("1"), + ), + }, + data.ImportStep(), + }) +} + func TestAccMonitorDiagnosticSetting_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_monitor_diagnostic_setting", "test") r := MonitorDiagnosticSettingResource{} @@ -123,15 +140,15 @@ func (t MonitorDiagnosticSettingResource) Exists(ctx context.Context, clients *c if err != nil { return nil, err } - actualResourceId := id.ResourceID - targetResourceId := strings.TrimPrefix(actualResourceId, "/") + // actualResourceId := id.ResourceUri + // targetResourceId := strings.TrimPrefix(actualResourceId, "/") - resp, err := clients.Monitor.DiagnosticSettingsClient.Get(ctx, targetResourceId, id.Name) + resp, err := clients.Monitor.DiagnosticSettingsClient.Get(ctx, *id) if err != nil { return nil, fmt.Errorf("reading diagnostic setting (%s): %+v", id, err) } - return utils.Bool(resp.ID != nil), nil + return utils.Bool(resp.Model != nil && resp.Model.Id != nil), nil } func (MonitorDiagnosticSettingResource) eventhub(data acceptance.TestData) string { @@ -218,6 +235,88 @@ resource "azurerm_monitor_diagnostic_setting" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomIntOfLength(17)) } +func (MonitorDiagnosticSettingResource) categoryGroup(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_eventhub_namespace" "test" { + name = "acctest-EHN-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Basic" +} + +resource "azurerm_eventhub" "test" { + name = "acctest-EH-%[1]d" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name + partition_count = 2 + message_retention = 1 +} + +resource "azurerm_eventhub_namespace_authorization_rule" "test" { + name = "example" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name + listen = true + send = true + manage = true +} + +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_monitor_diagnostic_setting" "test" { + name = "acctest-DS-%[1]d" + target_resource_id = azurerm_key_vault.test.id + eventhub_authorization_rule_id = azurerm_eventhub_namespace_authorization_rule.test.id + eventhub_name = azurerm_eventhub.test.name + + log { + category_group = "Audit" + enabled = true + + retention_policy { + days = 0 + enabled = false + } + } + + log { + category_group = "allLogs" + enabled = false + + retention_policy { + days = 0 + enabled = false + } + } + + metric { + category = "AllMetrics" + + retention_policy { + enabled = false + } + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomIntOfLength(17)) +} func (r MonitorDiagnosticSettingResource) requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -436,56 +535,6 @@ resource "azurerm_monitor_diagnostic_setting" "test" { } } - log { - category = "AirflowDagProcessingLogs" - enabled = false - - retention_policy { - days = 0 - enabled = false - } - } - - log { - category = "AirflowSchedulerLogs" - enabled = false - - retention_policy { - days = 0 - enabled = false - } - } - - log { - category = "AirflowTaskLogs" - enabled = false - - retention_policy { - days = 0 - enabled = false - } - } - - log { - category = "AirflowWebLogs" - enabled = false - - retention_policy { - days = 0 - enabled = false - } - } - - log { - category = "AirflowWorkerLogs" - enabled = false - - retention_policy { - days = 0 - enabled = false - } - } - metric { category = "AllMetrics" retention_policy { diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/README.md new file mode 100644 index 000000000000..2b11c6fd03ad --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/README.md @@ -0,0 +1,89 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings` Documentation + +The `diagnosticsettings` SDK allows for interaction with the Azure Resource Manager Service `insights` (API Version `2021-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings" +``` + + +### Client Initialization + +```go +client := diagnosticsettings.NewDiagnosticSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DiagnosticSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := diagnosticsettings.NewScopedDiagnosticSettingID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "nameValue") + +payload := diagnosticsettings.DiagnosticSettingsResource{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticSettingsClient.Delete` + +```go +ctx := context.TODO() +id := diagnosticsettings.NewScopedDiagnosticSettingID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "nameValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticSettingsClient.Get` + +```go +ctx := context.TODO() +id := diagnosticsettings.NewScopedDiagnosticSettingID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "nameValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticSettingsClient.List` + +```go +ctx := context.TODO() +id := diagnosticsettings.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/client.go new file mode 100644 index 000000000000..27de3a96a134 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/client.go @@ -0,0 +1,18 @@ +package diagnosticsettings + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticSettingsClient struct { + Client autorest.Client + baseUri string +} + +func NewDiagnosticSettingsClientWithBaseURI(endpoint string) DiagnosticSettingsClient { + return DiagnosticSettingsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/id_scopeddiagnosticsetting.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/id_scopeddiagnosticsetting.go new file mode 100644 index 000000000000..a53e722bad9d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/id_scopeddiagnosticsetting.go @@ -0,0 +1,110 @@ +package diagnosticsettings + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ScopedDiagnosticSettingId{} + +// ScopedDiagnosticSettingId is a struct representing the Resource ID for a Scoped Diagnostic Setting +type ScopedDiagnosticSettingId struct { + ResourceUri string + Name string +} + +// NewScopedDiagnosticSettingID returns a new ScopedDiagnosticSettingId struct +func NewScopedDiagnosticSettingID(resourceUri string, name string) ScopedDiagnosticSettingId { + return ScopedDiagnosticSettingId{ + ResourceUri: resourceUri, + Name: name, + } +} + +// ParseScopedDiagnosticSettingID parses 'input' into a ScopedDiagnosticSettingId +func ParseScopedDiagnosticSettingID(input string) (*ScopedDiagnosticSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(ScopedDiagnosticSettingId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ScopedDiagnosticSettingId{} + + if id.ResourceUri, ok = parsed.Parsed["resourceUri"]; !ok { + return nil, fmt.Errorf("the segment 'resourceUri' was not found in the resource id %q", input) + } + + if id.Name, ok = parsed.Parsed["name"]; !ok { + return nil, fmt.Errorf("the segment 'name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseScopedDiagnosticSettingIDInsensitively parses 'input' case-insensitively into a ScopedDiagnosticSettingId +// note: this method should only be used for API response data and not user input +func ParseScopedDiagnosticSettingIDInsensitively(input string) (*ScopedDiagnosticSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(ScopedDiagnosticSettingId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ScopedDiagnosticSettingId{} + + if id.ResourceUri, ok = parsed.Parsed["resourceUri"]; !ok { + return nil, fmt.Errorf("the segment 'resourceUri' was not found in the resource id %q", input) + } + + if id.Name, ok = parsed.Parsed["name"]; !ok { + return nil, fmt.Errorf("the segment 'name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateScopedDiagnosticSettingID checks that 'input' can be parsed as a Scoped Diagnostic Setting ID +func ValidateScopedDiagnosticSettingID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedDiagnosticSettingID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Diagnostic Setting ID +func (id ScopedDiagnosticSettingId) ID() string { + fmtString := "/%s/providers/Microsoft.Insights/diagnosticSettings/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.ResourceUri, "/"), id.Name) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Diagnostic Setting ID +func (id ScopedDiagnosticSettingId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("resourceUri", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftInsights", "Microsoft.Insights", "Microsoft.Insights"), + resourceids.StaticSegment("staticDiagnosticSettings", "diagnosticSettings", "diagnosticSettings"), + resourceids.UserSpecifiedSegment("name", "nameValue"), + } +} + +// String returns a human-readable description of this Scoped Diagnostic Setting ID +func (id ScopedDiagnosticSettingId) String() string { + components := []string{ + fmt.Sprintf("Resource Uri: %q", id.ResourceUri), + fmt.Sprintf("Name: %q", id.Name), + } + return fmt.Sprintf("Scoped Diagnostic Setting (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/method_createorupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/method_createorupdate_autorest.go new file mode 100644 index 000000000000..033d1e65c27b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/method_createorupdate_autorest.go @@ -0,0 +1,69 @@ +package diagnosticsettings + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *DiagnosticSettingsResource +} + +// CreateOrUpdate ... +func (c DiagnosticSettingsClient) CreateOrUpdate(ctx context.Context, id ScopedDiagnosticSettingId, input DiagnosticSettingsResource) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettings.DiagnosticSettingsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettings.DiagnosticSettingsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettings.DiagnosticSettingsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c DiagnosticSettingsClient) preparerForCreateOrUpdate(ctx context.Context, id ScopedDiagnosticSettingId, input DiagnosticSettingsResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c DiagnosticSettingsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/method_delete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/method_delete_autorest.go new file mode 100644 index 000000000000..b3511e09a4d3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/method_delete_autorest.go @@ -0,0 +1,66 @@ +package diagnosticsettings + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c DiagnosticSettingsClient) Delete(ctx context.Context, id ScopedDiagnosticSettingId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettings.DiagnosticSettingsClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettings.DiagnosticSettingsClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettings.DiagnosticSettingsClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c DiagnosticSettingsClient) preparerForDelete(ctx context.Context, id ScopedDiagnosticSettingId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDelete handles the response to the Delete request. The method always +// closes the http.Response Body. +func (c DiagnosticSettingsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/method_get_autorest.go new file mode 100644 index 000000000000..b5e0680ebd64 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/method_get_autorest.go @@ -0,0 +1,68 @@ +package diagnosticsettings + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *DiagnosticSettingsResource +} + +// Get ... +func (c DiagnosticSettingsClient) Get(ctx context.Context, id ScopedDiagnosticSettingId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettings.DiagnosticSettingsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettings.DiagnosticSettingsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettings.DiagnosticSettingsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c DiagnosticSettingsClient) preparerForGet(ctx context.Context, id ScopedDiagnosticSettingId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c DiagnosticSettingsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/method_list_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/method_list_autorest.go new file mode 100644 index 000000000000..86adaa8b5f7c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/method_list_autorest.go @@ -0,0 +1,70 @@ +package diagnosticsettings + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *DiagnosticSettingsResourceCollection +} + +// List ... +func (c DiagnosticSettingsClient) List(ctx context.Context, id commonids.ScopeId) (result ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettings.DiagnosticSettingsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettings.DiagnosticSettingsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettings.DiagnosticSettingsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForList prepares the List request. +func (c DiagnosticSettingsClient) preparerForList(ctx context.Context, id commonids.ScopeId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Insights/diagnosticSettings", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c DiagnosticSettingsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_diagnosticsettings.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_diagnosticsettings.go new file mode 100644 index 000000000000..00b60e83648d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_diagnosticsettings.go @@ -0,0 +1,16 @@ +package diagnosticsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticSettings struct { + EventHubAuthorizationRuleId *string `json:"eventHubAuthorizationRuleId,omitempty"` + EventHubName *string `json:"eventHubName,omitempty"` + LogAnalyticsDestinationType *string `json:"logAnalyticsDestinationType,omitempty"` + Logs *[]LogSettings `json:"logs,omitempty"` + MarketplacePartnerId *string `json:"marketplacePartnerId,omitempty"` + Metrics *[]MetricSettings `json:"metrics,omitempty"` + ServiceBusRuleId *string `json:"serviceBusRuleId,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + WorkspaceId *string `json:"workspaceId,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_diagnosticsettingsresource.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_diagnosticsettingsresource.go new file mode 100644 index 000000000000..9643b6d4d5c0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_diagnosticsettingsresource.go @@ -0,0 +1,16 @@ +package diagnosticsettings + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticSettingsResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DiagnosticSettings `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_diagnosticsettingsresourcecollection.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_diagnosticsettingsresourcecollection.go new file mode 100644 index 000000000000..ffca8773f191 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_diagnosticsettingsresourcecollection.go @@ -0,0 +1,8 @@ +package diagnosticsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticSettingsResourceCollection struct { + Value *[]DiagnosticSettingsResource `json:"value,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_logsettings.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_logsettings.go new file mode 100644 index 000000000000..4c0db6afeda0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_logsettings.go @@ -0,0 +1,11 @@ +package diagnosticsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogSettings struct { + Category *string `json:"category,omitempty"` + CategoryGroup *string `json:"categoryGroup,omitempty"` + Enabled bool `json:"enabled"` + RetentionPolicy *RetentionPolicy `json:"retentionPolicy,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_metricsettings.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_metricsettings.go new file mode 100644 index 000000000000..03e317b38eb9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_metricsettings.go @@ -0,0 +1,11 @@ +package diagnosticsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetricSettings struct { + Category *string `json:"category,omitempty"` + Enabled bool `json:"enabled"` + RetentionPolicy *RetentionPolicy `json:"retentionPolicy,omitempty"` + TimeGrain *string `json:"timeGrain,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_retentionpolicy.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_retentionpolicy.go new file mode 100644 index 000000000000..62218806a946 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/model_retentionpolicy.go @@ -0,0 +1,9 @@ +package diagnosticsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RetentionPolicy struct { + Days int64 `json:"days"` + Enabled bool `json:"enabled"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/version.go new file mode 100644 index 000000000000..ac3ed61868de --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings/version.go @@ -0,0 +1,12 @@ +package diagnosticsettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/diagnosticsettings/%s", defaultApiVersion) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/README.md new file mode 100644 index 000000000000..8f4adb8680f4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/README.md @@ -0,0 +1,52 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories` Documentation + +The `diagnosticsettingscategories` SDK allows for interaction with the Azure Resource Manager Service `insights` (API Version `2021-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories" +``` + + +### Client Initialization + +```go +client := diagnosticsettingscategories.NewDiagnosticSettingsCategoriesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DiagnosticSettingsCategoriesClient.DiagnosticSettingsCategoryGet` + +```go +ctx := context.TODO() +id := diagnosticsettingscategories.NewScopedDiagnosticSettingsCategoriesID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "nameValue") + +read, err := client.DiagnosticSettingsCategoryGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticSettingsCategoriesClient.DiagnosticSettingsCategoryList` + +```go +ctx := context.TODO() +id := diagnosticsettingscategories.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.DiagnosticSettingsCategoryList(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/client.go new file mode 100644 index 000000000000..cf4ebb0e9cb8 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/client.go @@ -0,0 +1,18 @@ +package diagnosticsettingscategories + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticSettingsCategoriesClient struct { + Client autorest.Client + baseUri string +} + +func NewDiagnosticSettingsCategoriesClientWithBaseURI(endpoint string) DiagnosticSettingsCategoriesClient { + return DiagnosticSettingsCategoriesClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/constants.go new file mode 100644 index 000000000000..ffee76501f4c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/constants.go @@ -0,0 +1,34 @@ +package diagnosticsettingscategories + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CategoryType string + +const ( + CategoryTypeLogs CategoryType = "Logs" + CategoryTypeMetrics CategoryType = "Metrics" +) + +func PossibleValuesForCategoryType() []string { + return []string{ + string(CategoryTypeLogs), + string(CategoryTypeMetrics), + } +} + +func parseCategoryType(input string) (*CategoryType, error) { + vals := map[string]CategoryType{ + "logs": CategoryTypeLogs, + "metrics": CategoryTypeMetrics, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CategoryType(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/id_scopeddiagnosticsettingscategories.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/id_scopeddiagnosticsettingscategories.go new file mode 100644 index 000000000000..897654b6713a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/id_scopeddiagnosticsettingscategories.go @@ -0,0 +1,110 @@ +package diagnosticsettingscategories + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ScopedDiagnosticSettingsCategoriesId{} + +// ScopedDiagnosticSettingsCategoriesId is a struct representing the Resource ID for a Scoped Diagnostic Settings Categories +type ScopedDiagnosticSettingsCategoriesId struct { + ResourceUri string + Name string +} + +// NewScopedDiagnosticSettingsCategoriesID returns a new ScopedDiagnosticSettingsCategoriesId struct +func NewScopedDiagnosticSettingsCategoriesID(resourceUri string, name string) ScopedDiagnosticSettingsCategoriesId { + return ScopedDiagnosticSettingsCategoriesId{ + ResourceUri: resourceUri, + Name: name, + } +} + +// ParseScopedDiagnosticSettingsCategoriesID parses 'input' into a ScopedDiagnosticSettingsCategoriesId +func ParseScopedDiagnosticSettingsCategoriesID(input string) (*ScopedDiagnosticSettingsCategoriesId, error) { + parser := resourceids.NewParserFromResourceIdType(ScopedDiagnosticSettingsCategoriesId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ScopedDiagnosticSettingsCategoriesId{} + + if id.ResourceUri, ok = parsed.Parsed["resourceUri"]; !ok { + return nil, fmt.Errorf("the segment 'resourceUri' was not found in the resource id %q", input) + } + + if id.Name, ok = parsed.Parsed["name"]; !ok { + return nil, fmt.Errorf("the segment 'name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseScopedDiagnosticSettingsCategoriesIDInsensitively parses 'input' case-insensitively into a ScopedDiagnosticSettingsCategoriesId +// note: this method should only be used for API response data and not user input +func ParseScopedDiagnosticSettingsCategoriesIDInsensitively(input string) (*ScopedDiagnosticSettingsCategoriesId, error) { + parser := resourceids.NewParserFromResourceIdType(ScopedDiagnosticSettingsCategoriesId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ScopedDiagnosticSettingsCategoriesId{} + + if id.ResourceUri, ok = parsed.Parsed["resourceUri"]; !ok { + return nil, fmt.Errorf("the segment 'resourceUri' was not found in the resource id %q", input) + } + + if id.Name, ok = parsed.Parsed["name"]; !ok { + return nil, fmt.Errorf("the segment 'name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateScopedDiagnosticSettingsCategoriesID checks that 'input' can be parsed as a Scoped Diagnostic Settings Categories ID +func ValidateScopedDiagnosticSettingsCategoriesID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedDiagnosticSettingsCategoriesID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Diagnostic Settings Categories ID +func (id ScopedDiagnosticSettingsCategoriesId) ID() string { + fmtString := "/%s/providers/Microsoft.Insights/diagnosticSettingsCategories/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.ResourceUri, "/"), id.Name) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Diagnostic Settings Categories ID +func (id ScopedDiagnosticSettingsCategoriesId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("resourceUri", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftInsights", "Microsoft.Insights", "Microsoft.Insights"), + resourceids.StaticSegment("staticDiagnosticSettingsCategories", "diagnosticSettingsCategories", "diagnosticSettingsCategories"), + resourceids.UserSpecifiedSegment("name", "nameValue"), + } +} + +// String returns a human-readable description of this Scoped Diagnostic Settings Categories ID +func (id ScopedDiagnosticSettingsCategoriesId) String() string { + components := []string{ + fmt.Sprintf("Resource Uri: %q", id.ResourceUri), + fmt.Sprintf("Name: %q", id.Name), + } + return fmt.Sprintf("Scoped Diagnostic Settings Categories (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/method_diagnosticsettingscategoryget_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/method_diagnosticsettingscategoryget_autorest.go new file mode 100644 index 000000000000..a19e35dffbfc --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/method_diagnosticsettingscategoryget_autorest.go @@ -0,0 +1,68 @@ +package diagnosticsettingscategories + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticSettingsCategoryGetOperationResponse struct { + HttpResponse *http.Response + Model *DiagnosticSettingsCategoryResource +} + +// DiagnosticSettingsCategoryGet ... +func (c DiagnosticSettingsCategoriesClient) DiagnosticSettingsCategoryGet(ctx context.Context, id ScopedDiagnosticSettingsCategoriesId) (result DiagnosticSettingsCategoryGetOperationResponse, err error) { + req, err := c.preparerForDiagnosticSettingsCategoryGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettingscategories.DiagnosticSettingsCategoriesClient", "DiagnosticSettingsCategoryGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettingscategories.DiagnosticSettingsCategoriesClient", "DiagnosticSettingsCategoryGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDiagnosticSettingsCategoryGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettingscategories.DiagnosticSettingsCategoriesClient", "DiagnosticSettingsCategoryGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDiagnosticSettingsCategoryGet prepares the DiagnosticSettingsCategoryGet request. +func (c DiagnosticSettingsCategoriesClient) preparerForDiagnosticSettingsCategoryGet(ctx context.Context, id ScopedDiagnosticSettingsCategoriesId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDiagnosticSettingsCategoryGet handles the response to the DiagnosticSettingsCategoryGet request. The method always +// closes the http.Response Body. +func (c DiagnosticSettingsCategoriesClient) responderForDiagnosticSettingsCategoryGet(resp *http.Response) (result DiagnosticSettingsCategoryGetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/method_diagnosticsettingscategorylist_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/method_diagnosticsettingscategorylist_autorest.go new file mode 100644 index 000000000000..8aa7c3bb43e5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/method_diagnosticsettingscategorylist_autorest.go @@ -0,0 +1,70 @@ +package diagnosticsettingscategories + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticSettingsCategoryListOperationResponse struct { + HttpResponse *http.Response + Model *DiagnosticSettingsCategoryResourceCollection +} + +// DiagnosticSettingsCategoryList ... +func (c DiagnosticSettingsCategoriesClient) DiagnosticSettingsCategoryList(ctx context.Context, id commonids.ScopeId) (result DiagnosticSettingsCategoryListOperationResponse, err error) { + req, err := c.preparerForDiagnosticSettingsCategoryList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettingscategories.DiagnosticSettingsCategoriesClient", "DiagnosticSettingsCategoryList", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettingscategories.DiagnosticSettingsCategoriesClient", "DiagnosticSettingsCategoryList", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDiagnosticSettingsCategoryList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "diagnosticsettingscategories.DiagnosticSettingsCategoriesClient", "DiagnosticSettingsCategoryList", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDiagnosticSettingsCategoryList prepares the DiagnosticSettingsCategoryList request. +func (c DiagnosticSettingsCategoriesClient) preparerForDiagnosticSettingsCategoryList(ctx context.Context, id commonids.ScopeId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Insights/diagnosticSettingsCategories", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDiagnosticSettingsCategoryList handles the response to the DiagnosticSettingsCategoryList request. The method always +// closes the http.Response Body. +func (c DiagnosticSettingsCategoriesClient) responderForDiagnosticSettingsCategoryList(resp *http.Response) (result DiagnosticSettingsCategoryListOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/model_diagnosticsettingscategory.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/model_diagnosticsettingscategory.go new file mode 100644 index 000000000000..f26e5e3f4f9f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/model_diagnosticsettingscategory.go @@ -0,0 +1,9 @@ +package diagnosticsettingscategories + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticSettingsCategory struct { + CategoryGroups *[]string `json:"categoryGroups,omitempty"` + CategoryType *CategoryType `json:"categoryType,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/model_diagnosticsettingscategoryresource.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/model_diagnosticsettingscategoryresource.go new file mode 100644 index 000000000000..9f7da59e4114 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/model_diagnosticsettingscategoryresource.go @@ -0,0 +1,16 @@ +package diagnosticsettingscategories + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticSettingsCategoryResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DiagnosticSettingsCategory `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/model_diagnosticsettingscategoryresourcecollection.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/model_diagnosticsettingscategoryresourcecollection.go new file mode 100644 index 000000000000..2a8a974ad2ad --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/model_diagnosticsettingscategoryresourcecollection.go @@ -0,0 +1,8 @@ +package diagnosticsettingscategories + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticSettingsCategoryResourceCollection struct { + Value *[]DiagnosticSettingsCategoryResource `json:"value,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/version.go new file mode 100644 index 000000000000..c18b19577e81 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories/version.go @@ -0,0 +1,12 @@ +package diagnosticsettingscategories + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/diagnosticsettingscategories/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index dfa2425c625a..5d350b6f2d44 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -242,6 +242,8 @@ github.com/hashicorp/go-azure-sdk/resource-manager/fluidrelay/2022-05-26/fluidre github.com/hashicorp/go-azure-sdk/resource-manager/hardwaresecuritymodules/2021-11-30/dedicatedhsms github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-04-01/datacollectionendpoints github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-04-01/datacollectionrules +github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings +github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-08-01/scheduledqueryrules github.com/hashicorp/go-azure-sdk/resource-manager/iotcentral/2021-11-01-preview/apps github.com/hashicorp/go-azure-sdk/resource-manager/loadtestservice/2021-12-01-preview/loadtests diff --git a/website/docs/d/monitor_diagnostic_categories.html.markdown b/website/docs/d/monitor_diagnostic_categories.html.markdown index 036316d86290..d951551bbf6d 100644 --- a/website/docs/d/monitor_diagnostic_categories.html.markdown +++ b/website/docs/d/monitor_diagnostic_categories.html.markdown @@ -34,6 +34,12 @@ data "azurerm_monitor_diagnostic_categories" "example" { * `logs` - A list of the Log Categories supported for this Resource. +* ~> **NOTE:** `logs` is deprecated and will be removed in favour of the property `log_category_types` and `log_category_groups` in version 4.0 of the AzureRM Provider. + +* `log_category_types` - A list of the supported log category types of this resource to send to the destination. + +* `log_category_groups` - A list of the supported log category groups of this resource to send to the destination. + * `metrics` - A list of the Metric Categories supported for this Resource. ## Timeouts diff --git a/website/docs/r/monitor_diagnostic_setting.html.markdown b/website/docs/r/monitor_diagnostic_setting.html.markdown index 1a11287a3555..b08037c71d22 100644 --- a/website/docs/r/monitor_diagnostic_setting.html.markdown +++ b/website/docs/r/monitor_diagnostic_setting.html.markdown @@ -95,10 +95,14 @@ The following arguments are supported: A `log` block supports the following: -* `category` - (Required) The name of a Diagnostic Log Category for this Resource. +* `category` - (Optional) The name of a Diagnostic Log Category for this Resource. -> **NOTE:** The Log Categories available vary depending on the Resource being used. You may wish to use [the `azurerm_monitor_diagnostic_categories` Data Source](../d/monitor_diagnostic_categories.html) or [list of service specific schemas](https://docs.microsoft.com/azure/azure-monitor/platform/resource-logs-schema#service-specific-schemas) to identify which categories are available for a given Resource. +* `category_group` - (Optional) The name of a Diagnostic Log Category Group for this Resource. + +-> **NOTE:** Not all resources have category groups available.**** + * `retention_policy` - (Optional) A `retention_policy` block as defined below. * `enabled` - (Optional) Is this Diagnostic Log enabled? Defaults to `true`.