Skip to content

Commit

Permalink
azurerm_iothub - export event_hub_events_namespace and add a fall…
Browse files Browse the repository at this point in the history
…back route by default (#14942)

* export iothub build-in eventhub namespace

* replace DeviceMessages with const

* set the default fallback route to enabled for 3.0

* add 3.0 docs todo comment
  • Loading branch information
catriona-m authored Jan 13, 2022
1 parent ba3c9fb commit 07d6256
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
36 changes: 29 additions & 7 deletions internal/services/iothub/iothub_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"net/url"
"regexp"
"sort"
"strconv"
Expand All @@ -17,6 +18,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/iothub/parse"
iothubValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/iothub/validate"
Expand Down Expand Up @@ -388,14 +390,14 @@ func resourceIotHub() *pluginsdk.Resource {
"source": {
Type: pluginsdk.TypeString,
Optional: true,
Default: "DeviceMessages",
Default: string(devices.RoutingSourceDeviceMessages),
ValidateFunc: validation.StringInSlice([]string{
"DeviceConnectionStateEvents",
"DeviceJobLifecycleEvents",
"DeviceLifecycleEvents",
"DeviceMessages",
"Invalid",
"TwinChangeEvents",
string(devices.RoutingSourceDeviceConnectionStateEvents),
string(devices.RoutingSourceDeviceJobLifecycleEvents),
string(devices.RoutingSourceDeviceLifecycleEvents),
string(devices.RoutingSourceDeviceMessages),
string(devices.RoutingSourceInvalid),
string(devices.RoutingSourceTwinChangeEvents),
}, false),
},
"condition": {
Expand Down Expand Up @@ -527,6 +529,10 @@ func resourceIotHub() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Computed: true,
},
"event_hub_events_namespace": {
Type: pluginsdk.TypeString,
Computed: true,
},
"event_hub_operations_endpoint": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -597,6 +603,14 @@ func resourceIotHubCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) err

if _, ok := d.GetOk("fallback_route"); ok {
routingProperties.FallbackRoute = expandIoTHubFallbackRoute(d)
} else if features.ThreePointOh() {
// TODO update docs for 3.0
routingProperties.FallbackRoute = &devices.FallbackRouteProperties{
Source: utils.String(string(devices.RoutingSourceDeviceMessages)),
Condition: utils.String("true"),
EndpointNames: &[]string{"events"},
IsEnabled: utils.Bool(true),
}
}

if _, ok := d.GetOk("endpoint"); ok {
Expand Down Expand Up @@ -726,6 +740,14 @@ func resourceIotHubRead(d *pluginsdk.ResourceData, meta interface{}) error {

if k == "events" {
d.Set("event_hub_events_endpoint", v.Endpoint)

if *v.Endpoint != "" {
uri, err := url.Parse(*v.Endpoint)
if err == nil {
d.Set("event_hub_events_namespace", strings.Split(uri.Hostname(), ".")[0])
}
}

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)
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/iothub.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ The following attributes are exported:
* `id` - The ID of the IoTHub.

* `event_hub_events_endpoint` - The EventHub compatible endpoint for events data
* `event_hub_events_namespace` - The EventHub namespace for events data
* `event_hub_events_path` - The EventHub compatible path for events data
* `event_hub_operations_endpoint` - The EventHub compatible endpoint for operational data
* `event_hub_operations_path` - The EventHub compatible path for operational data
Expand Down

0 comments on commit 07d6256

Please sign in to comment.