diff --git a/products/healthcare/api.yaml b/products/healthcare/api.yaml index 981cd1afee52..f0520cec6aa0 100644 --- a/products/healthcare/api.yaml +++ b/products/healthcare/api.yaml @@ -333,6 +333,7 @@ objects: at_least_one_of: - parser_config.0.allow_null_header - parser_config.0.segment_terminator + - parser_config.0.schema description: | Determines whether messages with no header are allowed. - !ruby/object:Api::Type::String @@ -340,11 +341,20 @@ objects: at_least_one_of: - parser_config.0.allow_null_header - parser_config.0.segment_terminator + - parser_config.0.schema description: | Byte(s) to be used as the segment terminator. If this is unset, '\r' will be used as segment terminator. A base64-encoded string. - + - !ruby/object:Api::Type::String + name: schema + at_least_one_of: + - parser_config.0.allow_null_header + - parser_config.0.segment_terminator + - parser_config.0.schema + description: | + JSON encoded string for schemas used to parse messages in this + store if schematized parsing is desired. - !ruby/object:Api::Type::KeyValuePairs name: labels required: false diff --git a/products/healthcare/terraform.yaml b/products/healthcare/terraform.yaml index 92c80245ca94..7ff64a207baa 100644 --- a/products/healthcare/terraform.yaml +++ b/products/healthcare/terraform.yaml @@ -88,15 +88,28 @@ overrides: !ruby/object:Overrides::ResourceOverrides examples: - !ruby/object:Provider::Terraform::Examples name: "healthcare_hl7_v2_store_basic" - skip_test: true - primary_resource_id: "default" + min_version: beta + primary_resource_id: "store" vars: dataset_name: "example-dataset" hl7_v2_store_name: "example-hl7-v2-store" pubsub_topic: "hl7-v2-notifications" + - !ruby/object:Provider::Terraform::Examples + name: "healthcare_hl7_v2_store_parser_config" + min_version: beta + primary_resource_id: "store" + vars: + dataset_name: "example-dataset" + hl7_v2_store_name: "example-hl7-v2-store" properties: creationTime: !ruby/object:Overrides::Terraform::PropertyOverride exclude: true + parserConfig.schema: !ruby/object:Overrides::Terraform::PropertyOverride + custom_expand: 'templates/terraform/custom_expand/healthcare_hl7_v2_store_schema.erb' + custom_flatten: 'templates/terraform/custom_flatten/healthcare_hl7_v2_store_schema.erb' + state_func: 'func(v interface{}) string { s, _ := structure.NormalizeJsonString(v); return s }' + validation: !ruby/object:Provider::Terraform::Validation + function: 'validation.ValidateJsonString' selfLink: !ruby/object:Overrides::Terraform::PropertyOverride ignore_read: true custom_code: !ruby/object:Provider::Terraform::CustomCode diff --git a/templates/terraform/custom_expand/healthcare_hl7_v2_store_schema.erb b/templates/terraform/custom_expand/healthcare_hl7_v2_store_schema.erb new file mode 100644 index 000000000000..ef3f0dec09e3 --- /dev/null +++ b/templates/terraform/custom_expand/healthcare_hl7_v2_store_schema.erb @@ -0,0 +1,25 @@ +<%- # the license inside this block applies to this file + # Copyright 2020 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +-%> +func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + b := []byte(v.(string)) + if len(b) == 0 { + return nil, nil + } + m := make(map[string]interface{}) + if err := json.Unmarshal(b, &m); err != nil { + return nil, err + } + return m, nil +} diff --git a/templates/terraform/custom_flatten/healthcare_hl7_v2_store_schema.erb b/templates/terraform/custom_flatten/healthcare_hl7_v2_store_schema.erb new file mode 100644 index 000000000000..ee6080405942 --- /dev/null +++ b/templates/terraform/custom_flatten/healthcare_hl7_v2_store_schema.erb @@ -0,0 +1,25 @@ +<%# The license inside this block applies to this file. + # Copyright 2020 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +-%> +func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return nil + } + b, err := json.Marshal(v) + if err != nil { + // TODO: return error once https://github.com/GoogleCloudPlatform/magic-modules/issues/3257 is fixed. + log.Printf("[ERROR] failed to marshal schema to JSON: %v", err) + } + return string(b) +} 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 c49aba55018e..f80795f46621 100644 --- a/templates/terraform/examples/healthcare_hl7_v2_store_basic.tf.erb +++ b/templates/terraform/examples/healthcare_hl7_v2_store_basic.tf.erb @@ -2,11 +2,6 @@ resource "google_healthcare_hl7_v2_store" "default" { name = "<%= ctx[:vars]['hl7_v2_store_name'] %>" dataset = google_healthcare_dataset.dataset.id - parser_config { - allow_null_header = false - segment_terminator = "Jw==" - } - notification_config { pubsub_topic = google_pubsub_topic.topic.id } @@ -14,6 +9,7 @@ resource "google_healthcare_hl7_v2_store" "default" { labels = { label1 = "labelvalue1" } + provider = google-beta } diff --git a/templates/terraform/examples/healthcare_hl7_v2_store_parser_config.tf.erb b/templates/terraform/examples/healthcare_hl7_v2_store_parser_config.tf.erb new file mode 100644 index 000000000000..04f73fb405ae --- /dev/null +++ b/templates/terraform/examples/healthcare_hl7_v2_store_parser_config.tf.erb @@ -0,0 +1,96 @@ +resource "google_healthcare_hl7_v2_store" "default" { + provider = google-beta + name = "<%= ctx[:vars]['hl7_v2_store_name'] %>" + dataset = google_healthcare_dataset.dataset.id + + parser_config { + allow_null_header = false + segment_terminator = "Jw==" + schema = <