Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
azurerm_eventgrid_data_connection: add support for table_name, `m…
Browse files Browse the repository at this point in the history
…apping_rule_name` and `data_format` (hashicorp#11157)

zurerm_eventgrid_data_connection: add support for table_name, mapping_rule_name and data_format

$ make acctests SERVICE='kusto' TESTARGS='-run=TestAccKustoEventGridDataConnection_mappingRule' TESTTIMEOUT='600m'
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...
==> Checking that acceptance test packages are used...
TF_ACC=1 go test -v ./azurerm/internal/services/kusto -run=TestAccKustoEventGridDataConnection_mappingRule -timeout 600m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
2021/03/30 16:20:12 [DEBUG] not using binary driver name, it's no longer needed
2021/03/30 16:20:12 [DEBUG] not using binary driver name, it's no longer needed
=== RUN   TestAccKustoEventGridDataConnection_mappingRule
=== PAUSE TestAccKustoEventGridDataConnection_mappingRule
=== CONT  TestAccKustoEventGridDataConnection_mappingRule
--- PASS: TestAccKustoEventGridDataConnection_mappingRule (1647.62s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/kusto	1648.919s
Fixes hashicorp#10977
favoretti authored and r0bnet committed Apr 8, 2021
1 parent 5d21851 commit c727172
Showing 3 changed files with 94 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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)
}
}

Original file line number Diff line number Diff line change
@@ -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,14 +183,39 @@ 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" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-SecurityCenter-%d"
name = "acctestRG-%d"
location = "%s"
}
8 changes: 8 additions & 0 deletions website/docs/r/kusto_eventgrid_data_connection.html.markdown
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit c727172

Please sign in to comment.