From fd6dcdef4704bdf29509177022769612160d16d1 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Tue, 30 Mar 2021 16:21:24 +0200 Subject: [PATCH] `azurerm_eventgrid_data_connection`: add support for `table_name`, `mapping_rule_name` and `data_format` --- ...usto_eventgrid_data_connection_resource.go | 45 +++++++++++++++++++ ...eventgrid_data_connection_resource_test.go | 42 ++++++++++++++++- ...to_eventgrid_data_connection.html.markdown | 8 ++++ 3 files changed, 94 insertions(+), 1 deletion(-) diff --git a/azurerm/internal/services/kusto/kusto_eventgrid_data_connection_resource.go b/azurerm/internal/services/kusto/kusto_eventgrid_data_connection_resource.go index 9588f79de433..b0a52ea78f74 100644 --- a/azurerm/internal/services/kusto/kusto_eventgrid_data_connection_resource.go +++ b/azurerm/internal/services/kusto/kusto_eventgrid_data_connection_resource.go @@ -102,6 +102,36 @@ func resourceKustoEventGridDataConnection() *schema.Resource { Optional: true, Default: false, }, + + "table_name": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.EntityName, + }, + + "mapping_rule_name": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.EntityName, + }, + + "data_format": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + string(kusto.AVRO), + string(kusto.CSV), + string(kusto.JSON), + string(kusto.MULTIJSON), + string(kusto.PSV), + string(kusto.RAW), + string(kusto.SCSV), + string(kusto.SINGLEJSON), + string(kusto.SOHSV), + string(kusto.TSV), + string(kusto.TXT), + }, false), + }, }, } } @@ -139,6 +169,18 @@ func resourceKustoEventGridDataConnectionCreateUpdate(d *schema.ResourceData, me }, } + if tableName, ok := d.GetOk("table_name"); ok { + dataConnection.EventGridConnectionProperties.TableName = utils.String(tableName.(string)) + } + + if mappingRuleName, ok := d.GetOk("mapping_rule_name"); ok { + dataConnection.EventGridConnectionProperties.MappingRuleName = utils.String(mappingRuleName.(string)) + } + + if df, ok := d.GetOk("data_format"); ok { + dataConnection.EventGridConnectionProperties.DataFormat = kusto.EventGridDataFormat(df.(string)) + } + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.ClusterName, id.DatabaseName, id.Name, dataConnection) if err != nil { return fmt.Errorf("creating %s: %+v", id, err) @@ -185,6 +227,9 @@ func resourceKustoEventGridDataConnectionRead(d *schema.ResourceData, meta inter d.Set("eventhub_consumer_group_name", props.ConsumerGroup) d.Set("skip_first_record", props.IgnoreFirstRecord) d.Set("blob_storage_event_type", props.BlobStorageEventType) + d.Set("table_name", props.TableName) + d.Set("mapping_rule_name", props.MappingRuleName) + d.Set("data_format", props.DataFormat) } } diff --git a/azurerm/internal/services/kusto/kusto_eventgrid_data_connection_resource_test.go b/azurerm/internal/services/kusto/kusto_eventgrid_data_connection_resource_test.go index 153eccfe7449..fef0870802d5 100644 --- a/azurerm/internal/services/kusto/kusto_eventgrid_data_connection_resource_test.go +++ b/azurerm/internal/services/kusto/kusto_eventgrid_data_connection_resource_test.go @@ -62,6 +62,21 @@ func TestAccKustoEventGridDataConnection_complete(t *testing.T) { }) } +func TestAccKustoEventGridDataConnection_mappingRule(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kusto_eventgrid_data_connection", "test") + r := KustoEventGridDataConnectionResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.mappingRule(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccKustoEventGridDataConnection_update(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_kusto_eventgrid_data_connection", "test") r := KustoEventGridDataConnectionResource{} @@ -168,6 +183,31 @@ resource "azurerm_kusto_eventgrid_data_connection" "test" { `, r.template(data), data.RandomInteger) } +func (r KustoEventGridDataConnectionResource) mappingRule(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_kusto_eventgrid_data_connection" "test" { + name = "acctestkrgdc-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + cluster_name = azurerm_kusto_cluster.test.name + database_name = azurerm_kusto_database.test.name + storage_account_id = azurerm_storage_account.test.id + eventhub_id = azurerm_eventhub.test.id + eventhub_consumer_group_name = azurerm_eventhub_consumer_group.test.name + + blob_storage_event_type = "Microsoft.Storage.BlobRenamed" + skip_first_record = true + + mapping_rule_name = "Json_Mapping" + data_format = "MULTIJSON" + + depends_on = [azurerm_eventgrid_event_subscription.test] +} +`, r.template(data), data.RandomInteger) +} + func (KustoEventGridDataConnectionResource) template(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { @@ -175,7 +215,7 @@ provider "azurerm" { } resource "azurerm_resource_group" "test" { - name = "acctestRG-SecurityCenter-%d" + name = "acctestRG-%d" location = "%s" } diff --git a/website/docs/r/kusto_eventgrid_data_connection.html.markdown b/website/docs/r/kusto_eventgrid_data_connection.html.markdown index 6ab2222bbc4b..25a39149293e 100644 --- a/website/docs/r/kusto_eventgrid_data_connection.html.markdown +++ b/website/docs/r/kusto_eventgrid_data_connection.html.markdown @@ -120,8 +120,16 @@ The following arguments are supported: Values are `Microsoft.Storage.BlobCreated` and `Microsoft.Storage.BlobRenamed`. Defaults to `Microsoft.Storage.BlobCreated`. +* `data_format` - (Optional) Specifies the data format of the EventHub messages. Allowed values: `AVRO`, `CSV`, `JSON`, `MULTIJSON`, `PSV`, `RAW`, `SCSV`, `SINGLEJSON`, `SOHSV`, `TSV` and `TXT` + +* `mapping_rule_name` - (Optional) Specifies the mapping rule used for the message ingestion. Mapping rule must exist before resource is created. + +* `table_name` - (Optional) Specifies the target table name used for the message ingestion. Table must exist before resource is created. + * `skip_first_record` - (Optional) is the first record of every file ignored? Defaults to `false`. + + ## Attributes Reference The following attributes are exported: