From efce2a7a96af33fcf25048f20658e2d56a6339f3 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Wed, 17 Jan 2024 03:35:01 +0000 Subject: [PATCH] Add support for enableHistoryModifications in FHIR Stores (#9823) * initial commit * clean unused code * add test. * Update resource_healthcare_fhir_store_test.go.erb * Update resource_healthcare_fhir_store_test.go.erb * Move to beta example * Update resource_healthcare_fhir_store_test.go.erb * Add version guard * Update resource_healthcare_fhir_store_test.go.erb * Update resource_healthcare_fhir_store_test.go.erb [upstream:5d303ae685495eaa845bc50696ccd6617fd1e3d4] Signed-off-by: Modular Magician --- .changelog/9823.txt | 3 ++ .../resource_healthcare_fhir_store.go | 33 +++++++++++++++++++ ...ce_healthcare_fhir_store_generated_test.go | 1 + .../resource_healthcare_fhir_store_test.go | 3 ++ .../r/healthcare_fhir_store.html.markdown | 6 ++++ 5 files changed, 46 insertions(+) create mode 100644 .changelog/9823.txt diff --git a/.changelog/9823.txt b/.changelog/9823.txt new file mode 100644 index 0000000000..2450cd24f5 --- /dev/null +++ b/.changelog/9823.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +healthcare: added `enable_history_modifications` field to `google_healthcare_fhir_store` resource (beta) +``` diff --git a/google-beta/services/healthcare/resource_healthcare_fhir_store.go b/google-beta/services/healthcare/resource_healthcare_fhir_store.go index f89d969af2..d85bacd62c 100644 --- a/google-beta/services/healthcare/resource_healthcare_fhir_store.go +++ b/google-beta/services/healthcare/resource_healthcare_fhir_store.go @@ -120,6 +120,12 @@ will fail with an error. ** Changing this property may recreate the FHIR store (removing all data) ** ** This property can be changed manually in the Google Cloud Healthcare admin console without recreating the FHIR store **`, + }, + "enable_history_modifications": { + Type: schema.TypeBool, + Optional: true, + Description: `Whether to allow the ExecuteBundle API to accept history bundles, and directly insert and overwrite historical +resource versions into the FHIR store. If set to false, using history bundles fails with an error.`, }, "enable_update_create": { Type: schema.TypeBool, @@ -383,6 +389,12 @@ func resourceHealthcareFhirStoreCreate(d *schema.ResourceData, meta interface{}) } else if v, ok := d.GetOkExists("enable_history_import"); !tpgresource.IsEmptyValue(reflect.ValueOf(enableHistoryImportProp)) && (ok || !reflect.DeepEqual(v, enableHistoryImportProp)) { obj["enableHistoryImport"] = enableHistoryImportProp } + enableHistoryModificationsProp, err := expandHealthcareFhirStoreEnableHistoryModifications(d.Get("enable_history_modifications"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("enable_history_modifications"); !tpgresource.IsEmptyValue(reflect.ValueOf(enableHistoryModificationsProp)) && (ok || !reflect.DeepEqual(v, enableHistoryModificationsProp)) { + obj["enableHistoryModifications"] = enableHistoryModificationsProp + } notificationConfigProp, err := expandHealthcareFhirStoreNotificationConfig(d.Get("notification_config"), d, config) if err != nil { return err @@ -515,6 +527,9 @@ func resourceHealthcareFhirStoreRead(d *schema.ResourceData, meta interface{}) e if err := d.Set("enable_history_import", flattenHealthcareFhirStoreEnableHistoryImport(res["enableHistoryImport"], d, config)); err != nil { return fmt.Errorf("Error reading FhirStore: %s", err) } + if err := d.Set("enable_history_modifications", flattenHealthcareFhirStoreEnableHistoryModifications(res["enableHistoryModifications"], d, config)); err != nil { + return fmt.Errorf("Error reading FhirStore: %s", err) + } if err := d.Set("labels", flattenHealthcareFhirStoreLabels(res["labels"], d, config)); err != nil { return fmt.Errorf("Error reading FhirStore: %s", err) } @@ -562,6 +577,12 @@ func resourceHealthcareFhirStoreUpdate(d *schema.ResourceData, meta interface{}) } else if v, ok := d.GetOkExists("enable_update_create"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enableUpdateCreateProp)) { obj["enableUpdateCreate"] = enableUpdateCreateProp } + enableHistoryModificationsProp, err := expandHealthcareFhirStoreEnableHistoryModifications(d.Get("enable_history_modifications"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("enable_history_modifications"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enableHistoryModificationsProp)) { + obj["enableHistoryModifications"] = enableHistoryModificationsProp + } notificationConfigProp, err := expandHealthcareFhirStoreNotificationConfig(d.Get("notification_config"), d, config) if err != nil { return err @@ -609,6 +630,10 @@ func resourceHealthcareFhirStoreUpdate(d *schema.ResourceData, meta interface{}) updateMask = append(updateMask, "enableUpdateCreate") } + if d.HasChange("enable_history_modifications") { + updateMask = append(updateMask, "enableHistoryModifications") + } + if d.HasChange("notification_config") { updateMask = append(updateMask, "notificationConfig") } @@ -749,6 +774,10 @@ func flattenHealthcareFhirStoreEnableHistoryImport(v interface{}, d *schema.Reso return v } +func flattenHealthcareFhirStoreEnableHistoryModifications(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenHealthcareFhirStoreLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { if v == nil { return v @@ -967,6 +996,10 @@ func expandHealthcareFhirStoreEnableHistoryImport(v interface{}, d tpgresource.T return v, nil } +func expandHealthcareFhirStoreEnableHistoryModifications(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandHealthcareFhirStoreNotificationConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { l := v.([]interface{}) if len(l) == 0 || l[0] == nil { diff --git a/google-beta/services/healthcare/resource_healthcare_fhir_store_generated_test.go b/google-beta/services/healthcare/resource_healthcare_fhir_store_generated_test.go index 98cff576f1..4e69eec0fe 100644 --- a/google-beta/services/healthcare/resource_healthcare_fhir_store_generated_test.go +++ b/google-beta/services/healthcare/resource_healthcare_fhir_store_generated_test.go @@ -259,6 +259,7 @@ resource "google_healthcare_fhir_store" "default" { disable_referential_integrity = false disable_resource_versioning = false enable_history_import = false + enable_history_modifications = false labels = { label1 = "labelvalue1" diff --git a/google-beta/services/healthcare/resource_healthcare_fhir_store_test.go b/google-beta/services/healthcare/resource_healthcare_fhir_store_test.go index e6be9f5ce7..2a9a1d8d22 100644 --- a/google-beta/services/healthcare/resource_healthcare_fhir_store_test.go +++ b/google-beta/services/healthcare/resource_healthcare_fhir_store_test.go @@ -134,6 +134,8 @@ resource "google_healthcare_fhir_store" "default" { disable_resource_versioning = false enable_history_import = false version = "R4" + + enable_history_modifications = false } resource "google_healthcare_dataset" "dataset" { @@ -163,6 +165,7 @@ resource "google_healthcare_fhir_store" "default" { send_previous_resource_on_delete = true } + enable_history_modifications = true labels = { label1 = "labelvalue1" } diff --git a/website/docs/r/healthcare_fhir_store.html.markdown b/website/docs/r/healthcare_fhir_store.html.markdown index dc22925cd2..c2f08f6e52 100644 --- a/website/docs/r/healthcare_fhir_store.html.markdown +++ b/website/docs/r/healthcare_fhir_store.html.markdown @@ -179,6 +179,7 @@ resource "google_healthcare_fhir_store" "default" { disable_referential_integrity = false disable_resource_versioning = false enable_history_import = false + enable_history_modifications = false labels = { label1 = "labelvalue1" @@ -269,6 +270,11 @@ The following arguments are supported: ** Changing this property may recreate the FHIR store (removing all data) ** ** This property can be changed manually in the Google Cloud Healthcare admin console without recreating the FHIR store ** +* `enable_history_modifications` - + (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) + Whether to allow the ExecuteBundle API to accept history bundles, and directly insert and overwrite historical + resource versions into the FHIR store. If set to false, using history bundles fails with an error. + * `labels` - (Optional) User-supplied key-value pairs used to organize FHIR stores.