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 diff --git a/products/monitoring/api.yaml b/products/monitoring/api.yaml index d92c8ba195a8..88fb5146c17b 100644 --- a/products/monitoring/api.yaml +++ b/products/monitoring/api.yaml @@ -772,3 +772,87 @@ 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. + 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 + 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 + description: The type of the notification channel. This field matches the value + 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 + 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..a2682ca88587 100644 --- a/products/monitoring/terraform.yaml +++ b/products/monitoring/terraform.yaml @@ -69,6 +69,21 @@ 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}}"] + mutex: stackdriver/notifications/{{project}} + example: + - !ruby/object:Provider::Terraform::Examples + version: <%= _version_name %> + 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 + 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. 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 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, + ) +}