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

Support for azurerm_kusto_iothub_data_connection missing table_name, mapping_rule_name, data_format #12293

Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -83,6 +83,44 @@ func resourceKustoIotHubDataConnection() *pluginsdk.Resource {
ValidateFunc: iothubValidate.IotHubSharedAccessPolicyName,
},

"table_name": {
EliiseS marked this conversation as resolved.
Show resolved Hide resolved
Type: pluginsdk.TypeString,
ForceNew: true,
Optional: true,
ValidateFunc: validate.EntityName,
},

"mapping_rule_name": {
Type: pluginsdk.TypeString,
ForceNew: true,
Optional: true,
ValidateFunc: validate.EntityName,
},

"data_format": {
Type: pluginsdk.TypeString,
ForceNew: true,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
string(kusto.IotHubDataFormatAPACHEAVRO),
string(kusto.IotHubDataFormatAVRO),
string(kusto.IotHubDataFormatCSV),
string(kusto.IotHubDataFormatJSON),
string(kusto.IotHubDataFormatMULTIJSON),
string(kusto.IotHubDataFormatORC),
string(kusto.IotHubDataFormatPARQUET),
string(kusto.IotHubDataFormatPSV),
string(kusto.IotHubDataFormatRAW),
string(kusto.IotHubDataFormatSCSV),
string(kusto.IotHubDataFormatSINGLEJSON),
string(kusto.IotHubDataFormatSOHSV),
string(kusto.IotHubDataFormatTSV),
string(kusto.IotHubDataFormatTSVE),
string(kusto.IotHubDataFormatTXT),
string(kusto.IotHubDataFormatW3CLOGFILE),
}, false),
},

"event_system_properties": {
Type: pluginsdk.TypeSet,
Optional: true,
Expand Down Expand Up @@ -128,17 +166,11 @@ func resourceKustoIotHubDataConnectionCreate(d *pluginsdk.ResourceData, meta int
return tf.ImportAsExistsError("azurerm_kusto_iothub_data_connection", id.ID())
}

dataConnection := kusto.IotHubDataConnection{
Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))),
IotHubConnectionProperties: &kusto.IotHubConnectionProperties{
IotHubResourceID: utils.String(d.Get("iothub_id").(string)),
ConsumerGroup: utils.String(d.Get("consumer_group").(string)),
SharedAccessPolicyName: utils.String(d.Get("shared_access_policy_name").(string)),
},
}
iotHubDataConnectionProperties := expandKustoIotHubDataConnectionProperties(d)

if eventSystemProperties, ok := d.GetOk("event_system_properties"); ok {
dataConnection.IotHubConnectionProperties.EventSystemProperties = utils.ExpandStringSlice(eventSystemProperties.(*pluginsdk.Set).List())
dataConnection := kusto.IotHubDataConnection{
Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))),
IotHubConnectionProperties: iotHubDataConnectionProperties,
}

future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.ClusterName, id.DatabaseName, id.Name, dataConnection)
Expand Down Expand Up @@ -183,6 +215,9 @@ func resourceKustoIotHubDataConnectionRead(d *pluginsdk.ResourceData, meta inter
if props := dataConnection.IotHubConnectionProperties; props != nil {
d.Set("iothub_id", props.IotHubResourceID)
d.Set("consumer_group", props.ConsumerGroup)
d.Set("table_name", props.TableName)
d.Set("mapping_rule_name", props.MappingRuleName)
d.Set("data_format", props.DataFormat)
d.Set("shared_access_policy_name", props.SharedAccessPolicyName)
d.Set("event_system_properties", utils.FlattenStringSlice(props.EventSystemProperties))
}
Expand Down Expand Up @@ -212,3 +247,29 @@ func resourceKustoIotHubDataConnectionDelete(d *pluginsdk.ResourceData, meta int

return nil
}

func expandKustoIotHubDataConnectionProperties(d *pluginsdk.ResourceData) *kusto.IotHubConnectionProperties {
iotHubDataConnectionProperties := &kusto.IotHubConnectionProperties{
IotHubResourceID: utils.String(d.Get("iothub_id").(string)),
ConsumerGroup: utils.String(d.Get("consumer_group").(string)),
SharedAccessPolicyName: utils.String(d.Get("shared_access_policy_name").(string)),
}

if tableName, ok := d.GetOk("table_name"); ok {
iotHubDataConnectionProperties.TableName = utils.String(tableName.(string))
}

if mappingRuleName, ok := d.GetOk("mapping_rule_name"); ok {
iotHubDataConnectionProperties.MappingRuleName = utils.String(mappingRuleName.(string))
}

if df, ok := d.GetOk("data_format"); ok {
iotHubDataConnectionProperties.DataFormat = kusto.IotHubDataFormat(df.(string))
}

if eventSystemProperties, ok := d.GetOk("event_system_properties"); ok {
iotHubDataConnectionProperties.EventSystemProperties = utils.ExpandStringSlice(eventSystemProperties.(*pluginsdk.Set).List())
}

return iotHubDataConnectionProperties
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,80 @@ func TestAccKustoIotHubDataConnection_basic(t *testing.T) {
})
}

