Skip to content

Commit

Permalink
Dependency New Resource/Data Source azurerm_healthcare_dicom_service (
Browse files Browse the repository at this point in the history
#15887)

Co-authored-by: kt <[email protected]>adding new resource: healthcare dicom service. Dependency of #15759

DICOM (Digital Imaging and Communications in Medicine) is the international standard to transmit, store, retrieve, print, process, and display medical imaging information, and is the primary medical imaging standard accepted across healthcare.

The DICOM service is a managed service within Azure Health Data Services that ingests and persists DICOM objects at multiple thousands of images per second.
  • Loading branch information
xiaxyi authored May 2, 2022
1 parent 076b945 commit 440c014
Show file tree
Hide file tree
Showing 14 changed files with 1,312 additions and 8 deletions.
13 changes: 9 additions & 4 deletions internal/services/healthcare/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
)

type Client struct {
HealthcareServiceClient *healthcareapis.ServicesClient
HealthcareWorkspaceClient *healthcareapis.WorkspacesClient
HealthcareServiceClient *healthcareapis.ServicesClient
HealthcareWorkspaceClient *healthcareapis.WorkspacesClient
HealthcareWorkspaceDicomServiceClient *healthcareapis.DicomServicesClient
}

func NewClient(o *common.ClientOptions) *Client {
Expand All @@ -17,8 +18,12 @@ func NewClient(o *common.ClientOptions) *Client {
HealthcareWorkspaceClient := healthcareapis.NewWorkspacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&HealthcareWorkspaceClient.Client, o.ResourceManagerAuthorizer)

HealthcareWorkspaceDicomServiceClient := healthcareapis.NewDicomServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&HealthcareWorkspaceDicomServiceClient.Client, o.ResourceManagerAuthorizer)

return &Client{
HealthcareServiceClient: &HealthcareServiceClient,
HealthcareWorkspaceClient: &HealthcareWorkspaceClient,
HealthcareServiceClient: &HealthcareServiceClient,
HealthcareWorkspaceClient: &HealthcareWorkspaceClient,
HealthcareWorkspaceDicomServiceClient: &HealthcareWorkspaceDicomServiceClient,
}
}
135 changes: 135 additions & 0 deletions internal/services/healthcare/healthcare_dicom_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package healthcare

import (
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

func dataSourceHealthcareDicomService() *pluginsdk.Resource {
return &pluginsdk.Resource{
Read: dataSourceHealthcareApisDicomServiceRead,

Timeouts: &pluginsdk.ResourceTimeout{
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validate.DicomServiceName(),
},

"workspace_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validate.WorkspaceID,
},

"location": commonschema.LocationComputed(),

"identity": commonschema.SystemAssignedUserAssignedIdentityComputed(),

"authentication": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"authority": {
Type: pluginsdk.TypeString,
Computed: true,
},
"audience": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{Type: pluginsdk.TypeString},
},
},
},
},

"private_endpoint": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Computed: true,
},

"id": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},

"service_url": {
Type: pluginsdk.TypeString,
Computed: true,
},

"tags": tags.SchemaDataSource(),
},
}
}

func dataSourceHealthcareApisDicomServiceRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).HealthCare.HealthcareWorkspaceDicomServiceClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

workspaceId, err := parse.WorkspaceID(d.Get("workspace_id").(string))
if err != nil {
return fmt.Errorf("parsing workspace id error: %+v", err)
}

id := parse.NewDicomServiceID(subscriptionId, workspaceId.ResourceGroup, workspaceId.Name, d.Get("name").(string))
resp, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.Name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
return nil
}
return fmt.Errorf("retrieving %s: %+v", id, err)
}

d.SetId(id.ID())

d.Set("name", id.Name)
d.Set("workspace_id", workspaceId.ID())

if resp.Location != nil {
d.Set("location", location.Normalize(*resp.Location))
}

if props := resp.DicomServiceProperties; props != nil {
d.Set("authentication", flattenDicomAuthentication(props.AuthenticationConfiguration))
d.Set("private_endpoint", flattenDicomServicePrivateEndpoint(props.PrivateEndpointConnections))
d.Set("service_url", props.ServiceURL)
}

identity, _ := flattenDicomManagedIdentity(resp.Identity)
if err := d.Set("identity", identity); err != nil {
return fmt.Errorf("setting `identity`: %+v", err)
}

if err := tags.FlattenAndSet(d, resp.Tags); err != nil {
return err
}

return nil
}
35 changes: 35 additions & 0 deletions internal/services/healthcare/healthcare_dicom_data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package healthcare_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
)

type HealthCareDicomServiceDataSource struct{}

func TestAccHealthCareDicomDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_healthcare_dicom_service", "test")
r := HealthCareDicomServiceDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("name").Exists()),
},
})
}

func (r HealthCareDicomServiceDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
data "azurerm_healthcare_dicom_service" "test" {
name = azurerm_healthcare_dicom_service.test.name
workspace_id = azurerm_healthcare_dicom_service.test.workspace_id
}
`, HealthCareDicomResource{}.basic(data))
}
Loading

0 comments on commit 440c014

Please sign in to comment.