Skip to content

Commit

Permalink
Add support for healthcare fhir new notifications config
Browse files Browse the repository at this point in the history
  • Loading branch information
joycezhou47 committed Sep 9, 2022
2 parents 717d5d6 + 1e8f2d1 commit 27174ea
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,24 @@ resource "google_healthcare_fhir_store" "default" {
}

notification_configs {
pubsub_topic = google_pubsub_topic.topic.name
pubsub_topic = "${google_pubsub_topic.topic.id}"
send_full_resource = true
}
depends_on = [google_pubsub_topic_iam_binding.binding]
}

// Enable notifications by giving the correct IAM permission to the unique service account.
data "google_healthcare_project_service_account" "gcs_account" {
}

// Create a Pub/Sub topic.
resource "google_pubsub_topic_iam_binding" "binding" {
topic = google_pubsub_topic.topic.id
role = "roles/pubsub.publisher"
members = ["serviceAccount:${data.google_healthcare_project_service_account.gcs_account.email_address}"]
}


resource "google_pubsub_topic" "topic" {
name = "<%= ctx[:vars]['pubsub_topic']%>"
}
Expand All @@ -26,3 +39,5 @@ 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,62 @@
package google

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceGoogleHealthcareProjectServiceAccount() *schema.Resource {
return &schema.Resource{
Read: dataSourceGoogleHealthcareProjectServiceAccountRead,
Schema: map[string]*schema.Schema{
"project": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
},
"user_project": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"email_address": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceGoogleHealthcareProjectServiceAccountRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
userAgent, err := generateUserAgentString(d, config.userAgent)
if err != nil {
return err
}

project, err := getProject(d, config)
if err != nil {
return err
}

rmProject, err := config.NewResourceManagerClient(userAgent).Projects.Get(project).Do()
if err != nil {
return handleNotFoundError(err, d, "Project not found")
}
projectNumber := rmProject.ProjectNumber

serviceAccountEmail := fmt.Sprintf("service-%[email protected]", projectNumber)

if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error setting project: %s", err)
}
if err := d.Set("email_address", serviceAccountEmail); err != nil {
return fmt.Errorf("Error setting email_address: %s", err)
}

d.SetId(serviceAccountEmail)

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package google

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

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

resourceName := "data.google_healthcare_project_service_account.gcs_account"

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckGoogleHealthcareProjectServiceAccount_basic,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "email_address"),
),
},
},
})
}

const testAccCheckGoogleHealthcareProjectServiceAccount_basic = `
data "google_healthcare_project_service_account" "gcs_account" {
}
`
1 change: 1 addition & 0 deletions mmv1/third_party/terraform/utils/provider.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ func Provider() *schema.Provider {
"google_folder": dataSourceGoogleFolder(),
"google_folders": dataSourceGoogleFolders(),
"google_folder_organization_policy": dataSourceGoogleFolderOrganizationPolicy(),
"google_healthcare_project_service_account": dataSourceGoogleHealthcareProjectServiceAccount(),
"google_monitoring_notification_channel": dataSourceMonitoringNotificationChannel(),
"google_monitoring_cluster_istio_service": dataSourceMonitoringServiceClusterIstio(),
"google_monitoring_istio_canonical_service": dataSourceMonitoringIstioCanonicalService(),
Expand Down

0 comments on commit 27174ea

Please sign in to comment.