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_iothub - event_hub_[retention_in_days|partition_count] #5505

Merged
merged 2 commits into from
Jan 24, 2020
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
99 changes: 63 additions & 36 deletions azurerm/internal/services/iothub/resource_arm_iothub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
},
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
11 changes: 8 additions & 3 deletions website/docs/r/iothub.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---
Expand Down