func (KustoIotHubDataConnectionResource) basic(data acceptance.TestData) string {
func TestAccKustoIotHubDataConnection_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kusto_iothub_data_connection", "test")
r := KustoIotHubDataConnectionResource{}

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

func (KustoIotHubDataConnectionResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.DataConnectionID(state.ID)
if err != nil {
return nil, err
}

resp, err := clients.Kusto.DataConnectionsClient.Get(ctx, id.ResourceGroup, id.ClusterName, id.DatabaseName, id.Name)
if err != nil {
return nil, fmt.Errorf("retrieving %s: %v", id.String(), err)
}

value, ok := resp.Value.AsIotHubDataConnection()
if !ok {
return nil, fmt.Errorf("%s is not an IotHub Data Connection", id.String())
}

return utils.Bool(value.IotHubConnectionProperties != nil), nil
}

func (r KustoIotHubDataConnectionResource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_kusto_iothub_data_connection" "test" {
name = "acctestkedc-%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

iothub_id = azurerm_iothub.test.id
consumer_group = azurerm_iothub_consumer_group.test.name
shared_access_policy_name = azurerm_iothub_shared_access_policy.test.name
}
`, r.template(data), data.RandomInteger)
}

func (r KustoIotHubDataConnectionResource) complete(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_kusto_iothub_data_connection" "test" {
name = "acctestkedc-%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

iothub_id = azurerm_iothub.test.id
consumer_group = azurerm_iothub_consumer_group.test.name
shared_access_policy_name = azurerm_iothub_shared_access_policy.test.name
event_system_properties = ["message-id", "sequence-number", "to"]
mapping_rule_name = "Json_Mapping"
data_format = "MULTIJSON"
EliiseS marked this conversation as resolved.
Show resolved Hide resolved
}
`, r.template(data), data.RandomInteger)
}

func (KustoIotHubDataConnectionResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down Expand Up @@ -89,37 +162,5 @@ resource "azurerm_iothub_consumer_group" "test" {
eventhub_endpoint_name = "events"
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_kusto_iothub_data_connection" "test" {
name = "acctestkedc-%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

iothub_id = azurerm_iothub.test.id
consumer_group = azurerm_iothub_consumer_group.test.name
shared_access_policy_name = azurerm_iothub_shared_access_policy.test.name
event_system_properties = ["message-id", "sequence-number", "to"]
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (KustoIotHubDataConnectionResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.DataConnectionID(state.ID)
if err != nil {
return nil, err
}

resp, err := clients.Kusto.DataConnectionsClient.Get(ctx, id.ResourceGroup, id.ClusterName, id.DatabaseName, id.Name)
if err != nil {
return nil, fmt.Errorf("retrieving %s: %v", id.String(), err)
}

value, ok := resp.Value.AsIotHubDataConnection()
if !ok {
return nil, fmt.Errorf("%s is not an IotHub Data Connection", id.String())
}

return utils.Bool(value.IotHubConnectionProperties != nil), nil
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger)
}