From f372e4d6e85540ab1999e37589c339240a35cde0 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 23 Jan 2020 19:50:59 -0800 Subject: [PATCH] azurerm_iothub - event_hub_[retention_in_days|partition_count] (#5505) fixes #2821 --- .../services/iothub/resource_arm_iothub.go | 99 ++++++++++++------- .../iothub/tests/resource_arm_iothub_test.go | 3 + website/docs/r/iothub.html.markdown | 11 ++- 3 files changed, 74 insertions(+), 39 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 8eca7ab5891d..e1fae76b447e 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}" diff --git a/website/docs/r/iothub.html.markdown b/website/docs/r/iothub.html.markdown index 56a3dca00340..bf964c6d5d33 100644 --- a/website/docs/r/iothub.html.markdown +++ b/website/docs/r/iothub.html.markdown @@ -123,16 +123,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. ---