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 - export event_hub_events_namespace and add a fallback route by default #14942

Merged
merged 4 commits into from
Jan 13, 2022
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
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