From bf01887ba355f26886748da31415050dcd7d24bb Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Sun, 11 Nov 2018 10:30:51 -0800 Subject: [PATCH 1/3] New Resource: Stackdiver Notification Channel --- products/monitoring/api.yaml | 78 ++++++++++++++++++++++++++++++ products/monitoring/terraform.yaml | 7 +++ 2 files changed, 85 insertions(+) diff --git a/products/monitoring/api.yaml b/products/monitoring/api.yaml index e2a59b286253..abebe1aa31eb 100644 --- a/products/monitoring/api.yaml +++ b/products/monitoring/api.yaml @@ -774,3 +774,81 @@ objects: description: | The filter used to determine which monitored resources belong to this group. + + + - !ruby/object:Api::Resource + name: NotificationChannel + base_url: projects/{{project}}/notificationChannels + self_link: "{{name}}" + update_verb: :PATCH + description: | + A NotificationChannel is a medium through which an alert is delivered + when a policy violation is detected. Examples of channels include email, SMS, + and third-party messaging applications. Fields containing sensitive information + like authentication tokens or contact info are only partially populated on retrieval. + properties: + - !ruby/object:Api::Type::KeyValuePairs + name: labels + description: Configuration fields that define the channel and its behavior. The + permissible and required labels are specified in the NotificationChannelDescriptor.labels + of the NotificationChannelDescriptor corresponding to the type field. + - !ruby/object:Api::Type::String + name: name + description: | + The full REST resource name for this channel. The syntax is: + projects/[PROJECT_ID]/notificationChannels/[CHANNEL_ID] + The [CHANNEL_ID] is automatically assigned by the server on creation. + output: true + - !ruby/object:Api::Type::Enum + name: verificationStatus + description: Indicates whether this channel has been verified or not. On a ListNotificationChannels + or GetNotificationChannel operation, this field is expected to be populated.If + the value is UNVERIFIED, then it indicates that the channel is non-functioning + (it both requires verification and lacks verification); otherwise, it is assumed + that the channel works.If the channel is neither VERIFIED nor UNVERIFIED, it + implies that the channel is of a type that does not require verification or + that this specific channel has been exempted from verification because it was + created prior to verification being required for channels of this type.This + field cannot be modified using a standard UpdateNotificationChannel operation. + To change the value of this field, you must call VerifyNotificationChannel. + # output: true + values: + - :VERIFICATION_STATUS_UNSPECIFIED + - :UNVERIFIED + - :VERIFIED + - !ruby/object:Api::Type::String + name: type + required: true + # TODO enum? + description: The type of the notification channel. This field matches the value + of the NotificationChannelDescriptor.type field. + - !ruby/object:Api::Type::KeyValuePairs + name: userLabels + description: User-supplied key/value data that does not need to conform to the + corresponding NotificationChannelDescriptor's schema, unlike the labels field. + This field is intended to be used for organizing and identifying the NotificationChannel + objects.The field can contain up to 64 entries. Each key and value is limited + to 63 Unicode characters or 128 bytes, whichever is smaller. Labels and values + can contain only lowercase letters, numerals, underscores, and dashes. Keys + must begin with a letter. + - !ruby/object:Api::Type::String + name: description + description: An optional human-readable description of this notification channel. + This description may provide additional details, beyond the display name, for + the channel. This may not exceeed 1024 Unicode characters. + - !ruby/object:Api::Type::String + name: displayName + required: true + description: An optional human-readable name for this notification channel. It + is recommended that you specify a non-empty and unique name in order to make + it easier to identify the channels in your project, though this is not enforced. + The display name is limited to 512 Unicode characters. + - !ruby/object:Api::Type::Boolean + name: enabled + default_value: true + description: Whether notifications are forwarded to the described channel. This + makes it possible to disable delivery of notifications to a particular channel + without removing the channel from all alerting policies that reference the channel. + This is a more convenient approach when the change is temporary and you want + to receive notifications from the same set of alerting policies on the channel + at some point in the future. \ No newline at end of file diff --git a/products/monitoring/terraform.yaml b/products/monitoring/terraform.yaml index eafd2bd95343..654ea7da5f8d 100644 --- a/products/monitoring/terraform.yaml +++ b/products/monitoring/terraform.yaml @@ -84,6 +84,13 @@ overrides: !ruby/object:Provider::ResourceOverrides custom_code: !ruby/object:Provider::Terraform::CustomCode post_create: templates/terraform/post_create/group.erb + NotificationChannel: !ruby/object:Provider::Terraform::ResourceOverride + id_format: "{{name}}" + import_format: ["{{name}}"] + custom_code: !ruby/object:Provider::Terraform::CustomCode + custom_import: templates/terraform/custom_import/self_link_as_name.erb + post_create: templates/terraform/post_create/set_computed_name.erb + files: !ruby/object:Provider::Config::Files # These files have templating (ERB) code that will be run. # This is usually to add licensing info, autogeneration notices, etc. From 18f8ff0699f7817d3609a0716876438d0e423561 Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Mon, 12 Nov 2018 11:22:31 -0800 Subject: [PATCH 2/3] Add notification channel test --- products/monitoring/api.yaml | 7 ++++--- products/monitoring/terraform.yaml | 7 +++++++ .../terraform/examples/notification_channel_basic.tf.erb | 7 +++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 templates/terraform/examples/notification_channel_basic.tf.erb diff --git a/products/monitoring/api.yaml b/products/monitoring/api.yaml index abebe1aa31eb..f0d3decbff4e 100644 --- a/products/monitoring/api.yaml +++ b/products/monitoring/api.yaml @@ -811,7 +811,7 @@ objects: created prior to verification being required for channels of this type.This field cannot be modified using a standard UpdateNotificationChannel operation. To change the value of this field, you must call VerifyNotificationChannel. - # output: true + output: true values: - :VERIFICATION_STATUS_UNSPECIFIED - :UNVERIFIED @@ -819,9 +819,10 @@ objects: - !ruby/object:Api::Type::String name: type required: true - # TODO enum? description: The type of the notification channel. This field matches the value - of the NotificationChannelDescriptor.type field. + of the NotificationChannelDescriptor.type field. See + https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.notificationChannelDescriptors/list + to get the list of valid values such as "email", "slack", etc... - !ruby/object:Api::Type::KeyValuePairs name: userLabels description: User-supplied key/value data that does not need to conform to the diff --git a/products/monitoring/terraform.yaml b/products/monitoring/terraform.yaml index 654ea7da5f8d..43031fb84dcc 100644 --- a/products/monitoring/terraform.yaml +++ b/products/monitoring/terraform.yaml @@ -87,6 +87,13 @@ overrides: !ruby/object:Provider::ResourceOverrides NotificationChannel: !ruby/object:Provider::Terraform::ResourceOverride id_format: "{{name}}" import_format: ["{{name}}"] + mutex: stackdriver/notifications/{{project}} + example: + - !ruby/object:Provider::Terraform::Examples + name: "notification_channel_basic" + primary_resource_id: "basic" + vars: + display_name: "Test Notification Channel" custom_code: !ruby/object:Provider::Terraform::CustomCode custom_import: templates/terraform/custom_import/self_link_as_name.erb post_create: templates/terraform/post_create/set_computed_name.erb diff --git a/templates/terraform/examples/notification_channel_basic.tf.erb b/templates/terraform/examples/notification_channel_basic.tf.erb new file mode 100644 index 000000000000..421e3acef35d --- /dev/null +++ b/templates/terraform/examples/notification_channel_basic.tf.erb @@ -0,0 +1,7 @@ +resource "google_monitoring_notification_channel" "<%= ctx[:primary_resource_id] %>" { + display_name = "<%= ctx[:vars]["display_name"] %>" + type = "email" + labels = { + email_address = "fake_email@blahblah.com" + } +} \ No newline at end of file From 35fbc2e12c29e795f4691fde85892f78d21be607 Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Tue, 13 Nov 2018 08:28:37 -0800 Subject: [PATCH 3/3] Add update integration test --- ...ce_monitoring_notification_channel_test.go | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 third_party/terraform/tests/resource_monitoring_notification_channel_test.go diff --git a/third_party/terraform/tests/resource_monitoring_notification_channel_test.go b/third_party/terraform/tests/resource_monitoring_notification_channel_test.go new file mode 100644 index 000000000000..3d26c8cb7aff --- /dev/null +++ b/third_party/terraform/tests/resource_monitoring_notification_channel_test.go @@ -0,0 +1,49 @@ +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccMonitoringNotificationChannel_update(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMonitoringNotificationChannelDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMonitoringNotificationChannel_update("email", `email_address = "fake_email@blahblah.com"`), + }, + { + ResourceName: "google_monitoring_notification_channel.update", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccMonitoringNotificationChannel_update("sms", `number = "+15555379009"`), + }, + { + ResourceName: "google_monitoring_notification_channel.update", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccMonitoringNotificationChannel_update(channel, labels string) string { + return fmt.Sprintf(` +resource "google_monitoring_notification_channel" "update" { + display_name = "IntTest Notification Channel" + type = "%s" + labels = { + %s + } +} +`, channel, labels, + ) +}