Skip to content

Commit

Permalink
Merge 35fbc2e into d93b98e
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisst authored Nov 13, 2018
2 parents d93b98e + 35fbc2e commit 9169b65
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 0 deletions.
79 changes: 79 additions & 0 deletions products/monitoring/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -774,3 +774,82 @@ 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
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.
14 changes: 14 additions & 0 deletions products/monitoring/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ 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}}"]
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

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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "google_monitoring_notification_channel" "<%= ctx[:primary_resource_id] %>" {
display_name = "<%= ctx[:vars]["display_name"] %>"
type = "email"
labels = {
email_address = "[email protected]"
}
}
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"`),
},
{
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,
)
}

0 comments on commit 9169b65

Please sign in to comment.