Skip to content

Commit

Permalink
Add a new resource for creating DataMapper Workspaces (GoogleCloudPla…
Browse files Browse the repository at this point in the history
…tform#11603)

Co-authored-by: Scott Suarez <[email protected]>
  • Loading branch information
2 people authored and iyabchen committed Sep 14, 2024
1 parent 8c0cb37 commit dda847e
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 0 deletions.
73 changes: 73 additions & 0 deletions mmv1/products/healthcare/Workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright 2024 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.

--- !ruby/object:Api::Resource
name: 'Workspace'
description: |
A Data Mapper workspace is used to configure Data Mapper access, permissions and data sources for mapping clinical patient data to the FHIR standard.
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Create and manage Data Mapper workspaces ': 'https://cloud.google.com/healthcare-api/healthcare-data-engine/docs/manage-workspaces'
api: 'https://cloud.google.com/healthcare-api/healthcare-data-engine/docs/reference/rest/v1/projects.locations.datasets.dataMapperWorkspaces'
base_url: '{{dataset}}/dataMapperWorkspaces?workspaceId={{name}}'
self_link: '{{dataset}}/dataMapperWorkspaces/{{name}}'
create_url: '{{dataset}}/dataMapperWorkspaces?workspaceId={{name}}'
update_verb: :PATCH
update_mask: true
id_format: '{{dataset}}/dataMapperWorkspaces/{{name}}'
import_format: ['{{%dataset}}/dataMapperWorkspaces/{{name}}']
skip_sweeper: true
examples:
- !ruby/object:Provider::Terraform::Examples
name: 'healthcare_workspace_basic'
primary_resource_id: 'default'
vars:
dataset_name: 'example-dataset'
workspace_name: 'example-dm-workspace'
source_project_id: 'example-data-source-project-id'
parameters:
- !ruby/object:Api::Type::ResourceRef
name: 'dataset'
description: |
Identifies the dataset addressed by this request. Must be in the format
'projects/{project}/locations/{location}/datasets/{dataset}'
required: true
immutable: true
resource: 'Dataset'
imports: 'selfLink'
url_param_only: true
properties:
- !ruby/object:Api::Type::String
name: 'name'
description: |
The name of the workspace, in the format 'projects/{projectId}/locations/{location}/datasets/{datasetId}/dataMapperWorkspaces/{workspaceId}'
required: true
immutable: true
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
- !ruby/object:Api::Type::NestedObject
name: 'settings'
description: |
Settings associated with this workspace.
required: true
properties:
- !ruby/object:Api::Type::Array
name: 'dataProjectIds'
description: |
Project IDs for data projects hosted in a workspace.
required: true
item_type: Api::Type::String
- !ruby/object:Api::Type::KeyValueLabels
name: 'labels'
description: |
The user labels. An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }
required: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "google_healthcare_workspace" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['workspace_name'] %>"
dataset = google_healthcare_dataset.dataset.id

settings {
data_project_ids = ["<%= ctx[:vars]['source_project_id'] %>"]
}

labels = {
label1 = "labelvalue1"
}
}


resource "google_healthcare_dataset" "dataset" {
name = "<%= ctx[:vars]['dataset_name'] %>"
location = "us-central1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package healthcare_test

import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"

"github.com/hashicorp/terraform-provider-google/google/acctest"
)

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

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

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckHealthcareWorkspaceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccHealthcareWorkspace_basic(context),
},
{
ResourceName: "google_healthcare_workspace.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"dataset", "labels", "terraform_labels"},
},
{
Config: testAccHealthcareWorkspace_update(context),
},
{
ResourceName: "google_healthcare_workspace.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"dataset", "labels", "terraform_labels"},
},
},
})
}

func testAccHealthcareWorkspace_basic(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_healthcare_workspace" "default" {
name = "tf-test-example-dm-workspace%{random_suffix}"
dataset = google_healthcare_dataset.dataset.id
settings {
data_project_ids = ["tf-test-example-data-source-project-id%{random_suffix}"]
}
labels = {
label1 = "labelvalue1"
}
}
resource "google_healthcare_dataset" "dataset" {
name = "tf-test-example-dataset%{random_suffix}"
location = "us-central1"
}
`, context)
}

func testAccHealthcareWorkspace_update(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_healthcare_workspace" "default" {
name = "tf-test-example-dm-workspace%{random_suffix}"
dataset = google_healthcare_dataset.dataset.id
settings {
data_project_ids = ["tf-test-example-data-source-project-id%{random_suffix}"]
}
}
resource "google_healthcare_dataset" "dataset" {
name = "tf-test-example-dataset%{random_suffix}"
location = "us-central1"
}
`, context)
}

0 comments on commit dda847e

Please sign in to comment.