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

Dependency New Resource/Data Source azurerm_healthcare_dicom_service #15887

Merged
merged 29 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
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
}
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