From f22641f1b0dea85c903ea81b043dfba42ef08b8d Mon Sep 17 00:00:00 2001 From: Catriona Date: Wed, 12 Jan 2022 19:59:34 +0000 Subject: [PATCH 1/4] export iothub build-in eventhub namespace --- internal/services/iothub/iothub_resource.go | 25 ++++++++++++++++----- website/docs/r/iothub.html.markdown | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/internal/services/iothub/iothub_resource.go b/internal/services/iothub/iothub_resource.go index 0f43be171322..c0d7a630e05b 100644 --- a/internal/services/iothub/iothub_resource.go +++ b/internal/services/iothub/iothub_resource.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "net/url" "regexp" "sort" "strconv" @@ -390,12 +391,12 @@ func resourceIotHub() *pluginsdk.Resource { Optional: true, Default: "DeviceMessages", 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": { @@ -527,6 +528,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, @@ -726,6 +731,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) diff --git a/website/docs/r/iothub.html.markdown b/website/docs/r/iothub.html.markdown index d9b9089e71de..5f032472205c 100644 --- a/website/docs/r/iothub.html.markdown +++ b/website/docs/r/iothub.html.markdown @@ -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 From a3801cb90432c953fb3e7edc56e88bff2f6cbc94 Mon Sep 17 00:00:00 2001 From: Catriona Date: Wed, 12 Jan 2022 23:05:04 +0000 Subject: [PATCH 2/4] replace DeviceMessages with const --- internal/services/iothub/iothub_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/iothub/iothub_resource.go b/internal/services/iothub/iothub_resource.go index c0d7a630e05b..da19e8308d91 100644 --- a/internal/services/iothub/iothub_resource.go +++ b/internal/services/iothub/iothub_resource.go @@ -389,7 +389,7 @@ func resourceIotHub() *pluginsdk.Resource { "source": { Type: pluginsdk.TypeString, Optional: true, - Default: "DeviceMessages", + Default: string(devices.RoutingSourceDeviceMessages), ValidateFunc: validation.StringInSlice([]string{ string(devices.RoutingSourceDeviceConnectionStateEvents), string(devices.RoutingSourceDeviceJobLifecycleEvents), From 2d0bdf81a1e724f4dcd958acb2cf2cbd88d07cdd Mon Sep 17 00:00:00 2001 From: Catriona Date: Thu, 13 Jan 2022 10:59:17 +0000 Subject: [PATCH 3/4] set the default fallback route to enabled for 3.0 --- internal/services/iothub/iothub_resource.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/services/iothub/iothub_resource.go b/internal/services/iothub/iothub_resource.go index da19e8308d91..5ddf9608fd80 100644 --- a/internal/services/iothub/iothub_resource.go +++ b/internal/services/iothub/iothub_resource.go @@ -18,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" @@ -602,6 +603,13 @@ func resourceIotHubCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) err if _, ok := d.GetOk("fallback_route"); ok { routingProperties.FallbackRoute = expandIoTHubFallbackRoute(d) + } else if features.ThreePointOh() { + 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 { From 876448f486447633af18ec25f6a53318023b0744 Mon Sep 17 00:00:00 2001 From: Catriona Date: Thu, 13 Jan 2022 12:21:34 +0000 Subject: [PATCH 4/4] add 3.0 docs todo comment --- internal/services/iothub/iothub_resource.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/services/iothub/iothub_resource.go b/internal/services/iothub/iothub_resource.go index 5ddf9608fd80..9204edcaedbc 100644 --- a/internal/services/iothub/iothub_resource.go +++ b/internal/services/iothub/iothub_resource.go @@ -604,6 +604,7 @@ 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"),