From 6baaa6a504e8888f021f6866fafa379da02d63f0 Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Sun, 11 Nov 2018 10:30:51 -0800 Subject: [PATCH 1/6] 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 d92c8ba195a8..eee35f324b44 100644 --- a/products/monitoring/api.yaml +++ b/products/monitoring/api.yaml @@ -772,3 +772,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 23993c030235..7e1fe7833057 100644 --- a/products/monitoring/terraform.yaml +++ b/products/monitoring/terraform.yaml @@ -69,6 +69,13 @@ overrides: !ruby/object:Provider::ResourceOverrides custom_import: templates/terraform/custom_import/self_link_as_name.erb post_create: templates/terraform/post_create/set_computed_name.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 b3931849a4b0114b4624f7f925aedec8f603f67e Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Mon, 12 Nov 2018 11:22:31 -0800 Subject: [PATCH 2/6] 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 eee35f324b44..eeb4448b8af9 100644 --- a/products/monitoring/api.yaml +++ b/products/monitoring/api.yaml @@ -809,7 +809,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 @@ -817,9 +817,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 7e1fe7833057..a2b977367b46 100644 --- a/products/monitoring/terraform.yaml +++ b/products/monitoring/terraform.yaml @@ -72,6 +72,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 a2e50e8c0859bb200eb9b5ad03474f4ce1c84a8c Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Tue, 13 Nov 2018 08:28:37 -0800 Subject: [PATCH 3/6] 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, + ) +} From 2446ff0e722d963bd5cab51e6d73336367207623 Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Tue, 13 Nov 2018 13:27:31 -0800 Subject: [PATCH 4/6] adding versions to examples --- products/monitoring/terraform.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/products/monitoring/terraform.yaml b/products/monitoring/terraform.yaml index a2b977367b46..a2682ca88587 100644 --- a/products/monitoring/terraform.yaml +++ b/products/monitoring/terraform.yaml @@ -75,6 +75,7 @@ overrides: !ruby/object:Provider::ResourceOverrides mutex: stackdriver/notifications/{{project}} example: - !ruby/object:Provider::Terraform::Examples + version: <%= _version_name %> name: "notification_channel_basic" primary_resource_id: "basic" vars: From 53df41d536b70ff550ea625a3ab69697fdecda8d Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Tue, 13 Nov 2018 14:00:04 -0800 Subject: [PATCH 5/6] Adding docs to notification channel --- products/monitoring/api.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/products/monitoring/api.yaml b/products/monitoring/api.yaml index eeb4448b8af9..88fb5146c17b 100644 --- a/products/monitoring/api.yaml +++ b/products/monitoring/api.yaml @@ -784,6 +784,11 @@ objects: 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. + references: !ruby/object:Api::Resource::ReferenceLinks + guides: + 'Official Documentation': + 'https://cloud.google.com/monitoring/api/v3/' + api: 'https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.notificationChannels' properties: - !ruby/object:Api::Type::KeyValuePairs name: labels From 2fa96e9d67e2d6f2753b31513fc9ce10e31745d5 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Tue, 13 Nov 2018 23:30:39 +0000 Subject: [PATCH 6/6] Update tracked submodules -> HEAD on Tue Nov 13 23:30:39 UTC 2018 Tracked submodules are build/terraform-beta build/terraform build/ansible build/inspec. --- build/terraform | 2 +- build/terraform-beta | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/terraform b/build/terraform index 4f425a8aef40..a15a66a42809 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 4f425a8aef406142cc6ae2a801b5f885beecc98a +Subproject commit a15a66a428099817aa28196bf0ebe20ae5b08898 diff --git a/build/terraform-beta b/build/terraform-beta index f11572f1d47c..4e2f9c529fc9 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit f11572f1d47ceaa8601f769a38986b6569ddc25e +Subproject commit 4e2f9c529fc9869fa1936f95ef34391b80318531