Skip to content

Commit

Permalink
azure_healthcare_* - a state migration to work around the previousl…
Browse files Browse the repository at this point in the history
…y incorrect id casing (#19511)
  • Loading branch information
mbfrahry authored Dec 2, 2022
1 parent 49c892e commit 6cf6d98
Show file tree
Hide file tree
Showing 28 changed files with 1,433 additions and 97 deletions.
6 changes: 6 additions & 0 deletions internal/services/healthcare/healthcare_dicom_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare/migration"
"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"
Expand All @@ -35,6 +36,11 @@ func resourceHealthcareApisDicomService() *pluginsdk.Resource {
Delete: pluginsdk.DefaultTimeout(30 * time.Minute),
},

SchemaVersion: 1,
StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{
0: migration.HealthCareDicomServiceV0ToV1{},
}),

Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := parse.DicomServiceID(id)
return err
Expand Down
6 changes: 6 additions & 0 deletions internal/services/healthcare/healthcare_fhir_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare/migration"
"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"
Expand All @@ -37,6 +38,11 @@ func resourceHealthcareApisFhirService() *pluginsdk.Resource {
Delete: pluginsdk.DefaultTimeout(30 * time.Minute),
},

SchemaVersion: 1,
StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{
0: migration.HealthCareFhirV0ToV1{},
}),

Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := parse.FhirServiceID(id)
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func dataSourceHealthcareIotConnectorRead(d *pluginsdk.ResourceData, meta interf

id := parse.NewMedTechServiceID(subscriptionId, workspaceId.ResourceGroup, workspaceId.Name, d.Get("name").(string))

resp, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotconnectorName)
resp, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotConnectorName)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
Expand All @@ -85,7 +85,7 @@ func dataSourceHealthcareIotConnectorRead(d *pluginsdk.ResourceData, meta interf
}

d.SetId(id.ID())
d.Set("name", id.IotconnectorName)
d.Set("name", id.IotConnectorName)

d.Set("workspace_id", workspaceId.ID())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare/migration"
"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/tf/pluginsdk"
Expand All @@ -41,6 +42,11 @@ func resourceHealthcareApisMedTechServiceFhirDestination() *pluginsdk.Resource {
return err
}),

SchemaVersion: 1,
StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{
0: migration.HealthCareMedTechServiceFhirDestinationV0ToV1{},
}),

Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Expand Down Expand Up @@ -93,10 +99,10 @@ func resourceHealthcareApisMedTechServiceFhirDestinationCreate(d *pluginsdk.Reso
if err != nil {
return fmt.Errorf("parsing Med Tech Service error: %+v", err)
}
id := parse.NewMedTechServiceFhirDestinationID(medTechService.SubscriptionId, medTechService.ResourceGroup, medTechService.WorkspaceName, medTechService.IotconnectorName, d.Get("name").(string))
id := parse.NewMedTechServiceFhirDestinationID(medTechService.SubscriptionId, medTechService.ResourceGroup, medTechService.WorkspaceName, medTechService.IotConnectorName, d.Get("name").(string))

if d.IsNewResource() {
existing, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotconnectorName, id.FhirdestinationName)
existing, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotConnectorName, id.FhirDestinationName)
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("checking for presence of existing %s: %+v", id, err)
Expand Down Expand Up @@ -127,7 +133,7 @@ func resourceHealthcareApisMedTechServiceFhirDestinationCreate(d *pluginsdk.Reso
}
iotFhirServiceParameters.IotFhirDestinationProperties.FhirMapping = &fhirMap

medTechServiceDesFuture, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.WorkspaceName, id.IotconnectorName, id.FhirdestinationName, iotFhirServiceParameters)
medTechServiceDesFuture, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.WorkspaceName, id.IotConnectorName, id.FhirDestinationName, iotFhirServiceParameters)
if err != nil {
return fmt.Errorf("updating fhir service %s for the Med Tech Service err: %+v", id, err)
}
Expand All @@ -150,10 +156,10 @@ func resourceHealthcareApisMedTechServiceFhirDestinationRead(d *pluginsdk.Resour
return err
}

medTechServiceId := parse.NewMedTechServiceID(id.SubscriptionId, id.ResourceGroup, id.WorkspaceName, id.IotconnectorName)
medTechServiceId := parse.NewMedTechServiceID(id.SubscriptionId, id.ResourceGroup, id.WorkspaceName, id.IotConnectorName)
d.Set("medtech_service_id", medTechServiceId.ID())

resp, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotconnectorName, id.FhirdestinationName)
resp, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotConnectorName, id.FhirDestinationName)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
log.Printf("[WARN] Healthcare Apis Med Tech Service Fhir Destination %s was not found", id)
Expand All @@ -163,7 +169,7 @@ func resourceHealthcareApisMedTechServiceFhirDestinationRead(d *pluginsdk.Resour
return fmt.Errorf("retrieving %s: %+v", *id, err)
}

