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_kusto_eventgrid_data_connection - support database_routing, eventgrid_resource_id, managed_identity_resource_id #17524

Merged
merged 4 commits into from
Jul 14, 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 @@ -6,6 +6,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/services/kusto/mgmt/2022-02-01/kusto"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2017-04-01/eventhubs"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
Expand Down Expand Up @@ -137,6 +138,33 @@ func resourceKustoEventGridDataConnection() *pluginsdk.Resource {
string(kusto.EventGridDataFormatW3CLOGFILE),
}, false),
},

"database_routing_type": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
Default: string(kusto.DatabaseRoutingSingle),
ValidateFunc: validation.StringInSlice([]string{
string(kusto.DatabaseRoutingSingle),
string(kusto.DatabaseRoutingMulti),
}, false),
},

"eventgrid_resource_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: azure.ValidateResourceID,
},

"managed_identity_resource_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.Any(
validation.StringIsEmpty,
validate.ClusterID,
commonids.ValidateUserAssignedIdentityID,
),
},
},
}
}
Expand Down Expand Up @@ -186,6 +214,18 @@ func resourceKustoEventGridDataConnectionCreateUpdate(d *pluginsdk.ResourceData,
dataConnection.EventGridConnectionProperties.DataFormat = kusto.EventGridDataFormat(df.(string))
}

if databaseRouting, ok := d.GetOk("database_routing_type"); ok {
dataConnection.DatabaseRouting = kusto.DatabaseRouting(databaseRouting.(string))
}

if eventGridRID, ok := d.GetOk("eventgrid_resource_id"); ok {
dataConnection.EventGridConnectionProperties.EventGridResourceID = utils.String(eventGridRID.(string))
}

if managedIdentityRID, ok := d.GetOk("managed_identity_resource_id"); ok {
dataConnection.EventGridConnectionProperties.ManagedIdentityResourceID = utils.String(managedIdentityRID.(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)
Expand Down Expand Up @@ -235,6 +275,9 @@ func resourceKustoEventGridDataConnectionRead(d *pluginsdk.ResourceData, meta in
d.Set("table_name", props.TableName)
d.Set("mapping_rule_name", props.MappingRuleName)
d.Set("data_format", props.DataFormat)
d.Set("database_routing_type", props.DatabaseRouting)
d.Set("eventgrid_resource_id", props.EventGridResourceID)
d.Set("managed_identity_resource_id", props.ManagedIdentityResourceID)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestAccKustoEventGridDataConnection_complete(t *testing.T) {
Config: r.complete(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("database_routing_type").HasValue("Multi"),
),
},
data.ImportStep(),
Expand All @@ -75,6 +76,36 @@ func TestAccKustoEventGridDataConnection_mappingRule(t *testing.T) {
})
}

func TestAccKustoEventGridDataConnection_userAssignedIdentity(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kusto_eventgrid_data_connection", "test")
r := KustoEventGridDataConnectionResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.userAssignedIdentity(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccKustoEventGridDataConnection_systemAssignedIdentity(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kusto_eventgrid_data_connection", "test")
r := KustoEventGridDataConnectionResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.systemAssignedIdentity(data),
Check: acceptance.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{}
Expand Down Expand Up @@ -176,6 +207,9 @@ resource "azurerm_kusto_eventgrid_data_connection" "test" {
blob_storage_event_type = "Microsoft.Storage.BlobRenamed"
skip_first_record = true

database_routing_type = "Multi"
eventgrid_resource_id = azurerm_eventgrid_event_subscription.test.id

depends_on = [azurerm_eventgrid_event_subscription.test]
}
`, r.template(data), data.RandomInteger)
Expand Down Expand Up @@ -206,6 +240,42 @@ resource "azurerm_kusto_eventgrid_data_connection" "test" {
`, r.template(data), data.RandomInteger)
}

func (r KustoEventGridDataConnectionResource) userAssignedIdentity(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
managed_identity_resource_id = azurerm_user_assigned_identity.test.id
depends_on = [azurerm_eventgrid_event_subscription.test]
}
`, r.template(data), data.RandomInteger)
}

func (r KustoEventGridDataConnectionResource) systemAssignedIdentity(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
managed_identity_resource_id = azurerm_kusto_cluster.test.id
depends_on = [azurerm_eventgrid_event_subscription.test]
}
`, r.template(data), data.RandomInteger)
}

func (KustoEventGridDataConnectionResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand All @@ -217,6 +287,12 @@ resource "azurerm_resource_group" "test" {
location = "%s"
}

resource "azurerm_user_assigned_identity" "test" {
name = "acctest%s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
}

resource "azurerm_kusto_cluster" "test" {
name = "acctestkc%s"
location = azurerm_resource_group.test.location
Expand All @@ -225,6 +301,11 @@ resource "azurerm_kusto_cluster" "test" {
name = "Dev(No SLA)_Standard_D11_v2"
capacity = 1
}

identity {
type = "SystemAssigned, UserAssigned"
identity_ids = [azurerm_user_assigned_identity.test.id]
}
}

resource "azurerm_kusto_database" "test" {
Expand Down Expand Up @@ -276,5 +357,5 @@ resource "azurerm_eventgrid_event_subscription" "test" {
max_delivery_attempts = 10
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ 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`
* `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`.

* `database_routing_type` - (Optional) Indication for database routing information from the data connection, by default only database routing information is allowed. Allowed values: `Single`, `Multi`.

* `eventgrid_resource_id` - (Optional) The resource ID of the event grid that is subscribed to the storage account events.

* `managed_identity_resource_id` - (Optional) Empty for non-managed identity based data connection. For system assigned identity, provide cluster resource Id. For user assigned identity (UAI) provide the UAI resource Id.

* `mapping_rule_name` - (Optional) Specifies the mapping rule used for the message ingestion. Mapping rule must exist before resource is created.

Expand Down