Skip to content

Commit 2753939

Browse files
Healthcare Fhir Store, promote notification_configs field to GA, deprecation message for notification_config (#10851) (#18306)
[upstream:710c06bdc931d2228e1a825af70f8afcd5110985] Signed-off-by: Modular Magician <[email protected]>
1 parent c0b8700 commit 2753939

4 files changed

+213
-50
lines changed

google/services/healthcare/resource_healthcare_fhir_store.go

+137
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Please refer to the field 'effective_labels' for all of the labels present on th
163163
"notification_config": {
164164
Type: schema.TypeList,
165165
Optional: true,
166+
Deprecated: "`notification_config` is deprecated and will be removed in a future major release. Use `notification_configs` instead.",
166167
Description: `A nested object resource`,
167168
MaxItems: 1,
168169
Elem: &schema.Resource{
@@ -180,6 +181,43 @@ Cloud Pub/Sub topic. Not having adequate permissions will cause the calls that s
180181
},
181182
},
182183
},
184+
"notification_configs": {
185+
Type: schema.TypeList,
186+
Optional: true,
187+
Description: `A list of notifcation configs that configure the notification for every resource mutation in this FHIR store.`,
188+
Elem: &schema.Resource{
189+
Schema: map[string]*schema.Schema{
190+
"pubsub_topic": {
191+
Type: schema.TypeString,
192+
Required: true,
193+
Description: `The Cloud Pub/Sub topic that notifications of changes are published on. Supplied by the client.
194+
PubsubMessage.Data will contain the resource name. PubsubMessage.MessageId is the ID of this message.
195+
It is guaranteed to be unique within the topic. PubsubMessage.PublishTime is the time at which the message
196+
was published. Notifications are only sent if the topic is non-empty. Topic names must be scoped to a
197+
project. [email protected] must have publisher permissions on the given
198+
Cloud Pub/Sub topic. Not having adequate permissions will cause the calls that send notifications to fail.`,
199+
},
200+
"send_full_resource": {
201+
Type: schema.TypeBool,
202+
Optional: true,
203+
Description: `Whether to send full FHIR resource to this Pub/Sub topic for Create and Update operation.
204+
Note that setting this to true does not guarantee that all resources will be sent in the format of
205+
full FHIR resource. When a resource change is too large or during heavy traffic, only the resource name will be
206+
sent. Clients should always check the "payloadType" label from a Pub/Sub message to determine whether
207+
it needs to fetch the full resource as a separate operation.`,
208+
},
209+
"send_previous_resource_on_delete": {
210+
Type: schema.TypeBool,
211+
Optional: true,
212+
Description: `Whether to send full FHIR resource to this Pub/Sub topic for deleting FHIR resource. Note that setting this to
213+
true does not guarantee that all previous resources will be sent in the format of full FHIR resource. When a
214+
resource change is too large or during heavy traffic, only the resource name will be sent. Clients should always
215+
check the "payloadType" label from a Pub/Sub message to determine whether it needs to fetch the full previous
216+
resource as a separate operation.`,
217+
},
218+
},
219+
},
220+
},
183221
"stream_configs": {
184222
Type: schema.TypeList,
185223
Optional: true,
@@ -364,6 +402,12 @@ func resourceHealthcareFhirStoreCreate(d *schema.ResourceData, meta interface{})
364402
} else if v, ok := d.GetOkExists("default_search_handling_strict"); !tpgresource.IsEmptyValue(reflect.ValueOf(defaultSearchHandlingStrictProp)) && (ok || !reflect.DeepEqual(v, defaultSearchHandlingStrictProp)) {
365403
obj["defaultSearchHandlingStrict"] = defaultSearchHandlingStrictProp
366404
}
405+
notificationConfigsProp, err := expandHealthcareFhirStoreNotificationConfigs(d.Get("notification_configs"), d, config)
406+
if err != nil {
407+
return err
408+
} else if v, ok := d.GetOkExists("notification_configs"); !tpgresource.IsEmptyValue(reflect.ValueOf(notificationConfigsProp)) && (ok || !reflect.DeepEqual(v, notificationConfigsProp)) {
409+
obj["notificationConfigs"] = notificationConfigsProp
410+
}
367411
labelsProp, err := expandHealthcareFhirStoreEffectiveLabels(d.Get("effective_labels"), d, config)
368412
if err != nil {
369413
return err
@@ -488,6 +532,9 @@ func resourceHealthcareFhirStoreRead(d *schema.ResourceData, meta interface{}) e
488532
if err := d.Set("default_search_handling_strict", flattenHealthcareFhirStoreDefaultSearchHandlingStrict(res["defaultSearchHandlingStrict"], d, config)); err != nil {
489533
return fmt.Errorf("Error reading FhirStore: %s", err)
490534
}
535+
if err := d.Set("notification_configs", flattenHealthcareFhirStoreNotificationConfigs(res["notificationConfigs"], d, config)); err != nil {
536+
return fmt.Errorf("Error reading FhirStore: %s", err)
537+
}
491538
if err := d.Set("terraform_labels", flattenHealthcareFhirStoreTerraformLabels(res["labels"], d, config)); err != nil {
492539
return fmt.Errorf("Error reading FhirStore: %s", err)
493540
}
@@ -538,6 +585,12 @@ func resourceHealthcareFhirStoreUpdate(d *schema.ResourceData, meta interface{})
538585
} else if v, ok := d.GetOkExists("default_search_handling_strict"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, defaultSearchHandlingStrictProp)) {
539586
obj["defaultSearchHandlingStrict"] = defaultSearchHandlingStrictProp
540587
}
588+
notificationConfigsProp, err := expandHealthcareFhirStoreNotificationConfigs(d.Get("notification_configs"), d, config)
589+
if err != nil {
590+
return err
591+
} else if v, ok := d.GetOkExists("notification_configs"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, notificationConfigsProp)) {
592+
obj["notificationConfigs"] = notificationConfigsProp
593+
}
541594
labelsProp, err := expandHealthcareFhirStoreEffectiveLabels(d.Get("effective_labels"), d, config)
542595
if err != nil {
543596
return err
@@ -574,6 +627,10 @@ func resourceHealthcareFhirStoreUpdate(d *schema.ResourceData, meta interface{})
574627
updateMask = append(updateMask, "defaultSearchHandlingStrict")
575628
}
576629

