From 36cee726058bd3f9a535e8398aaa95512361a412 Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Thu, 20 Oct 2022 17:13:54 +0800 Subject: [PATCH 1/7] fix streams --- .../monitor_data_collection_rule_resource.go | 65 ++++++++++++++----- ...itor_data_collection_rule_resource_test.go | 2 +- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/internal/services/monitor/monitor_data_collection_rule_resource.go b/internal/services/monitor/monitor_data_collection_rule_resource.go index 270b72a5af27..396d98a38096 100644 --- a/internal/services/monitor/monitor_data_collection_rule_resource.go +++ b/internal/services/monitor/monitor_data_collection_rule_resource.go @@ -3,6 +3,7 @@ package monitor import ( "context" "fmt" + "github.com/hashicorp/terraform-provider-azurerm/internal/features" "time" "github.com/hashicorp/go-azure-helpers/lang/response" @@ -66,6 +67,7 @@ type Syslog struct { FacilityNames []string `tfschema:"facility_names"` LogLevels []string `tfschema:"log_levels"` Name string `tfschema:"name"` + Streams []string `tfschema:"streams"` } type WindowsEventLog struct { @@ -118,9 +120,8 @@ func (r DataCollectionRuleResource) Arguments() map[string]*pluginsdk.Schema { Required: true, MinItems: 1, Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.StringInSlice( - datacollectionrules.PossibleValuesForKnownDataFlowStreams(), false), + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, }, }, }, @@ -198,10 +199,8 @@ func (r DataCollectionRuleResource) Arguments() map[string]*pluginsdk.Schema { Required: true, MinItems: 1, Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.StringInSlice( - datacollectionrules.PossibleValuesForKnownExtensionDataSourceStreams(), - false), + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, }, }, "extension_json": { @@ -241,10 +240,8 @@ func (r DataCollectionRuleResource) Arguments() map[string]*pluginsdk.Schema { Required: true, MinItems: 1, Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.StringInSlice( - datacollectionrules.PossibleValuesForKnownPerfCounterDataSourceStreams(), - false), + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, }, }, "counter_specifiers": { @@ -290,6 +287,16 @@ func (r DataCollectionRuleResource) Arguments() map[string]*pluginsdk.Schema { datacollectionrules.PossibleValuesForKnownSyslogDataSourceLogLevels(), false), }, }, + "streams": { + Type: pluginsdk.TypeList, + Optional: !features.FourPointOhBeta(), + Required: features.FourPointOhBeta(), + MinItems: 1, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, }, }, }, @@ -308,10 +315,8 @@ func (r DataCollectionRuleResource) Arguments() map[string]*pluginsdk.Schema { Required: true, MinItems: 1, Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.StringInSlice( - datacollectionrules.PossibleValuesForKnownWindowsEventLogDataSourceStreams(), - false), + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, }, }, "x_path_queries": { @@ -692,12 +697,27 @@ func expandDataCollectionRuleDataSourceSyslog(input []Syslog) *[]datacollectionr FacilityNames: expandDataCollectionRuleDataSourceSyslogFacilityNames(v.FacilityNames), LogLevels: expandDataCollectionRuleDataSourceSyslogLogLevels(v.LogLevels), Name: utils.String(v.Name), - Streams: &[]datacollectionrules.KnownSyslogDataSourceStreams{datacollectionrules.KnownSyslogDataSourceStreamsMicrosoftNegativeSyslog}, + Streams: expandDataCollectionRuleDataSourceSyslogStreams(v.Streams), }) } return &result } +func expandDataCollectionRuleDataSourceSyslogStreams(input []string) *[]datacollectionrules.KnownSyslogDataSourceStreams { + if len(input) == 0 { + if !features.FourPointOhBeta() { + return &[]datacollectionrules.KnownSyslogDataSourceStreams{datacollectionrules.KnownSyslogDataSourceStreamsMicrosoftNegativeSyslog} + } + return nil + } + + result := make([]datacollectionrules.KnownSyslogDataSourceStreams, 0) + for _, v := range input { + result = append(result, datacollectionrules.KnownSyslogDataSourceStreams(v)) + } + return &result +} + func expandDataCollectionRuleDataSourceSyslogFacilityNames(input []string) *[]datacollectionrules.KnownSyslogDataSourceFacilityNames { if len(input) == 0 { return nil @@ -922,6 +942,7 @@ func flattenDataCollectionRuleDataSourceSyslog(input *[]datacollectionrules.Sysl Name: flattenStringPtr(v.Name), FacilityNames: flattenDataCollectionRuleDataSourceSyslogFacilityNames(v.FacilityNames), LogLevels: flattenDataCollectionRuleDataSourceSyslogLogLevels(v.LogLevels), + Streams: flattenDataCollectionRuleSyslogStreams(v.Streams), }) } return result @@ -951,6 +972,18 @@ func flattenDataCollectionRuleDataSourceSyslogLogLevels(input *[]datacollectionr return result } +func flattenDataCollectionRuleSyslogStreams(input *[]datacollectionrules.KnownSyslogDataSourceStreams) []string { + if input == nil { + return make([]string, 0) + } + + result := make([]string, 0) + for _, v := range *input { + result = append(result, string(v)) + } + return result +} + func flattenDataCollectionRuleWindowsEventLogs(input *[]datacollectionrules.WindowsEventLogDataSource) []WindowsEventLog { if input == nil { return make([]WindowsEventLog, 0) diff --git a/internal/services/monitor/monitor_data_collection_rule_resource_test.go b/internal/services/monitor/monitor_data_collection_rule_resource_test.go index 1ea51da7d069..d1a8d01c2d18 100644 --- a/internal/services/monitor/monitor_data_collection_rule_resource_test.go +++ b/internal/services/monitor/monitor_data_collection_rule_resource_test.go @@ -324,7 +324,7 @@ resource "azurerm_monitor_data_collection_rule" "test" { } extension { - streams = ["Microsoft-WindowsEvent"] + streams = ["Microsoft-WindowsEvent", "Microsoft-ServiceMap"] input_data_sources = ["test-datasource-wineventlog"] extension_name = "test-extension-name" extension_json = jsonencode({ From 8585b3873e5481ac8537e897dd66ee7140af0ed7 Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Mon, 24 Oct 2022 16:43:14 +0800 Subject: [PATCH 2/7] add computed --- .../services/monitor/monitor_data_collection_rule_resource.go | 1 + .../monitor/monitor_data_collection_rule_resource_test.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/internal/services/monitor/monitor_data_collection_rule_resource.go b/internal/services/monitor/monitor_data_collection_rule_resource.go index 396d98a38096..fe779905473c 100644 --- a/internal/services/monitor/monitor_data_collection_rule_resource.go +++ b/internal/services/monitor/monitor_data_collection_rule_resource.go @@ -290,6 +290,7 @@ func (r DataCollectionRuleResource) Arguments() map[string]*pluginsdk.Schema { "streams": { Type: pluginsdk.TypeList, Optional: !features.FourPointOhBeta(), + Computed: !features.FourPointOhBeta(), Required: features.FourPointOhBeta(), MinItems: 1, Elem: &pluginsdk.Schema{ diff --git a/internal/services/monitor/monitor_data_collection_rule_resource_test.go b/internal/services/monitor/monitor_data_collection_rule_resource_test.go index d1a8d01c2d18..bf5d9480b377 100644 --- a/internal/services/monitor/monitor_data_collection_rule_resource_test.go +++ b/internal/services/monitor/monitor_data_collection_rule_resource_test.go @@ -174,6 +174,7 @@ resource "azurerm_monitor_data_collection_rule" "test" { facility_names = ["*"] log_levels = ["*"] name = "test-datasource-syslog" + streams = ["Microsoft-CiscoAsa"] } performance_counter { streams = ["Microsoft-Perf", "Microsoft-InsightsMetrics"] @@ -283,6 +284,7 @@ resource "azurerm_monitor_data_collection_rule" "test" { "Notice", ] name = "test-datasource-syslog" + streams = ["Microsoft-Syslog", "Microsoft-CiscoAsa"] } performance_counter { From 160b668a71eccc8324e6476f29a69fd0ac09b7f8 Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Tue, 25 Oct 2022 17:15:51 +0800 Subject: [PATCH 3/7] fix doc --- .../r/monitor_data_collection_rule.html.markdown | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/website/docs/r/monitor_data_collection_rule.html.markdown b/website/docs/r/monitor_data_collection_rule.html.markdown index ada0367accc7..ad275bd1e55e 100644 --- a/website/docs/r/monitor_data_collection_rule.html.markdown +++ b/website/docs/r/monitor_data_collection_rule.html.markdown @@ -140,7 +140,7 @@ A `data_flow` block supports the following: * `destinations` - (Required) Specifies a list of destination names. A `azure_monitor_metrics` data source only allows for stream of kind `Microsoft-InsightsMetrics`. -* `streams` - (Required) Specifies a list of streams. Possible values are `Microsoft-Event`, `Microsoft-InsightsMetrics`, `Microsoft-Perf`, `Microsoft-Syslog`,and `Microsoft-WindowsEvent`. +* `streams` - (Required) Specifies a list of streams. Possible values include but not limited to `Microsoft-Event`, `Microsoft-InsightsMetrics`, `Microsoft-Perf`, `Microsoft-Syslog`,and `Microsoft-WindowsEvent`. --- @@ -172,7 +172,7 @@ A `extension` block supports the following: * `name` - (Required) The name which should be used for this data source. This name should be unique across all data sources regardless of type within the Data Collection Rule. -* `streams` - (Required) Specifies a list of streams that this data source will be sent to. A stream indicates what schema will be used for this data and usually what table in Log Analytics the data will be sent to. Possible values are `Microsoft-Event`, `Microsoft-InsightsMetrics`, `Microsoft-Perf`, `Microsoft-Syslog`,and `Microsoft-WindowsEvent`. +* `streams` - (Required) Specifies a list of streams that this data source will be sent to. A stream indicates what schema will be used for this data and usually what table in Log Analytics the data will be sent to. Possible values include but not limited to `Microsoft-Event`, `Microsoft-InsightsMetrics`, `Microsoft-Perf`, `Microsoft-Syslog`, `Microsoft-WindowsEvent`. * `extension_json` - (Optional) A JSON String which specifies the extension setting. @@ -196,7 +196,7 @@ A `performance_counter` block supports the following: * `sampling_frequency_in_seconds` - (Required) The number of seconds between consecutive counter measurements (samples). The value should be integer between `1` and `300` inclusive. -* `streams` - (Required) Specifies a list of streams that this data source will be sent to. A stream indicates what schema will be used for this data and usually what table in Log Analytics the data will be sent to. Possible values are `Microsoft-InsightsMetrics`,and `Microsoft-Perf`. +* `streams` - (Required) Specifies a list of streams that this data source will be sent to. A stream indicates what schema will be used for this data and usually what table in Log Analytics the data will be sent to. Possible values include but not limited to `Microsoft-InsightsMetrics`,and `Microsoft-Perf`. --- @@ -208,7 +208,9 @@ A `syslog` block supports the following: * `name` - (Required) The name which should be used for this data source. This name should be unique across all data sources regardless of type within the Data Collection Rule. --> **Note:** Syslog data source has only one possible streams value which is `Microsoft-Syslog`. +* `streams` - (Optional) Specifies a list of streams that this data source will be sent to. A stream indicates what schema will be used for this data and usually what table in Log Analytics the data will be sent to. Possible values include but not limited to `Microsoft-Syslog`,and `Microsoft-CiscoAsa`, and `Microsoft-CommonSecurityLog`. + +-> **Note:** In 4.0 or later version of the provider, `streams` will be required. In 3.x version of provider, if `streams` is not specified, it is default to `["Microsoft-Syslog"]`. if `streams` need to be modified (include change other value to the default value), it must be explicitly specified. --- @@ -216,7 +218,7 @@ A `windows_event_log` block supports the following: * `name` - (Required) The name which should be used for this data source. This name should be unique across all data sources regardless of type within the Data Collection Rule. -* `streams` - (Required) Specifies a list of streams that this data source will be sent to. A stream indicates what schema will be used for this data and usually what table in Log Analytics the data will be sent to. Possible values are `Microsoft-Event`,and `Microsoft-WindowsEvent`. +* `streams` - (Required) Specifies a list of streams that this data source will be sent to. A stream indicates what schema will be used for this data and usually what table in Log Analytics the data will be sent to. Possible values include but not limited to `Microsoft-Event`,and `Microsoft-WindowsEvent`, `Microsoft-RomeDetectionEvent`, and `Microsoft-SecurityEvent`. * `x_path_queries` - (Required) Specifies a list of Windows Event Log queries in XPath expression. From e6e19891952c5061edef99cbb9d98473fb570631 Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Tue, 25 Oct 2022 17:20:30 +0800 Subject: [PATCH 4/7] fix import --- .../services/monitor/monitor_data_collection_rule_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/monitor/monitor_data_collection_rule_resource.go b/internal/services/monitor/monitor_data_collection_rule_resource.go index fe779905473c..d0fda2b62f38 100644 --- a/internal/services/monitor/monitor_data_collection_rule_resource.go +++ b/internal/services/monitor/monitor_data_collection_rule_resource.go @@ -3,7 +3,6 @@ package monitor import ( "context" "fmt" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "time" "github.com/hashicorp/go-azure-helpers/lang/response" @@ -13,6 +12,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2020-08-01/workspaces" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" From bb5368af4745048752631b2a24549c361afd46d6 Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Tue, 25 Oct 2022 17:45:33 +0800 Subject: [PATCH 5/7] fix terrafmt --- .../monitor/monitor_data_collection_rule_resource_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/services/monitor/monitor_data_collection_rule_resource_test.go b/internal/services/monitor/monitor_data_collection_rule_resource_test.go index bf5d9480b377..3a41750b2384 100644 --- a/internal/services/monitor/monitor_data_collection_rule_resource_test.go +++ b/internal/services/monitor/monitor_data_collection_rule_resource_test.go @@ -283,7 +283,7 @@ resource "azurerm_monitor_data_collection_rule" "test" { "Info", "Notice", ] - name = "test-datasource-syslog" + name = "test-datasource-syslog" streams = ["Microsoft-Syslog", "Microsoft-CiscoAsa"] } @@ -350,6 +350,8 @@ resource "azurerm_monitor_data_collection_rule" "test" { } + + `, r.template(data), data.RandomInteger) } From e94bf480671c36b705f67b9aa5bb0ab15aad3afd Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Tue, 25 Oct 2022 17:46:58 +0800 Subject: [PATCH 6/7] fix doc --- website/docs/r/monitor_data_collection_rule.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/monitor_data_collection_rule.html.markdown b/website/docs/r/monitor_data_collection_rule.html.markdown index ad275bd1e55e..ce2f0f8b3a98 100644 --- a/website/docs/r/monitor_data_collection_rule.html.markdown +++ b/website/docs/r/monitor_data_collection_rule.html.markdown @@ -210,7 +210,7 @@ A `syslog` block supports the following: * `streams` - (Optional) Specifies a list of streams that this data source will be sent to. A stream indicates what schema will be used for this data and usually what table in Log Analytics the data will be sent to. Possible values include but not limited to `Microsoft-Syslog`,and `Microsoft-CiscoAsa`, and `Microsoft-CommonSecurityLog`. --> **Note:** In 4.0 or later version of the provider, `streams` will be required. In 3.x version of provider, if `streams` is not specified, it is default to `["Microsoft-Syslog"]`. if `streams` need to be modified (include change other value to the default value), it must be explicitly specified. +-> **Note:** In 4.0 or later version of the provider, `streams` will be required. In 3.x version of provider, if `streams` is not specified in creation, it is default to `["Microsoft-Syslog"]`. if `streams` need to be modified (include change other value to the default value), it must be explicitly specified. --- From 5ef879cbf4fcea7efc86ee4e796bd6cc01e3faa2 Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Thu, 27 Oct 2022 11:17:39 +0800 Subject: [PATCH 7/7] fix datasource --- .../monitor/monitor_data_collection_rule_data_source.go | 7 +++++++ .../monitor_data_collection_rule_data_source_test.go | 1 + 2 files changed, 8 insertions(+) diff --git a/internal/services/monitor/monitor_data_collection_rule_data_source.go b/internal/services/monitor/monitor_data_collection_rule_data_source.go index 191ec9aa1799..9817692f563c 100644 --- a/internal/services/monitor/monitor_data_collection_rule_data_source.go +++ b/internal/services/monitor/monitor_data_collection_rule_data_source.go @@ -197,6 +197,13 @@ func (d DataCollectionRuleDataSource) Attributes() map[string]*pluginsdk.Schema Type: pluginsdk.TypeString, }, }, + "streams": { + Type: pluginsdk.TypeList, + Computed: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, }, }, }, diff --git a/internal/services/monitor/monitor_data_collection_rule_data_source_test.go b/internal/services/monitor/monitor_data_collection_rule_data_source_test.go index cc3599b1dd24..a444b863f136 100644 --- a/internal/services/monitor/monitor_data_collection_rule_data_source_test.go +++ b/internal/services/monitor/monitor_data_collection_rule_data_source_test.go @@ -28,6 +28,7 @@ func TestAccMonitorDataCollectionRuleDataSource_complete(t *testing.T) { check.That(data.ResourceName).Key("data_flow.2.streams.0").HasValue("Microsoft-Event"), check.That(data.ResourceName).Key("data_flow.2.destinations.0").HasValue("test-destination-log1"), check.That(data.ResourceName).Key("data_sources.0.syslog.0.facility_names.#").HasValue("5"), + check.That(data.ResourceName).Key("data_sources.0.syslog.0.streams.#").HasValue("2"), check.That(data.ResourceName).Key("data_sources.0.performance_counter.#").HasValue("2"), check.That(data.ResourceName).Key("data_sources.0.performance_counter.1.sampling_frequency_in_seconds").HasValue("20"), check.That(data.ResourceName).Key("data_sources.0.performance_counter.1.name").HasValue("test-datasource-perfcounter2"),