Skip to content

Commit

Permalink
New Resource: Stack Driver Group (#895)
Browse files Browse the repository at this point in the history
Merged PR #895.
  • Loading branch information
chrisst authored and modular-magician committed Nov 13, 2018
1 parent dea946a commit 4585729
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 41 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
8 changes: 3 additions & 5 deletions products/monitoring/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -727,11 +727,9 @@ objects:
- !ruby/object:Api::Resource
name: 'Group'
exclude: true
# TODO - chrisst this resource is tested well enough to be release yet.
base_url: projects/{{project}}/groups
self_link: projects/{{project}}/groups/{{name}}
update_verb: :PATCH
self_link: "{{name}}"
update_verb: :PUT
description: |
The description of a dynamic collection of monitored resources. Each group
has a filter that is matched against monitored resources and their
Expand All @@ -746,7 +744,6 @@ objects:
- !ruby/object:Api::Type::String
name: parentName
# TODO chrisst - turn into self-reference if possible.
# if not, turn into {groupId} and expand
description: |
The name of the group's parent, if it has one. The format is
"projects/{project_id_or_number}/groups/{group_id}". For
Expand All @@ -771,6 +768,7 @@ objects:
purposes.
- !ruby/object:Api::Type::String
name: filter
required: true
description: |
The filter used to determine which monitored resources
belong to this group.
53 changes: 19 additions & 34 deletions products/monitoring/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,49 +40,34 @@ overrides: !ruby/object:Provider::ResourceOverrides
]
}
```
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

Group: !ruby/object:Provider::Terraform::ResourceOverride
id_format: "{{name}}"
examples: |
### Basic Usage
```hcl
resource "google_monitoring_group" "test" {
display_name = "New Group"
filter = "resource.metadata.region=\"europe-west2\""
}
```
### Full Usage
```hcl
resource "google_monitoring_group" "parent_group" {
display_name = "Parent Group"
filter = "resource.metadata.region=\"europe-west2\""
is_cluster = true
}
resource "google_monitoring_group" "child_group" {
display_name = "Child Group"
parent_name = "${google_monitoring_group.parent_group.name}"
filter = "resource.metadata.region=\"europe-west2\""
}
output "parent_group_name" {
value = "${google_monitoring_group.parent_group.name}"
}
```
import_format: ["{{name}}"]
mutex: stackdriver/groups/{{project}}
example:
- !ruby/object:Provider::Terraform::Examples
name: "monitoring_group_basic"
primary_resource_id: "basic"
version: <%= _version_name %>
vars:
display_name: "New Test Group"
- !ruby/object:Provider::Terraform::Examples
name: "monitoring_group_subgroup"
primary_resource_id: "subgroup"
version: <%= _version_name %>
vars:
display_name: "New Test SubGroup"
display_name2: "New Test SubGroup"
properties:
name: !ruby/object:Provider::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/monitoring_group_name.erb'
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
parentName: !ruby/object:Provider::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/monitoring_group_name.erb'
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
diff_suppress_func: 'compareSelfLinkRelativePaths'
custom_code: !ruby/object:Provider::Terraform::CustomCode
post_create: templates/terraform/post_create/group.erb
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.
Expand Down
5 changes: 5 additions & 0 deletions templates/terraform/examples/monitoring_group_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "google_monitoring_group" "<%= ctx[:primary_resource_id] %>" {
display_name = "<%= ctx[:vars]["display_name"] %>"

filter = "resource.metadata.region=\"europe-west2\""
}
10 changes: 10 additions & 0 deletions templates/terraform/examples/monitoring_group_subgroup.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "google_monitoring_group" "parent" {
display_name = "<%= ctx[:vars]["display_name"] %>"
filter = "resource.metadata.region=\"europe-west2\""
}

resource "google_monitoring_group" "<%= ctx[:primary_resource_id] %>" {
display_name = "<%= ctx[:vars]["display_name"] %>"
filter = "resource.metadata.region=\"europe-west2\""
parent_name = "${google_monitoring_group.parent.name}"
}
47 changes: 47 additions & 0 deletions third_party/terraform/tests/resource_monitoring_group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/resource"
)

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

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckMonitoringGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccMonitoringGroup_update("europe-west1"),
},
{
ResourceName: "google_monitoring_group.update",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccMonitoringGroup_update("europe-west2"),
},
{
ResourceName: "google_monitoring_group.update",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccMonitoringGroup_update(zone string) string {
return fmt.Sprintf(`
resource "google_monitoring_group" "update" {
display_name = "Integration Test Group"
filter = "resource.metadata.region=\"%s\""
}
`, zone,
)
}

0 comments on commit 4585729

Please sign in to comment.