Skip to content

Commit

Permalink
r/healthcare_medtech_service: fixing a hard-coding to Azure Public
Browse files Browse the repository at this point in the history
This should dynamically source the DomainSuffix for ServiceBus from the Azure Environment
so that this works in Environments other than Azure Public.
  • Loading branch information
tombuildsstuff committed Mar 22, 2023
1 parent f9ce92c commit 6176043
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func dataSourceHealthcareIotConnector() *pluginsdk.Resource {
func dataSourceHealthcareIotConnectorRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).HealthCare.HealthcareWorkspaceMedTechServiceClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
domainSuffix, ok := meta.(*clients.Client).Account.Environment.ServiceBus.DomainSuffix()
if !ok {
return fmt.Errorf("unable to retrieve the Domain Suffix for ServiceBus, this is not configured for this Cloud Environment")
}

ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -92,14 +97,27 @@ func dataSourceHealthcareIotConnectorRead(d *pluginsdk.ResourceData, meta interf
return fmt.Errorf("setting `identity`: %+v", err)
}
if props := resp.IotConnectorProperties; props != nil {
if props.IngestionEndpointConfiguration.EventHubName != nil {
d.Set("eventhub_name", props.IngestionEndpointConfiguration.EventHubName)
}
eventHubConsumerGroupName := ""
eventHubName := ""
eventHubNamespaceName := ""
if config := props.IngestionEndpointConfiguration; config != nil {
if config.ConsumerGroup != nil {
eventHubConsumerGroupName = *config.ConsumerGroup
}

if props.IngestionEndpointConfiguration.ConsumerGroup != nil {
d.Set("eventhub_consumer_group_name", props.IngestionEndpointConfiguration.ConsumerGroup)
if config.EventHubName != nil {
eventHubName = *config.EventHubName
}

if props.IngestionEndpointConfiguration.FullyQualifiedEventHubNamespace != nil {
eventHubNamespaceName = strings.TrimSuffix(*props.IngestionEndpointConfiguration.FullyQualifiedEventHubNamespace, *domainSuffix)
}
}
d.Set("eventhub_consumer_group_name", eventHubConsumerGroupName)
d.Set("eventhub_name", eventHubName)
d.Set("eventhub_namespace_name", eventHubNamespaceName)

mapContent := ""
if props.DeviceMapping != nil {
deviceMapData, err := json.Marshal(props.DeviceMapping)
if err != nil {
Expand All @@ -110,20 +128,15 @@ func dataSourceHealthcareIotConnectorRead(d *pluginsdk.ResourceData, meta interf
if err = json.Unmarshal(deviceMapData, &m); err != nil {
return err
}
mapContent := ""
if v, ok := m["content"]; ok {
contents, err := json.Marshal(v)
if err != nil {
return err
}
mapContent = string(contents)
}
d.Set("device_mapping_json", mapContent)
}

if props.IngestionEndpointConfiguration.FullyQualifiedEventHubNamespace != nil {
d.Set("eventhub_namespace_name", strings.TrimSuffix(*props.IngestionEndpointConfiguration.FullyQualifiedEventHubNamespace, ".servicebus.windows.net"))
}
d.Set("device_mapping_json", mapContent)
}
return nil
}
35 changes: 24 additions & 11 deletions internal/services/healthcare/healthcare_medtech_service_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ func resourceHealthcareApisMedTechServiceCreate(d *pluginsdk.ResourceData, meta

func resourceHealthcareApisMedTechServiceRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).HealthCare.HealthcareWorkspaceMedTechServiceClient
domainSuffix, ok := meta.(*clients.Client).Account.Environment.ServiceBus.DomainSuffix()
if !ok {
return fmt.Errorf("unable to retrieve the Domain Suffix for ServiceBus, this is not configured for this Cloud Environment")
}
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -209,14 +213,27 @@ func resourceHealthcareApisMedTechServiceRead(d *pluginsdk.ResourceData, meta in
}

if props := resp.IotConnectorProperties; props != nil {
if props.IngestionEndpointConfiguration.EventHubName != nil {
d.Set("eventhub_name", props.IngestionEndpointConfiguration.EventHubName)
}
eventHubConsumerGroupName := ""
eventHubName := ""
eventHubNamespaceName := ""
if config := props.IngestionEndpointConfiguration; config != nil {
if config.ConsumerGroup != nil {
eventHubConsumerGroupName = *config.ConsumerGroup
}

if config.EventHubName != nil {
eventHubName = *config.EventHubName
}

if props.IngestionEndpointConfiguration.ConsumerGroup != nil {
d.Set("eventhub_consumer_group_name", props.IngestionEndpointConfiguration.ConsumerGroup)
if props.IngestionEndpointConfiguration.FullyQualifiedEventHubNamespace != nil {
eventHubNamespaceName = strings.TrimSuffix(*props.IngestionEndpointConfiguration.FullyQualifiedEventHubNamespace, *domainSuffix)
}
}
d.Set("eventhub_consumer_group_name", eventHubConsumerGroupName)
d.Set("eventhub_name", eventHubName)
d.Set("eventhub_namespace_name", eventHubNamespaceName)

mapContent := ""
if props.DeviceMapping != nil {
deviceMapData, err := json.Marshal(props.DeviceMapping)
if err != nil {
Expand All @@ -227,20 +244,15 @@ func resourceHealthcareApisMedTechServiceRead(d *pluginsdk.ResourceData, meta in
if err = json.Unmarshal(deviceMapData, &m); err != nil {
return err
}
mapContent := ""
if v, ok := m["content"]; ok {
contents, err := json.Marshal(v)
if err != nil {
return err
}
mapContent = string(contents)
}
d.Set("device_mapping_json", mapContent)
}

if props.IngestionEndpointConfiguration.FullyQualifiedEventHubNamespace != nil {
d.Set("eventhub_namespace_name", strings.TrimSuffix(*props.IngestionEndpointConfiguration.FullyQualifiedEventHubNamespace, ".servicebus.windows.net"))
}
d.Set("device_mapping_json", mapContent)
}

if err := tags.FlattenAndSet(d, resp.Tags); err != nil {
Expand Down Expand Up @@ -331,6 +343,7 @@ func resourceHealthcareApisMedTechServiceDelete(d *pluginsdk.ResourceData, meta
return fmt.Errorf("deleting %s: %+v", *id, err)
}

// NOTE: this can be removed when using `hashicorp/go-azure-sdk`'s base layer
stateConf := &pluginsdk.StateChangeConf{
Pending: []string{"Pending"},
Target: []string{"Deleted"},
Expand Down

0 comments on commit 6176043

Please sign in to comment.