Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_monitor_data_collection_rule - correctly support streams #18966

Merged
merged 7 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
},
},
},
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -290,6 +287,17 @@ func (r DataCollectionRuleResource) Arguments() map[string]*pluginsdk.Schema {
datacollectionrules.PossibleValuesForKnownSyslogDataSourceLogLevels(), false),
},
},
"streams": {
Type: pluginsdk.TypeList,
Optional: !features.FourPointOhBeta(),
Computed: !features.FourPointOhBeta(),
Required: features.FourPointOhBeta(),
MinItems: 1,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},
},
Expand All @@ -308,10 +316,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": {
Expand Down Expand Up @@ -692,12 +698,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
Expand Down Expand Up @@ -922,6 +943,7 @@ func flattenDataCollectionRuleDataSourceSyslog(input *[]datacollectionrules.Sysl
Name: flattenStringPtr(v.Name),
FacilityNames: flattenDataCollectionRuleDataSourceSyslogFacilityNames(v.FacilityNames),
LogLevels: flattenDataCollectionRuleDataSourceSyslogLogLevels(v.LogLevels),
Streams: flattenDataCollectionRuleSyslogStreams(v.Streams),
})
}
return result
Expand Down Expand Up @@ -951,6 +973,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -282,7 +283,8 @@ resource "azurerm_monitor_data_collection_rule" "test" {
"Info",
"Notice",
]
name = "test-datasource-syslog"
name = "test-datasource-syslog"
streams = ["Microsoft-Syslog", "Microsoft-CiscoAsa"]
}

performance_counter {
Expand Down Expand Up @@ -324,7 +326,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({
Expand All @@ -348,6 +350,8 @@ resource "azurerm_monitor_data_collection_rule" "test" {
}




`, r.template(data), data.RandomInteger)
}

Expand Down
12 changes: 7 additions & 5 deletions website/docs/r/monitor_data_collection_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

---

Expand Down Expand Up @@ -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.

Expand All @@ -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`.

---

Expand All @@ -208,15 +208,17 @@ 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 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.

---

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.

Expand Down