From d7101a73c5bc064d1b5447191b492bcaee60ac8b Mon Sep 17 00:00:00 2001 From: Xiaxin <92154856+xiaxyi@users.noreply.github.com> Date: Tue, 2 May 2023 22:15:26 +0800 Subject: [PATCH] `azurerm_healthcare_dicom_service`, `azurerm_healthcare_fhir_service` - fix identity schema in in data source (#21594) * fix data source identity * add test cases to cover identity --- .../healthcare/healthcare_fhir_data_source.go | 2 +- .../healthcare_fhir_data_source_test.go | 24 ++++++++ .../healthcare_fhir_resource_test.go | 57 ++++++++++++++++++- .../healthcare_medtech_service_data_source.go | 2 +- .../r/healthcare_fhir_service.html.markdown | 4 +- 5 files changed, 84 insertions(+), 5 deletions(-) diff --git a/internal/services/healthcare/healthcare_fhir_data_source.go b/internal/services/healthcare/healthcare_fhir_data_source.go index 7d31345cf965..d2d31fba9305 100644 --- a/internal/services/healthcare/healthcare_fhir_data_source.go +++ b/internal/services/healthcare/healthcare_fhir_data_source.go @@ -77,7 +77,7 @@ func dataSourceHealthcareApisFhirService() *pluginsdk.Resource { }, }, - "identity": commonschema.SystemAssignedIdentityComputed(), + "identity": commonschema.SystemOrUserAssignedIdentityComputed(), "container_registry_login_server_url": { Type: pluginsdk.TypeList, diff --git a/internal/services/healthcare/healthcare_fhir_data_source_test.go b/internal/services/healthcare/healthcare_fhir_data_source_test.go index 9a84a1b82a34..cd5a1b404549 100644 --- a/internal/services/healthcare/healthcare_fhir_data_source_test.go +++ b/internal/services/healthcare/healthcare_fhir_data_source_test.go @@ -23,6 +23,19 @@ func TestAccHealthCareFhirServiceDataSource_basic(t *testing.T) { }) } +func TestAccHealthCareFhirServiceDataSource_identity(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_healthcare_fhir_service", "test") + r := HealthCareFhirServiceDataSource{} + + data.DataSourceTest(t, []acceptance.TestStep{ + { + Config: r.dataSourceUserAssignedIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("name").Exists()), + }, + }) +} + func (HealthCareFhirServiceDataSource) basic(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -33,3 +46,14 @@ data "azurerm_healthcare_fhir_service" "test" { } `, HealthcareApiFhirServiceResource{}.basic(data)) } + +func (HealthCareFhirServiceDataSource) dataSourceUserAssignedIdentity(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +data "azurerm_healthcare_fhir_service" "test" { + name = azurerm_healthcare_fhir_service.test.name + workspace_id = azurerm_healthcare_fhir_service.test.workspace_id +} +`, HealthcareApiFhirServiceResource{}.updateIdentityUserAssigned(data)) +} diff --git a/internal/services/healthcare/healthcare_fhir_resource_test.go b/internal/services/healthcare/healthcare_fhir_resource_test.go index b1b0facbd45c..c1181bb3cba0 100644 --- a/internal/services/healthcare/healthcare_fhir_resource_test.go +++ b/internal/services/healthcare/healthcare_fhir_resource_test.go @@ -58,7 +58,28 @@ func TestAccHealthcareApiFhirService_updateIdentity(t *testing.T) { }, data.ImportStep(), { - Config: r.updateIdentity(data), + Config: r.updateIdentitySystemAssigned(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.updateIdentityUserAssigned(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.updateIdentitySystemAssigned(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.basic(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -171,7 +192,7 @@ resource "azurerm_healthcare_fhir_service" "test" { `, r.template(data), data.RandomInteger) } -func (r HealthcareApiFhirServiceResource) updateIdentity(data acceptance.TestData) string { +func (r HealthcareApiFhirServiceResource) updateIdentitySystemAssigned(data acceptance.TestData) string { return fmt.Sprintf(` %s resource "azurerm_healthcare_fhir_service" "test" { @@ -193,6 +214,38 @@ resource "azurerm_healthcare_fhir_service" "test" { `, r.template(data), data.RandomInteger) } +func (r HealthcareApiFhirServiceResource) updateIdentityUserAssigned(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_user_assigned_identity" "test" { + name = "acctestUAI-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_healthcare_fhir_service" "test" { + name = "fhir%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + workspace_id = azurerm_healthcare_workspace.test.id + kind = "fhir-R4" + + authentication { + authority = "https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47" + audience = "https://acctestfhir.fhir.azurehealthcareapis.com" + } + + identity { + type = "UserAssigned" + identity_ids = [ + azurerm_user_assigned_identity.test.id + ] + } +} +`, r.template(data), data.RandomInteger, data.RandomInteger) +} + func (r HealthcareApiFhirServiceResource) requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s diff --git a/internal/services/healthcare/healthcare_medtech_service_data_source.go b/internal/services/healthcare/healthcare_medtech_service_data_source.go index d7c38489b45a..48b9c527ac39 100644 --- a/internal/services/healthcare/healthcare_medtech_service_data_source.go +++ b/internal/services/healthcare/healthcare_medtech_service_data_source.go @@ -39,7 +39,7 @@ func dataSourceHealthcareIotConnector() *pluginsdk.Resource { ValidateFunc: workspaces.ValidateWorkspaceID, }, - "identity": commonschema.SystemAssignedIdentityComputed(), + "identity": commonschema.SystemOrUserAssignedIdentityComputed(), "eventhub_namespace_name": { Type: pluginsdk.TypeString, diff --git a/website/docs/r/healthcare_fhir_service.html.markdown b/website/docs/r/healthcare_fhir_service.html.markdown index f5b827d94ecc..613c86166ee2 100644 --- a/website/docs/r/healthcare_fhir_service.html.markdown +++ b/website/docs/r/healthcare_fhir_service.html.markdown @@ -94,7 +94,9 @@ The following arguments are supported: --- An `identity` block supports the following: -* `type` - (Required) The type of identity used for the Healthcare FHIR service. Possible values are `SystemAssigned`. +* `type` - The type of managed identity to assign. Possible values are `UserAssigned` and `SystemAssigned` + +* `identity_ids` - A list of one or more Resource IDs for User Assigned Managed identities to assign. Required when `type` is set to `UserAssigned`. --- A `cors` block supports the following: