Skip to content

Commit

Permalink
update explicit buckets name and make item_type of bounds integers (#…
Browse files Browse the repository at this point in the history
…2258)

Merged PR #2258.
  • Loading branch information
megan07 authored and modular-magician committed Sep 3, 2019
1 parent 2598fff commit 6b16452
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 6 deletions.
7 changes: 7 additions & 0 deletions api/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ def nested_properties

super
end

def item_type_class
return @item_type \
if @item_type.class == Class

Object.const_get(@item_type)
end
end

# Represents an enum, and store is valid values
Expand Down
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
2 changes: 1 addition & 1 deletion build/terraform-mapper
4 changes: 2 additions & 2 deletions products/logging/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ objects:
description: |
Must be greater than 0.
- !ruby/object:Api::Type::NestedObject
name: explicit
name: explicitBuckets
description: |
Specifies a set of buckets with arbitrary widths.
properties:
- !ruby/object:Api::Type::Array
name: bounds
item_type: Api::Type::String
item_type: Api::Type::Double
description: |
The values must be monotonically increasing.
- !ruby/object:Api::Resource
Expand Down
2 changes: 1 addition & 1 deletion templates/terraform/schema_property.erb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<% end -%>
<% elsif property.item_type.is_a?(String) # Basic type like Api::Type::String -%>
Elem: &schema.Schema{
Type: <%= tf_types[property.item_type] -%>,
Type: <%= tf_types[property.item_type_class] -%>,
},
<% else # array of basic types -%>
Elem: &schema.Schema{
Expand Down
44 changes: 44 additions & 0 deletions third_party/terraform/tests/resource_logging_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ func TestAccLoggingMetric_update(t *testing.T) {
})
}

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

suffix := acctest.RandString(10)
filter := "resource.type=gae_app AND severity>=ERROR"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLoggingMetricDestroy,
Steps: []resource.TestStep{
{
Config: testAccLoggingMetric_explicitBucket(suffix, filter),
},
{
ResourceName: "google_logging_metric.logging_metric",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccLoggingMetric_update(suffix string, filter string) string {
return fmt.Sprintf(`
resource "google_logging_metric" "logging_metric" {
Expand All @@ -51,3 +74,24 @@ resource "google_logging_metric" "logging_metric" {
}
}`, suffix, filter)
}

func testAccLoggingMetric_explicitBucket(suffix string, filter string) string {
return fmt.Sprintf(`
resource "google_logging_metric" "logging_metric" {
name = "my-custom-metric-%s"
filter = "%s"
metric_descriptor {
metric_kind = "DELTA"
value_type = "DISTRIBUTION"
}
value_extractor = "EXTRACT(jsonPayload.metrics.running_jobs)"
bucket_options {
explicit_buckets {
bounds = [0,1,2,3,4.2]
}
}
}`, suffix, filter)
}

0 comments on commit 6b16452

Please sign in to comment.