630+
if d.HasChange("notification_configs") {
631+
updateMask = append(updateMask, "notificationConfigs")
632+
}
633+
577634
if d.HasChange("effective_labels") {
578635
updateMask = append(updateMask, "labels")
579636
}
@@ -841,6 +898,38 @@ func flattenHealthcareFhirStoreDefaultSearchHandlingStrict(v interface{}, d *sch
841898
return v
842899
}
843900

901+
func flattenHealthcareFhirStoreNotificationConfigs(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
902+
if v == nil {
903+
return v
904+
}
905+
l := v.([]interface{})
906+
transformed := make([]interface{}, 0, len(l))
907+
for _, raw := range l {
908+
original := raw.(map[string]interface{})
909+
if len(original) < 1 {
910+
// Do not include empty json objects coming back from the api
911+
continue
912+
}
913+
transformed = append(transformed, map[string]interface{}{
914+
"pubsub_topic": flattenHealthcareFhirStoreNotificationConfigsPubsubTopic(original["pubsubTopic"], d, config),
915+
"send_full_resource": flattenHealthcareFhirStoreNotificationConfigsSendFullResource(original["sendFullResource"], d, config),
916+
"send_previous_resource_on_delete": flattenHealthcareFhirStoreNotificationConfigsSendPreviousResourceOnDelete(original["sendPreviousResourceOnDelete"], d, config),
917+
})
918+
}
919+
return transformed
920+
}
921+
func flattenHealthcareFhirStoreNotificationConfigsPubsubTopic(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
922+
return v
923+
}
924+
925+
func flattenHealthcareFhirStoreNotificationConfigsSendFullResource(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
926+
return v
927+
}
928+
929+
func flattenHealthcareFhirStoreNotificationConfigsSendPreviousResourceOnDelete(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
930+
return v
931+
}
932+
844933
func flattenHealthcareFhirStoreTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
845934
if v == nil {
846935
return v
@@ -1053,6 +1142,54 @@ func expandHealthcareFhirStoreDefaultSearchHandlingStrict(v interface{}, d tpgre
10531142
return v, nil
10541143
}
10551144

1145+
func expandHealthcareFhirStoreNotificationConfigs(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1146+
l := v.([]interface{})
1147+
req := make([]interface{}, 0, len(l))
1148+
for _, raw := range l {
1149+
if raw == nil {
1150+
continue
1151+
}
1152+
original := raw.(map[string]interface{})
1153+
transformed := make(map[string]interface{})
1154+
1155+
transformedPubsubTopic, err := expandHealthcareFhirStoreNotificationConfigsPubsubTopic(original["pubsub_topic"], d, config)
1156+
if err != nil {
1157+
return nil, err
1158+
} else if val := reflect.ValueOf(transformedPubsubTopic); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1159+
transformed["pubsubTopic"] = transformedPubsubTopic
1160+
}
1161+
1162+
transformedSendFullResource, err := expandHealthcareFhirStoreNotificationConfigsSendFullResource(original["send_full_resource"], d, config)
1163+
if err != nil {
1164+
return nil, err
1165+
} else if val := reflect.ValueOf(transformedSendFullResource); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1166+
transformed["sendFullResource"] = transformedSendFullResource
1167+
}
1168+
1169+
transformedSendPreviousResourceOnDelete, err := expandHealthcareFhirStoreNotificationConfigsSendPreviousResourceOnDelete(original["send_previous_resource_on_delete"], d, config)
1170+
if err != nil {
1171+
return nil, err
1172+
} else if val := reflect.ValueOf(transformedSendPreviousResourceOnDelete); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1173+
transformed["sendPreviousResourceOnDelete"] = transformedSendPreviousResourceOnDelete
1174+
}
1175+
1176+
req = append(req, transformed)
1177+
}
1178+
return req, nil
1179+
}
1180+
1181+
func expandHealthcareFhirStoreNotificationConfigsPubsubTopic(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1182+
return v, nil
1183+
}
1184+
1185+
func expandHealthcareFhirStoreNotificationConfigsSendFullResource(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1186+
return v, nil
1187+
}
1188+
1189+
func expandHealthcareFhirStoreNotificationConfigsSendPreviousResourceOnDelete(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1190+
return v, nil
1191+
}
1192+
10561193
func expandHealthcareFhirStoreEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
10571194
if v == nil {
10581195
return map[string]string{}, nil

google/services/healthcare/resource_healthcare_fhir_store_generated_test.go

+60-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ resource "google_healthcare_fhir_store" "default" {
6969
enable_history_import = false
7070
default_search_handling_strict = false
7171
72-
notification_config {
72+
notification_configs {
7373
pubsub_topic = google_pubsub_topic.topic.id
7474
}
7575
@@ -222,6 +222,65 @@ resource "google_healthcare_dataset" "dataset" {
222222
`, context)
223223
}
224224

225+
func TestAccHealthcareFhirStore_healthcareFhirStoreNotificationConfigsExample(t *testing.T) {
226+
t.Parallel()
227+
228+
context := map[string]interface{}{
229+
"random_suffix": acctest.RandString(t, 10),
230+
}
231+
232+
acctest.VcrTest(t, resource.TestCase{
233+
PreCheck: func() { acctest.AccTestPreCheck(t) },
234+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
235+
CheckDestroy: testAccCheckHealthcareFhirStoreDestroyProducer(t),
236+
Steps: []resource.TestStep{
237+
{
238+
Config: testAccHealthcareFhirStore_healthcareFhirStoreNotificationConfigsExample(context),
239+
},
240+
{
241+
ResourceName: "google_healthcare_fhir_store.default",
242+
ImportState: true,
243+
ImportStateVerify: true,
244+
ImportStateVerifyIgnore: []string{"dataset", "labels", "self_link", "terraform_labels"},
245+
},
246+
},
247+
})
248+
}
249+
250+
func testAccHealthcareFhirStore_healthcareFhirStoreNotificationConfigsExample(context map[string]interface{}) string {
251+
return acctest.Nprintf(`
252+
resource "google_healthcare_fhir_store" "default" {
253+
name = "tf-test-example-fhir-store%{random_suffix}"
254+
dataset = google_healthcare_dataset.dataset.id
255+
version = "R4"
256+
257+
enable_update_create = false
258+
disable_referential_integrity = false
259+
disable_resource_versioning = false
260+
enable_history_import = false
261+
262+
labels = {
263+
label1 = "labelvalue1"
264+
}
265+
266+
notification_configs {
267+
pubsub_topic = "${google_pubsub_topic.topic.id}"
268+
send_full_resource = true
269+
send_previous_resource_on_delete = true
270+
}
271+
}
272+
273+
resource "google_pubsub_topic" "topic" {
274+
name = "tf-test-fhir-notifications%{random_suffix}"
275+
}
276+
277+
resource "google_healthcare_dataset" "dataset" {
278+
name = "tf-test-example-dataset%{random_suffix}"
279+
location = "us-central1"
280+
}
281+
`, context)
282+
}
283+
225284
func testAccCheckHealthcareFhirStoreDestroyProducer(t *testing.T) func(s *terraform.State) error {
226285
return func(s *terraform.State) error {
227286
for name, rs := range s.RootModule().Resources {

google/services/healthcare/resource_healthcare_fhir_store_test.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,13 @@ resource "google_healthcare_fhir_store" "default" {
154154
version = "R4"
155155
156156
157-
notification_config {
158-
pubsub_topic = google_pubsub_topic.topic.id
157+
notification_configs {
158+
pubsub_topic = google_pubsub_topic.topic.id
159+
send_full_resource = true
160+
send_previous_resource_on_delete = true
159161
}
160162
163+
161164
labels = {
162165
label1 = "labelvalue1"
163166
}
@@ -210,9 +213,12 @@ func testAccCheckGoogleHealthcareFhirStoreUpdate(t *testing.T, pubsubTopic strin
210213
return fmt.Errorf("fhirStore labels not updated: %s", gcpResourceUri)
211214
}
212215

213-
topicName := path.Base(response.NotificationConfig.PubsubTopic)
214-
if topicName != pubsubTopic {
215-
return fmt.Errorf("fhirStore 'NotificationConfig' not updated ('%s' != '%s'): %s", topicName, pubsubTopic, gcpResourceUri)
216+
notifications := response.NotificationConfigs
217+
if len(notifications) > 0 {
218+
topicName := path.Base(notifications[0].PubsubTopic)
219+
if topicName != pubsubTopic {
220+
return fmt.Errorf("fhirStore 'NotificationConfig' not updated ('%s' != '%s'): %s", topicName, pubsubTopic, gcpResourceUri)
221+
}
216222
}
217223
}
218224

0 commit comments

Comments
 (0)