From 63103ed1cf999c036adb9f38364fa9f7ec541b2e Mon Sep 17 00:00:00 2001 From: Aris van Ommeren Date: Thu, 29 Sep 2022 12:23:42 +0200 Subject: [PATCH] `azurerm_healthcare_fhir_service` - `oci_artifact` support --- .../healthcare/healthcare_fhir_resource.go | 122 +++++++++++++++--- .../healthcare_fhir_resource_test.go | 4 + .../r/healthcare_fhir_service.html.markdown | 13 ++ 3 files changed, 123 insertions(+), 16 deletions(-) diff --git a/internal/services/healthcare/healthcare_fhir_resource.go b/internal/services/healthcare/healthcare_fhir_resource.go index dd0d6e96d3f0..2d570cc27a5e 100644 --- a/internal/services/healthcare/healthcare_fhir_resource.go +++ b/internal/services/healthcare/healthcare_fhir_resource.go @@ -118,6 +118,32 @@ func resourceHealthcareApisFhirService() *pluginsdk.Resource { }, }, + "oci_artifact": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "login_server": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "image_name": { + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + Optional: true, + }, + + "digest": { + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + Optional: true, + }, + }, + }, + }, + "cors": { Type: pluginsdk.TypeList, Optional: true, @@ -242,11 +268,18 @@ func resourceHealthcareApisFhirServiceCreate(d *pluginsdk.ResourceData, meta int } } - acrConfig, hasValues := d.GetOk("container_registry_login_server_url") + acrConfig := healthcareapis.FhirServiceAcrConfiguration{} + ociArtifactsRaw, hasValues := d.GetOk("oci_artifact") + if hasValues { + ociArtifacts := expandOciArtifacts(ociArtifactsRaw.([]interface{})) + acrConfig.OciArtifacts = ociArtifacts + } + loginServersRaw, hasValues := d.GetOk("container_registry_login_server_url") if hasValues { - result := expandFhirAcrLoginServer(acrConfig.(*pluginsdk.Set).List()) - parameters.FhirServiceProperties.AcrConfiguration = result + loginServers := expandFhirAcrLoginServer(loginServersRaw.(*pluginsdk.Set).List()) + acrConfig.LoginServers = loginServers } + parameters.FhirServiceProperties.AcrConfiguration = &acrConfig future, err := client.CreateOrUpdate(ctx, fhirServiceId.ResourceGroup, fhirServiceId.WorkspaceName, fhirServiceId.Name, parameters) if err != nil { @@ -311,6 +344,12 @@ func resourceHealthcareApisFhirServiceRead(d *pluginsdk.ResourceData, meta inter d.Set("authentication", flattenFhirAuthentication(props.AuthenticationConfiguration)) d.Set("cors", flattenFhirCorsConfiguration(props.CorsConfiguration)) d.Set("container_registry_login_server_url", flattenFhirAcrLoginServer(props.AcrConfiguration)) + if acrConfig := props.AcrConfiguration; acrConfig != nil { + if artifacts := acrConfig.OciArtifacts; artifacts != nil { + d.Set("oci_artifact", flattenOciArtifacts(artifacts)) + } + + } if props.ExportConfiguration != nil && props.ExportConfiguration.StorageAccountName != nil { d.Set("configuration_export_storage_account_name", props.ExportConfiguration.StorageAccountName) } @@ -323,6 +362,31 @@ func resourceHealthcareApisFhirServiceRead(d *pluginsdk.ResourceData, meta inter return nil } +func expandOciArtifacts(input []interface{}) *[]healthcareapis.ServiceOciArtifactEntry { + output := make([]healthcareapis.ServiceOciArtifactEntry, 0) + + for _, artifactSet := range input { + artifactRaw := artifactSet.(map[string]interface{}) + + loginServer := artifactRaw["login_server"].(string) + artifact := healthcareapis.ServiceOciArtifactEntry{ + LoginServer: &loginServer, + ImageName: nil, + Digest: nil, + } + if image := artifactRaw["image_name"].(string); image != "" { + artifact.ImageName = &image + } + if digest := artifactRaw["digest"].(string); digest != "" { + artifact.Digest = &digest + } + + output = append(output, artifact) + } + + return &output +} + func resourceHealthcareApisFhirServiceUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).HealthCare.HealthcareWorkspaceFhirServiceClient ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) @@ -358,11 +422,18 @@ func resourceHealthcareApisFhirServiceUpdate(d *pluginsdk.ResourceData, meta int } } - acrConfig, hasValues := d.GetOk("container_registry_login_server_url") + acrConfig := healthcareapis.FhirServiceAcrConfiguration{} + ociArtifactsRaw, hasValues := d.GetOk("oci_artifact") + if hasValues { + ociArtifacts := expandOciArtifacts(ociArtifactsRaw.([]interface{})) + acrConfig.OciArtifacts = ociArtifacts + } + loginServersRaw, hasValues := d.GetOk("container_registry_login_server_url") if hasValues { - result := expandFhirAcrLoginServer(acrConfig.(*pluginsdk.Set).List()) - parameters.FhirServiceProperties.AcrConfiguration = result + loginServers := expandFhirAcrLoginServer(loginServersRaw.(*pluginsdk.Set).List()) + acrConfig.LoginServers = loginServers } + parameters.FhirServiceProperties.AcrConfiguration = &acrConfig future, err := client.CreateOrUpdate(ctx, fhirServiceId.ResourceGroup, fhirServiceId.WorkspaceName, fhirServiceId.Name, parameters) if err != nil { @@ -520,30 +591,26 @@ func expandFhirCorsConfiguration(input []interface{}) *healthcareapis.FhirServic return cors } -func expandFhirAcrLoginServer(input []interface{}) *healthcareapis.FhirServiceAcrConfiguration { +func expandFhirAcrLoginServer(input []interface{}) *[]string { acrLoginServers := make([]string, 0) if len(input) == 0 { - return &healthcareapis.FhirServiceAcrConfiguration{ - LoginServers: &acrLoginServers, - } + return &acrLoginServers } for _, item := range input { acrLoginServers = append(acrLoginServers, item.(string)) } - return &healthcareapis.FhirServiceAcrConfiguration{ - LoginServers: &acrLoginServers, - } + return &acrLoginServers } -func flattenFhirAcrLoginServer(acrLoginServer *healthcareapis.FhirServiceAcrConfiguration) []string { +func flattenFhirAcrLoginServer(acrConfig *healthcareapis.FhirServiceAcrConfiguration) []string { result := make([]string, 0) - if acrLoginServer == nil { + if acrConfig == nil { return result } - if loginServer := acrLoginServer.LoginServers; loginServer != nil { + if loginServer := acrConfig.LoginServers; loginServer != nil { result = append(result, *loginServer...) } return result @@ -564,6 +631,29 @@ func flattenFhirAccessPolicy(policies *[]healthcareapis.FhirServiceAccessPolicyE return result } +func flattenOciArtifacts(artifacts *[]healthcareapis.ServiceOciArtifactEntry) []map[string]interface{} { + result := make([]map[string]interface{}, 0) + if artifacts == nil { + return result + } + for _, artifact := range *artifacts { + artifactRaw := make(map[string]interface{}) + + if loginServer := artifact.LoginServer; loginServer != nil { + artifactRaw["login_server"] = *loginServer + } + if imageName := artifact.ImageName; imageName != nil { + artifactRaw["image_name"] = *imageName + } + if digest := artifact.Digest; digest != nil { + artifactRaw["digest"] = *digest + } + result = append(result, artifactRaw) + } + + return result +} + func flattenFhirCorsConfiguration(corsConfig *healthcareapis.FhirServiceCorsConfiguration) []interface{} { if corsConfig == nil { return []interface{}{} diff --git a/internal/services/healthcare/healthcare_fhir_resource_test.go b/internal/services/healthcare/healthcare_fhir_resource_test.go index ec1ce504e99f..5dece4aa939f 100644 --- a/internal/services/healthcare/healthcare_fhir_resource_test.go +++ b/internal/services/healthcare/healthcare_fhir_resource_test.go @@ -265,6 +265,10 @@ resource "azurerm_healthcare_fhir_service" "test" { container_registry_login_server_url = [azurerm_container_registry.test.login_server] + oci_artifact { + login_server = azurerm_container_registry.test.login_server + } + cors { allowed_origins = ["https://acctest.com:123", "https://acctest1.com:3389"] allowed_headers = ["*"] diff --git a/website/docs/r/healthcare_fhir_service.html.markdown b/website/docs/r/healthcare_fhir_service.html.markdown index e60a41e5e1f2..9e860f483417 100644 --- a/website/docs/r/healthcare_fhir_service.html.markdown +++ b/website/docs/r/healthcare_fhir_service.html.markdown @@ -81,6 +81,8 @@ The following arguments are supported: * `container_registry_login_server_url` - (Optional) A list of azure container registry settings used for convert data operation of the service instance. +* `oci_artifact` - (Optional) [A list](/docs/configuration/attr-as-blocks.html) of objects describing [OCI artifacts for export](https://learn.microsoft.com/en-gb/azure/healthcare-apis/fhir/de-identified-export) as defined below. + * `authentication` - (Required) An `authentication` block as defined below. * `configuration_export_storage_account_name` - (Optional) Specifies the name of the storage account which the operation configuration information is exported to. @@ -108,6 +110,17 @@ An `authentication` supports the following: Authority must be registered to Azure AD and in the following format: https://{Azure-AD-endpoint}/{tenant-id}. * `audience` - (Optional) The intended audience to receive authentication tokens for the service. The default value is https://.fhir.azurehealthcareapis.com +--- + +A `oci_artifact` block supports the following: + +* `login_server` - (Required) An Azure container registry used for export operations of the service instance. + +* `image_name` - (Optional) An image within Azure container registry used for export operations of the service instance. + +* `digest` - (Optional) A digest of an image within Azure container registry used for export operations of the service instance to narrow the artifacts down. + + ## Attributes Reference The following attributes are exported: