From 8e7cd7eb1131b79be83bc981598d61ee6dc54b55 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 23 Jan 2020 17:30:05 -0800 Subject: [PATCH 1/2] azurerm_iothub - support for the event_hub_retention_in_days and event_hub_partition_count properties --- .../services/iothub/resource_arm_iothub.go | 99 ++++++++++++------- .../iothub/tests/resource_arm_iothub_test.go | 3 + 2 files changed, 66 insertions(+), 36 deletions(-) diff --git a/azurerm/internal/services/iothub/resource_arm_iothub.go b/azurerm/internal/services/iothub/resource_arm_iothub.go index 0babfe7bdae4..9ec51042c281 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub.go @@ -119,34 +119,6 @@ func resourceArmIotHub() *schema.Resource { }, }, - "type": { - Type: schema.TypeString, - Computed: true, - }, - - "hostname": { - Type: schema.TypeString, - Computed: true, - }, - - "event_hub_events_endpoint": { - Type: schema.TypeString, - Computed: true, - }, - "event_hub_operations_endpoint": { - Type: schema.TypeString, - Computed: true, - }, - - "event_hub_events_path": { - Type: schema.TypeString, - Computed: true, - }, - "event_hub_operations_path": { - Type: schema.TypeString, - Computed: true, - }, - "shared_access_policy": { Type: schema.TypeList, Computed: true, @@ -174,6 +146,19 @@ func resourceArmIotHub() *schema.Resource { }, }, + "event_hub_partition_count": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + ValidateFunc: validation.IntBetween(2, 128), + }, + "event_hub_retention_in_days": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + ValidateFunc: validation.IntBetween(1, 7), + }, + "file_upload": { Type: schema.TypeList, MaxItems: 1, @@ -426,6 +411,34 @@ func resourceArmIotHub() *schema.Resource { }, }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + + "hostname": { + Type: schema.TypeString, + Computed: true, + }, + + "event_hub_events_endpoint": { + Type: schema.TypeString, + Computed: true, + }, + "event_hub_operations_endpoint": { + Type: schema.TypeString, + Computed: true, + }, + + "event_hub_events_path": { + Type: schema.TypeString, + Computed: true, + }, + "event_hub_operations_path": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tags.Schema(), }, } @@ -470,8 +483,6 @@ func resourceArmIotHubCreateUpdate(d *schema.ResourceData, meta interface{}) err } } - location := azure.NormalizeLocation(d.Get("location").(string)) - routingProperties := devices.RoutingProperties{} if _, ok := d.GetOk("route"); ok { @@ -495,14 +506,12 @@ func resourceArmIotHubCreateUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error expanding `file_upload`: %+v", err) } - ipFilterRules := expandIPFilterRules(d) - - properties := devices.IotHubDescription{ + props := devices.IotHubDescription{ Name: utils.String(name), - Location: utils.String(location), + Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))), Sku: expandIoTHubSku(d), Properties: &devices.IotHubProperties{ - IPFilterRules: ipFilterRules, + IPFilterRules: expandIPFilterRules(d), Routing: &routingProperties, StorageEndpoints: storageEndpoints, MessagingEndpoints: messagingEndpoints, @@ -511,7 +520,23 @@ func resourceArmIotHubCreateUpdate(d *schema.ResourceData, meta interface{}) err Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } - future, err := client.CreateOrUpdate(ctx, resourceGroup, name, properties, "") + retention, retentionOk := d.GetOk("event_hub_retention_in_days") + partition, partitionOk := d.GetOk("event_hub_partition_count") + if partitionOk || retentionOk { + eh := devices.EventHubProperties{} + if retentionOk { + eh.RetentionTimeInDays = utils.Int64(int64(retention.(int))) + } + if partitionOk { + eh.PartitionCount = utils.Int32(int32(partition.(int))) + } + + props.Properties.EventHubEndpoints = map[string]*devices.EventHubProperties{ + "events": &eh, + } + } + + future, err := client.CreateOrUpdate(ctx, resourceGroup, name, props, "") if err != nil { return fmt.Errorf("Error creating/updating IotHub %q (Resource Group %q): %+v", name, resourceGroup, err) } @@ -574,6 +599,8 @@ func resourceArmIotHubRead(d *schema.ResourceData, meta interface{}) error { if k == "events" { d.Set("event_hub_events_endpoint", v.Endpoint) d.Set("event_hub_events_path", v.Path) + d.Set("event_hub_partition_count", v.PartitionCount) + d.Set("event_hub_retention_in_days", v.RetentionTimeInDays) } else if k == "operationsMonitoringEvents" { d.Set("event_hub_operations_endpoint", v.Endpoint) d.Set("event_hub_operations_path", v.Path) diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iothub_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_test.go index ef10dd9bf47b..c6d8a858126b 100644 --- a/azurerm/internal/services/iothub/tests/resource_arm_iothub_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_test.go @@ -371,6 +371,9 @@ resource "azurerm_iothub" "test" { capacity = "1" } + event_hub_retention_in_days = 7 + event_hub_partition_count = 77 + endpoint { type = "AzureIotHub.StorageContainer" connection_string = "${azurerm_storage_account.test.primary_blob_connection_string}" From a595432d9ad84a1c6100ac4156b49214b5bf8f19 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 23 Jan 2020 17:33:03 -0800 Subject: [PATCH 2/2] add docs --- website/docs/r/iothub.html.markdown | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/website/docs/r/iothub.html.markdown b/website/docs/r/iothub.html.markdown index f4fff20c587b..6c5be3589ed8 100644 --- a/website/docs/r/iothub.html.markdown +++ b/website/docs/r/iothub.html.markdown @@ -100,16 +100,21 @@ The following arguments are supported: * `sku` - (Required) A `sku` block as defined below. -* `endpoint` - (Optional) An `endpoint` block as defined below. +* `event_hub_partition_count` - (Optional) The number of device-to-cloud partitions used by backing event hubs. Must be between `2` and `128`. -* `ip_filter_rule` - (Optional) One or more `ip_filter_rule` blocks as defined below. +* `event_hub_retention_in_days` - (Optional) The event hub retention to use in days. Must be between `1` and `7`. + +* `endpoint` - (Optional) An `endpoint` block as defined below. -* `route` - (Optional) A `route` block as defined below. * `fallback_route` - (Optional) A `fallback_route` block as defined below. If the fallback route is enabled, messages that don't match any of the supplied routes are automatically sent to this route. Defaults to messages/events. * `file_upload` - (Optional) A `file_upload` block as defined below. +* `ip_filter_rule` - (Optional) One or more `ip_filter_rule` blocks as defined below. + +* `route` - (Optional) A `route` block as defined below. + * `tags` - (Optional) A mapping of tags to assign to the resource. ---