From 520465130513d33a77be9d09bfdc4e87c66671ff Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Thu, 23 Apr 2020 17:43:28 -0700 Subject: [PATCH] Allow fields to be removed at a specific version (#3417) The healthcare API has deprecated a field at beta and removed it from the GA launch of the api. In order to support this without having to duplicate the entire resource this change supports defining a single field multiple times with a different configruation for each version. Specifically it allows a field to exist as deprecated at one version but not at another. This also introduces the removed_message field. --- api/type.rb | 19 +++++++ products/healthcare/api.yaml | 54 ++++++++++++++++++- provider/terraform/sub_template.rb | 4 ++ .../healthcare_hl7_v2_store_basic.tf.erb | 2 +- templates/terraform/schema_property.erb | 4 +- .../resource_healthcare_hl7_v2_store_test.go | 11 ++-- third_party/terraform/utils/config.go.erb | 2 +- .../terraform/utils/iam_healthcare_dataset.go | 2 +- .../utils/iam_healthcare_dicom_store.go | 2 +- .../utils/iam_healthcare_fhir_store.go | 2 +- .../utils/iam_healthcare_hl7_v2_store.go | 2 +- 11 files changed, 92 insertions(+), 12 deletions(-) diff --git a/api/type.rb b/api/type.rb index a2f137cd4fbd..696a6a74243e 100644 --- a/api/type.rb +++ b/api/type.rb @@ -31,6 +31,11 @@ module Fields # string, as providers expect a single-line one w/o a newline. attr_reader :deprecation_message + # Add a removed message for fields no longer supported in the API. This should + # be used for fields supported in one version but have been removed from + # a different version. + attr_reader :removed_message + attr_reader :output # If set value will not be sent to server on sync attr_reader :input # If set to true value is used only on creation @@ -70,6 +75,7 @@ module Fields attr_reader :allow_empty_object attr_reader :min_version + attr_reader :exact_version # A list of properties that conflict with this property. attr_reader :conflicts @@ -99,7 +105,9 @@ def validate check :description, type: ::String, required: true check :exclude, type: :boolean, default: false, required: true check :deprecation_message, type: ::String + check :removed_message, type: ::String check :min_version, type: ::String + check :exact_version, type: ::String check :output, type: :boolean check :required, type: :boolean check :send_empty_value, type: :boolean @@ -258,7 +266,14 @@ def min_version end end + def exact_version + return nil if @exact_version.nil? || @exact_version.blank? + + @__resource.__product.version_obj(@exact_version) + end + def exclude_if_not_in_version!(version) + @exclude ||= exact_version != version unless exact_version.nil? @exclude ||= version < min_version end @@ -289,6 +304,10 @@ def nested_properties? !nested_properties.empty? end + def removed? + !(@removed_message.nil? || @removed_message == '') + end + def deprecated? !(@deprecation_message.nil? || @deprecation_message == '') end diff --git a/products/healthcare/api.yaml b/products/healthcare/api.yaml index e3abd3ccd43f..357f85b8b1f1 100644 --- a/products/healthcare/api.yaml +++ b/products/healthcare/api.yaml @@ -375,9 +375,62 @@ objects: An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }. + - !ruby/object:Api::Type::Array + name: notificationConfigs + description: |- + A list of notification configs. Each configuration uses a filter to determine whether to publish a + message (both Ingest & Create) on the corresponding notification destination. Only the message name + is sent as part of the notification. Supplied by the client. + item_type: !ruby/object:Api::Type::NestedObject + properties: + - !ruby/object:Api::Type::String + name: pubsubTopic + description: | + The Cloud Pub/Sub topic that notifications of changes are published on. Supplied by the client. + PubsubMessage.Data will contain the resource name. PubsubMessage.MessageId is the ID of this message. + It is guaranteed to be unique within the topic. PubsubMessage.PublishTime is the time at which the message + was published. Notifications are only sent if the topic is non-empty. Topic names must be scoped to a + project. cloud-healthcare@system.gserviceaccount.com must have publisher permissions on the given + Cloud Pub/Sub topic. Not having adequate permissions will cause the calls that send notifications to fail. + If a notification cannot be published to Cloud Pub/Sub, errors will be logged to Stackdriver + required: true + - !ruby/object:Api::Type::String + name: filter + description: | + Restricts notifications sent for messages matching a filter. If this is empty, all messages + are matched. Syntax: https://cloud.google.com/appengine/docs/standard/python/search/query_strings + + Fields/functions available for filtering are: + + * messageType, from the MSH-9.1 field. For example, NOT messageType = "ADT". + * send_date or sendDate, the YYYY-MM-DD date the message was sent in the dataset's timeZone, from the MSH-7 segment. For example, send_date < "2017-01-02". + * sendTime, the timestamp when the message was sent, using the RFC3339 time format for comparisons, from the MSH-7 segment. For example, sendTime < "2017-01-02T00:00:00-05:00". + * sendFacility, the care center that the message came from, from the MSH-4 segment. For example, sendFacility = "ABC". + * PatientId(value, type), which matches if the message lists a patient having an ID of the given value and type in the PID-2, PID-3, or PID-4 segments. For example, PatientId("123456", "MRN"). + * labels.x, a string value of the label with key x as set using the Message.labels map. For example, labels."priority"="high". The operator :* can be used to assert the existence of a label. For example, labels."priority":*. - !ruby/object:Api::Type::NestedObject name: notificationConfig + removed_message: This field has been replaced by notificationConfigs + exact_version: ga + required: false + update_url: '{{dataset}}/hl7V2Stores/{{name}}' + properties: + - !ruby/object:Api::Type::String + name: pubsubTopic + description: | + The Cloud Pub/Sub topic that notifications of changes are published on. Supplied by the client. + PubsubMessage.Data will contain the resource name. PubsubMessage.MessageId is the ID of this message. + It is guaranteed to be unique within the topic. PubsubMessage.PublishTime is the time at which the message + was published. Notifications are only sent if the topic is non-empty. Topic names must be scoped to a + project. cloud-healthcare@system.gserviceaccount.com must have publisher permissions on the given + Cloud Pub/Sub topic. Not having adequate permissions will cause the calls that send notifications to fail. + required: true + - !ruby/object:Api::Type::NestedObject + name: notificationConfig + # This field is duplicated because beta and ga have different behaviors. + deprecation_message: This field has been replaced by notificationConfigs + exact_version: beta required: false update_url: '{{dataset}}/hl7V2Stores/{{name}}' properties: @@ -391,7 +444,6 @@ objects: project. cloud-healthcare@system.gserviceaccount.com must have publisher permissions on the given Cloud Pub/Sub topic. Not having adequate permissions will cause the calls that send notifications to fail. required: true - - !ruby/object:Api::Type::Time name: 'creationTime' description: | diff --git a/provider/terraform/sub_template.rb b/provider/terraform/sub_template.rb index a4e38113d3d6..0b3149f91547 100644 --- a/provider/terraform/sub_template.rb +++ b/provider/terraform/sub_template.rb @@ -54,11 +54,15 @@ def build_expand_resource_ref(var_name, property) end def build_property_documentation(property) + return if property.removed? + compile_template 'templates/terraform/property_documentation.erb', property: property end def build_nested_property_documentation(property) + return if property.removed? + compile_template( 'templates/terraform/nested_property_documentation.erb', property: property diff --git a/templates/terraform/examples/healthcare_hl7_v2_store_basic.tf.erb b/templates/terraform/examples/healthcare_hl7_v2_store_basic.tf.erb index ebe218c084c9..908532fe2aa0 100644 --- a/templates/terraform/examples/healthcare_hl7_v2_store_basic.tf.erb +++ b/templates/terraform/examples/healthcare_hl7_v2_store_basic.tf.erb @@ -2,7 +2,7 @@ resource "google_healthcare_hl7_v2_store" "default" { name = "<%= ctx[:vars]['hl7_v2_store_name'] %>" dataset = google_healthcare_dataset.dataset.id - notification_config { + notification_configs { pubsub_topic = google_pubsub_topic.topic.id } diff --git a/templates/terraform/schema_property.erb b/templates/terraform/schema_property.erb index 689b910b2b0d..9d9b34a33fe3 100644 --- a/templates/terraform/schema_property.erb +++ b/templates/terraform/schema_property.erb @@ -36,7 +36,9 @@ <% else -%> Optional: true, <% end -%> -<% if property.deprecated? -%> +<% if property.removed? -%> + Removed: "<%= property.removed_message %>", +<% elsif property.deprecated? -%> Deprecated: "<%= property.deprecation_message %>", <% end -%> <% if force_new?(property, object) -%> diff --git a/third_party/terraform/tests/resource_healthcare_hl7_v2_store_test.go b/third_party/terraform/tests/resource_healthcare_hl7_v2_store_test.go index afd1fd874418..7184b4c1c092 100644 --- a/third_party/terraform/tests/resource_healthcare_hl7_v2_store_test.go +++ b/third_party/terraform/tests/resource_healthcare_hl7_v2_store_test.go @@ -138,7 +138,7 @@ resource "google_healthcare_hl7_v2_store" "default" { segment_terminator = "Jw==" } - notification_config { + notification_configs { pubsub_topic = google_pubsub_topic.topic.id } @@ -195,9 +195,12 @@ func testAccCheckGoogleHealthcareHl7V2StoreUpdate(t *testing.T, pubsubTopic stri return fmt.Errorf("hl7_v2_store labels not updated: %s", gcpResourceUri) } - topicName := path.Base(response.NotificationConfig.PubsubTopic) - if topicName != pubsubTopic { - return fmt.Errorf("hl7_v2_store 'NotificationConfig' not updated ('%s' != '%s'): %s", topicName, pubsubTopic, gcpResourceUri) + notifications := response.NotificationConfigs + if len(notifications) > 0 { + topicName := path.Base(notifications[0].PubsubTopic) + if topicName != pubsubTopic { + return fmt.Errorf("hl7_v2_store 'NotificationConfig' not updated ('%s' != '%s'): %s", topicName, pubsubTopic, gcpResourceUri) + } } } diff --git a/third_party/terraform/utils/config.go.erb b/third_party/terraform/utils/config.go.erb index 85a87609a0b2..2e9ed01a01a6 100644 --- a/third_party/terraform/utils/config.go.erb +++ b/third_party/terraform/utils/config.go.erb @@ -42,7 +42,7 @@ import ( "google.golang.org/api/dns/v1" dnsBeta "google.golang.org/api/dns/v1beta2" file "google.golang.org/api/file/v1beta1" - healthcare "google.golang.org/api/healthcare/v1beta1" + healthcare "google.golang.org/api/healthcare/v1" "google.golang.org/api/iam/v1" iamcredentials "google.golang.org/api/iamcredentials/v1" cloudlogging "google.golang.org/api/logging/v2" diff --git a/third_party/terraform/utils/iam_healthcare_dataset.go b/third_party/terraform/utils/iam_healthcare_dataset.go index 2f0b9fb621a7..5179fff850af 100644 --- a/third_party/terraform/utils/iam_healthcare_dataset.go +++ b/third_party/terraform/utils/iam_healthcare_dataset.go @@ -3,7 +3,7 @@ package google import ( "fmt" - healthcare "google.golang.org/api/healthcare/v1beta1" + healthcare "google.golang.org/api/healthcare/v1" "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" diff --git a/third_party/terraform/utils/iam_healthcare_dicom_store.go b/third_party/terraform/utils/iam_healthcare_dicom_store.go index c3c44cd9fcf4..ff7d946b1bc4 100644 --- a/third_party/terraform/utils/iam_healthcare_dicom_store.go +++ b/third_party/terraform/utils/iam_healthcare_dicom_store.go @@ -3,7 +3,7 @@ package google import ( "fmt" - healthcare "google.golang.org/api/healthcare/v1beta1" + healthcare "google.golang.org/api/healthcare/v1" "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" diff --git a/third_party/terraform/utils/iam_healthcare_fhir_store.go b/third_party/terraform/utils/iam_healthcare_fhir_store.go index 6d1663b209ac..ebb513e5103d 100644 --- a/third_party/terraform/utils/iam_healthcare_fhir_store.go +++ b/third_party/terraform/utils/iam_healthcare_fhir_store.go @@ -3,7 +3,7 @@ package google import ( "fmt" - healthcare "google.golang.org/api/healthcare/v1beta1" + healthcare "google.golang.org/api/healthcare/v1" "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" diff --git a/third_party/terraform/utils/iam_healthcare_hl7_v2_store.go b/third_party/terraform/utils/iam_healthcare_hl7_v2_store.go index f26022a80d20..77f7561df5cc 100644 --- a/third_party/terraform/utils/iam_healthcare_hl7_v2_store.go +++ b/third_party/terraform/utils/iam_healthcare_hl7_v2_store.go @@ -3,7 +3,7 @@ package google import ( "fmt" - healthcare "google.golang.org/api/healthcare/v1beta1" + healthcare "google.golang.org/api/healthcare/v1" "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform-plugin-sdk/helper/schema"