Skip to content

Commit

Permalink
add version field for unschematized hl7 stores (#3983) (#2516)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Sep 25, 2020
1 parent 4384851 commit d218cec
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/3983.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
healthcare: Added field `parser_config.version` to `google_healthcare_hl7_v2_store`
```
27 changes: 26 additions & 1 deletion google-beta/resource_healthcare_hl7_v2_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Fields/functions available for filtering are:
StateFunc: func(v interface{}) string { s, _ := structure.NormalizeJsonString(v); return s },
Description: `JSON encoded string for schemas used to parse messages in this
store if schematized parsing is desired.`,
AtLeastOneOf: []string{"parser_config.0.allow_null_header", "parser_config.0.segment_terminator", "parser_config.0.schema"},
AtLeastOneOf: []string{"parser_config.0.allow_null_header", "parser_config.0.segment_terminator", "parser_config.0.schema", "parser_config.0.version"},
},
"segment_terminator": {
Type: schema.TypeString,
Expand All @@ -167,6 +167,14 @@ store if schematized parsing is desired.`,
A base64-encoded string.`,
AtLeastOneOf: []string{"parser_config.0.allow_null_header", "parser_config.0.segment_terminator", "parser_config.0.schema"},
},
"version": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"V1", "V2", ""}, false),
Description: `The version of the unschematized parser to be used when a custom 'schema' is not set. Default value: "V1" Possible values: ["V1", "V2"]`,
Default: "V1",
},
},
},
},
Expand Down Expand Up @@ -469,6 +477,8 @@ func flattenHealthcareHl7V2StoreParserConfig(v interface{}, d *schema.ResourceDa
flattenHealthcareHl7V2StoreParserConfigSegmentTerminator(original["segmentTerminator"], d, config)
transformed["schema"] =
flattenHealthcareHl7V2StoreParserConfigSchema(original["schema"], d, config)
transformed["version"] =
flattenHealthcareHl7V2StoreParserConfigVersion(original["version"], d, config)
return []interface{}{transformed}
}
func flattenHealthcareHl7V2StoreParserConfigAllowNullHeader(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand All @@ -491,6 +501,10 @@ func flattenHealthcareHl7V2StoreParserConfigSchema(v interface{}, d *schema.Reso
return string(b)
}

func flattenHealthcareHl7V2StoreParserConfigVersion(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenHealthcareHl7V2StoreLabels(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}
Expand Down Expand Up @@ -573,6 +587,13 @@ func expandHealthcareHl7V2StoreParserConfig(v interface{}, d TerraformResourceDa
transformed["schema"] = transformedSchema
}

transformedVersion, err := expandHealthcareHl7V2StoreParserConfigVersion(original["version"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedVersion); val.IsValid() && !isEmptyValue(val) {
transformed["version"] = transformedVersion
}

return transformed, nil
}

Expand All @@ -596,6 +617,10 @@ func expandHealthcareHl7V2StoreParserConfigSchema(v interface{}, d TerraformReso
return m, nil
}

func expandHealthcareHl7V2StoreParserConfigVersion(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandHealthcareHl7V2StoreLabels(v interface{}, d TerraformResourceData, config *Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
Expand Down
50 changes: 47 additions & 3 deletions google-beta/resource_healthcare_hl7_v2_store_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestAccHealthcareHl7V2Store_healthcareHl7V2StoreBasicExample(t *testing.T)
Config: testAccHealthcareHl7V2Store_healthcareHl7V2StoreBasicExample(context),
},
{
ResourceName: "google_healthcare_hl7_v2_store.default",
ResourceName: "google_healthcare_hl7_v2_store.store",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"self_link", "dataset"},
Expand All @@ -53,7 +53,7 @@ func TestAccHealthcareHl7V2Store_healthcareHl7V2StoreBasicExample(t *testing.T)

func testAccHealthcareHl7V2Store_healthcareHl7V2StoreBasicExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_healthcare_hl7_v2_store" "default" {
resource "google_healthcare_hl7_v2_store" "store" {
name = "tf-test-example-hl7-v2-store%{random_suffix}"
dataset = google_healthcare_dataset.dataset.id
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestAccHealthcareHl7V2Store_healthcareHl7V2StoreParserConfigExample(t *test

func testAccHealthcareHl7V2Store_healthcareHl7V2StoreParserConfigExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_healthcare_hl7_v2_store" "default" {
resource "google_healthcare_hl7_v2_store" "store" {
provider = google-beta
name = "tf-test-example-hl7-v2-store%{random_suffix}"
dataset = google_healthcare_dataset.dataset.id
Expand Down Expand Up @@ -200,6 +200,50 @@ resource "google_healthcare_dataset" "dataset" {
`, context)
}

func TestAccHealthcareHl7V2Store_healthcareHl7V2StoreUnschematizedExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersOiCS,
ExternalProviders: map[string]resource.ExternalProvider{
"random": {},
},
CheckDestroy: testAccCheckHealthcareHl7V2StoreDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccHealthcareHl7V2Store_healthcareHl7V2StoreUnschematizedExample(context),
},
},
})
}

func testAccHealthcareHl7V2Store_healthcareHl7V2StoreUnschematizedExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_healthcare_hl7_v2_store" "store" {
provider = google-beta
name = "tf-test-example-hl7-v2-store%{random_suffix}"
dataset = google_healthcare_dataset.dataset.id
parser_config {
allow_null_header = false
segment_terminator = "Jw=="
version = "V2"
}
}
resource "google_healthcare_dataset" "dataset" {
provider = google-beta
name = "tf-test-example-dataset%{random_suffix}"
location = "us-central1"
}
`, context)
}

func testAccCheckHealthcareHl7V2StoreDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
37 changes: 35 additions & 2 deletions website/docs/r/healthcare_hl7_v2_store.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ To get more information about Hl7V2Store, see:


```hcl
resource "google_healthcare_hl7_v2_store" "default" {
resource "google_healthcare_hl7_v2_store" "store" {
name = "example-hl7-v2-store"
dataset = google_healthcare_dataset.dataset.id
Expand Down Expand Up @@ -72,7 +72,7 @@ resource "google_healthcare_dataset" "dataset" {


```hcl
resource "google_healthcare_hl7_v2_store" "default" {
resource "google_healthcare_hl7_v2_store" "store" {
provider = google-beta
name = "example-hl7-v2-store"
dataset = google_healthcare_dataset.dataset.id
Expand Down Expand Up @@ -163,6 +163,33 @@ EOF
}
}
resource "google_healthcare_dataset" "dataset" {
provider = google-beta
name = "example-dataset"
location = "us-central1"
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgit.luolix.top%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=healthcare_hl7_v2_store_unschematized&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Healthcare Hl7 V2 Store Unschematized


```hcl
resource "google_healthcare_hl7_v2_store" "store" {
provider = google-beta
name = "example-hl7-v2-store"
dataset = google_healthcare_dataset.dataset.id
parser_config {
allow_null_header = false
segment_terminator = "Jw=="
version = "V2"
}
}
resource "google_healthcare_dataset" "dataset" {
provider = google-beta
name = "example-dataset"
Expand Down Expand Up @@ -234,6 +261,12 @@ The `parser_config` block supports:
JSON encoded string for schemas used to parse messages in this
store if schematized parsing is desired.

* `version` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
The version of the unschematized parser to be used when a custom `schema` is not set.
Default value is `V1`.
Possible values are `V1` and `V2`.

The `notification_configs` block supports:

* `pubsub_topic` -
Expand Down

0 comments on commit d218cec

Please sign in to comment.