d.Set("name", id.FhirdestinationName)
d.Set("name", id.FhirDestinationName)

if resp.Location != nil {
d.Set("location", location.NormalizeNilable(resp.Location))
Expand Down Expand Up @@ -208,7 +214,7 @@ func resourceHealthcareApisMedTechServiceFhirDestinationUpdate(d *pluginsdk.Reso
if err != nil {
return fmt.Errorf("parsing Med Tech Service error: %+v", err)
}
id := parse.NewMedTechServiceFhirDestinationID(medTechService.SubscriptionId, medTechService.ResourceGroup, medTechService.WorkspaceName, medTechService.IotconnectorName, d.Get("name").(string))
id := parse.NewMedTechServiceFhirDestinationID(medTechService.SubscriptionId, medTechService.ResourceGroup, medTechService.WorkspaceName, medTechService.IotConnectorName, d.Get("name").(string))

fhirServiceId, err := parse.FhirServiceID(d.Get("destination_fhir_service_id").(string))
if err != nil {
Expand All @@ -230,7 +236,7 @@ func resourceHealthcareApisMedTechServiceFhirDestinationUpdate(d *pluginsdk.Reso
}
medTechFhirServiceParameters.IotFhirDestinationProperties.FhirMapping = &fhirMap

medTechServiceDesFuture, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.WorkspaceName, id.IotconnectorName, id.FhirdestinationName, medTechFhirServiceParameters)
medTechServiceDesFuture, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.WorkspaceName, id.IotConnectorName, id.FhirDestinationName, medTechFhirServiceParameters)
if err != nil {
return fmt.Errorf("updating fhir service %s for the Med Tech Service err: %+v", id, err)
}
Expand All @@ -253,7 +259,7 @@ func resourceHealthcareApisMedTechServiceFhirDestinationDelete(d *pluginsdk.Reso
return err
}

future, err := client.Delete(ctx, id.ResourceGroup, id.WorkspaceName, id.IotconnectorName, id.FhirdestinationName)
future, err := client.Delete(ctx, id.ResourceGroup, id.WorkspaceName, id.IotConnectorName, id.FhirDestinationName)
if err != nil {
if response.WasNotFound(future.Response()) {
return nil
Expand All @@ -278,7 +284,7 @@ func resourceHealthcareApisMedTechServiceFhirDestinationDelete(d *pluginsdk.Reso

func healthcareApiMedTechServiceFhirDestinationStateCodeRefreshFunc(ctx context.Context, client *healthcareapis.IotConnectorFhirDestinationClient, id parse.MedTechServiceFhirDestinationId) pluginsdk.StateRefreshFunc {
return func() (interface{}, string, error) {
res, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotconnectorName, id.FhirdestinationName)
res, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotConnectorName, id.FhirDestinationName)

if err != nil {
if utils.ResponseWasNotFound(res.Response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (r HealthCareMedTechServiceFhirDestinationResource) Exists(ctx context.Cont
if err != nil {
return nil, err
}
resp, err := client.HealthCare.HealthcareWorkspaceMedTechServiceFhirDestinationClient.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotconnectorName, id.FhirdestinationName)
resp, err := client.HealthCare.HealthcareWorkspaceMedTechServiceFhirDestinationClient.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotConnectorName, id.FhirDestinationName)
if err != nil {
return nil, fmt.Errorf("retrieving %s, %+v", *id, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
eventhubValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare/migration"
"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"
Expand All @@ -39,6 +40,11 @@ func resourceHealthcareApisMedTechService() *pluginsdk.Resource {
Delete: pluginsdk.DefaultTimeout(90 * time.Minute),
},

SchemaVersion: 1,
StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{
0: migration.HealthCareIoTConnectorV0ToV1{},
}),

Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := parse.MedTechServiceID(id)
return err
Expand Down Expand Up @@ -106,7 +112,7 @@ func resourceHealthcareApisMedTechServiceCreate(d *pluginsdk.ResourceData, meta
medTechServiceId := parse.NewMedTechServiceID(workspace.SubscriptionId, workspace.ResourceGroup, workspace.Name, d.Get("name").(string))

if d.IsNewResource() {
existing, err := client.Get(ctx, medTechServiceId.ResourceGroup, medTechServiceId.WorkspaceName, medTechServiceId.IotconnectorName)
existing, err := client.Get(ctx, medTechServiceId.ResourceGroup, medTechServiceId.WorkspaceName, medTechServiceId.IotConnectorName)
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("checking for presence of existing %s: %+v", medTechServiceId, err)
Expand Down Expand Up @@ -143,7 +149,7 @@ func resourceHealthcareApisMedTechServiceCreate(d *pluginsdk.ResourceData, meta
}
parameters.IotConnectorProperties.DeviceMapping = &deviceContentMap

future, err := client.CreateOrUpdate(ctx, medTechServiceId.ResourceGroup, medTechServiceId.WorkspaceName, medTechServiceId.IotconnectorName, parameters)
future, err := client.CreateOrUpdate(ctx, medTechServiceId.ResourceGroup, medTechServiceId.WorkspaceName, medTechServiceId.IotConnectorName, parameters)
if err != nil {
return fmt.Errorf("creating %s: %+v", medTechServiceId, err)
}
Expand Down Expand Up @@ -180,7 +186,7 @@ func resourceHealthcareApisMedTechServiceRead(d *pluginsdk.ResourceData, meta in
return err
}

resp, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotconnectorName)
resp, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotConnectorName)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
log.Printf("[WARN] Healthcare Apis MedTech Service %s was not found", id)
Expand All @@ -190,7 +196,7 @@ func resourceHealthcareApisMedTechServiceRead(d *pluginsdk.ResourceData, meta in
return fmt.Errorf("retrieving %s: %+v", *id, err)
}

d.Set("name", id.IotconnectorName)
d.Set("name", id.IotConnectorName)
workspaceId := parse.NewWorkspaceID(id.SubscriptionId, id.ResourceGroup, id.WorkspaceName)
d.Set("workspace_id", workspaceId.ID())

Expand Down Expand Up @@ -280,7 +286,7 @@ func resourceHealthcareApisMedTechServiceUpdate(d *pluginsdk.ResourceData, meta
}
parameters.IotConnectorProperties.DeviceMapping = &deviceContentMap

future, err := client.CreateOrUpdate(ctx, medTechServiceId.ResourceGroup, medTechServiceId.WorkspaceName, medTechServiceId.IotconnectorName, parameters)
future, err := client.CreateOrUpdate(ctx, medTechServiceId.ResourceGroup, medTechServiceId.WorkspaceName, medTechServiceId.IotConnectorName, parameters)
if err != nil {
return fmt.Errorf("updating %s: %+v", medTechServiceId, err)
}
Expand Down Expand Up @@ -317,7 +323,7 @@ func resourceHealthcareApisMedTechServiceDelete(d *pluginsdk.ResourceData, meta
return err
}

future, err := client.Delete(ctx, id.ResourceGroup, id.IotconnectorName, id.WorkspaceName)
future, err := client.Delete(ctx, id.ResourceGroup, id.IotConnectorName, id.WorkspaceName)
if err != nil {
if response.WasNotFound(future.Response()) {
return nil
Expand All @@ -342,7 +348,7 @@ func resourceHealthcareApisMedTechServiceDelete(d *pluginsdk.ResourceData, meta

func medTechServiceStateStatusCodeRefreshFunc(ctx context.Context, client *healthcareapis.IotConnectorsClient, id parse.MedTechServiceId) pluginsdk.StateRefreshFunc {
return func() (interface{}, string, error) {
res, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotconnectorName)
res, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotConnectorName)

if err != nil {
if utils.ResponseWasNotFound(res.Response) {
Expand Down Expand Up @@ -392,7 +398,7 @@ func suppressJsonOrderingDifference(_, old, new string, _ *pluginsdk.ResourceDat

func medTechServiceCreateStateRefreshFunc(ctx context.Context, client *healthcareapis.IotConnectorsClient, medTechServiceId parse.MedTechServiceId) pluginsdk.StateRefreshFunc {
return func() (interface{}, string, error) {
resp, err := client.Get(ctx, medTechServiceId.ResourceGroup, medTechServiceId.WorkspaceName, medTechServiceId.IotconnectorName)
resp, err := client.Get(ctx, medTechServiceId.ResourceGroup, medTechServiceId.WorkspaceName, medTechServiceId.IotConnectorName)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return nil, "", fmt.Errorf("unable to retrieve MedTech Service %q: %+v", medTechServiceId, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (r HealthCareWorkspaceMedTechServiceResource) Exists(ctx context.Context, c
if err != nil {
return nil, err
}
resp, err := client.HealthCare.HealthcareWorkspaceMedTechServiceClient.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotconnectorName)
resp, err := client.HealthCare.HealthcareWorkspaceMedTechServiceClient.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.IotConnectorName)
if err != nil {
return nil, fmt.Errorf("retrieving %s, %+v", *id, err)
}
Expand Down
Loading

0 comments on commit 6cf6d98

Please sign in to comment.