Skip to content

Commit 0617752

Browse files
google_logging_metric: add disabled argument (#7600) (#14198)
Signed-off-by: Modular Magician <[email protected]>
1 parent 0b5436e commit 0617752

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

.changelog/7600.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
logging: added support for `disabled` to `google_logging_metric`
3+
```

google/resource_logging_metric.go

+28
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ Each bucket represents a constant absolute uncertainty on the specific value in
158158
Description: `A description of this metric, which is used in documentation. The maximum length of the
159159
description is 8000 characters.`,
160160
},
161+
"disabled": {
162+
Type: schema.TypeBool,
163+
Optional: true,
164+
Description: `If set to True, then this metric is disabled and it does not generate any points.`,
165+
},
161166
"label_extractors": {
162167
Type: schema.TypeMap,
163168
Optional: true,
@@ -296,6 +301,12 @@ func resourceLoggingMetricCreate(d *schema.ResourceData, meta interface{}) error
296301
} else if v, ok := d.GetOkExists("bucket_name"); !isEmptyValue(reflect.ValueOf(bucketNameProp)) && (ok || !reflect.DeepEqual(v, bucketNameProp)) {
297302
obj["bucketName"] = bucketNameProp
298303
}
304+
disabledProp, err := expandLoggingMetricDisabled(d.Get("disabled"), d, config)
305+
if err != nil {
306+
return err
307+
} else if v, ok := d.GetOkExists("disabled"); !isEmptyValue(reflect.ValueOf(disabledProp)) && (ok || !reflect.DeepEqual(v, disabledProp)) {
308+
obj["disabled"] = disabledProp
309+
}
299310
filterProp, err := expandLoggingMetricFilter(d.Get("filter"), d, config)
300311
if err != nil {
301312
return err
@@ -431,6 +442,9 @@ func resourceLoggingMetricRead(d *schema.ResourceData, meta interface{}) error {
431442
if err := d.Set("bucket_name", flattenLoggingMetricBucketName(res["bucketName"], d, config)); err != nil {
432443
return fmt.Errorf("Error reading Metric: %s", err)
433444
}
445+
if err := d.Set("disabled", flattenLoggingMetricDisabled(res["disabled"], d, config)); err != nil {
446+
return fmt.Errorf("Error reading Metric: %s", err)
447+
}
434448
if err := d.Set("filter", flattenLoggingMetricFilter(res["filter"], d, config)); err != nil {
435449
return fmt.Errorf("Error reading Metric: %s", err)
436450
}
@@ -484,6 +498,12 @@ func resourceLoggingMetricUpdate(d *schema.ResourceData, meta interface{}) error
484498
} else if v, ok := d.GetOkExists("bucket_name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, bucketNameProp)) {
485499
obj["bucketName"] = bucketNameProp
486500
}
501+
disabledProp, err := expandLoggingMetricDisabled(d.Get("disabled"), d, config)
502+
if err != nil {
503+
return err
504+
} else if v, ok := d.GetOkExists("disabled"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, disabledProp)) {
505+
obj["disabled"] = disabledProp
506+
}
487507
filterProp, err := expandLoggingMetricFilter(d.Get("filter"), d, config)
488508
if err != nil {
489509
return err
@@ -613,6 +633,10 @@ func flattenLoggingMetricBucketName(v interface{}, d *schema.ResourceData, confi
613633
return v
614634
}
615635

636+
func flattenLoggingMetricDisabled(v interface{}, d *schema.ResourceData, config *Config) interface{} {
637+
return v
638+
}
639+
616640
func flattenLoggingMetricFilter(v interface{}, d *schema.ResourceData, config *Config) interface{} {
617641
return v
618642
}
@@ -828,6 +852,10 @@ func expandLoggingMetricBucketName(v interface{}, d TerraformResourceData, confi
828852
return v, nil
829853
}
830854

855+
func expandLoggingMetricDisabled(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
856+
return v, nil
857+
}
858+
831859
func expandLoggingMetricFilter(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
832860
return v, nil
833861
}

google/resource_logging_metric_generated_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,44 @@ resource "google_logging_metric" "logging_metric" {
207207
`, context)
208208
}
209209

210+
func TestAccLoggingMetric_loggingMetricDisabledExample(t *testing.T) {
211+
t.Parallel()
212+
213+
context := map[string]interface{}{
214+
"random_suffix": RandString(t, 10),
215+
}
216+
217+
VcrTest(t, resource.TestCase{
218+
PreCheck: func() { testAccPreCheck(t) },
219+
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
220+
CheckDestroy: testAccCheckLoggingMetricDestroyProducer(t),
221+
Steps: []resource.TestStep{
222+
{
223+
Config: testAccLoggingMetric_loggingMetricDisabledExample(context),
224+
},
225+
{
226+
ResourceName: "google_logging_metric.logging_metric",
227+
ImportState: true,
228+
ImportStateVerify: true,
229+
},
230+
},
231+
})
232+
}
233+
234+
func testAccLoggingMetric_loggingMetricDisabledExample(context map[string]interface{}) string {
235+
return Nprintf(`
236+
resource "google_logging_metric" "logging_metric" {
237+
name = "tf-test-my-(custom)/metric%{random_suffix}"
238+
filter = "resource.type=gae_app AND severity>=ERROR"
239+
metric_descriptor {
240+
metric_kind = "DELTA"
241+
value_type = "INT64"
242+
}
243+
disabled = true
244+
}
245+
`, context)
246+
}
247+
210248
func testAccCheckLoggingMetricDestroyProducer(t *testing.T) func(s *terraform.State) error {
211249
return func(s *terraform.State) error {
212250
for name, rs := range s.RootModule().Resources {

website/docs/r/logging_metric.html.markdown

+23
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,25 @@ resource "google_logging_metric" "logging_metric" {
133133
bucket_name = google_logging_project_bucket_config.logging_metric.id
134134
}
135135
```
136+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
137+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=logging_metric_disabled&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
138+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
139+
</a>
140+
</div>
141+
## Example Usage - Logging Metric Disabled
142+
143+
144+
```hcl
145+
resource "google_logging_metric" "logging_metric" {
146+
name = "my-(custom)/metric"
147+
filter = "resource.type=gae_app AND severity>=ERROR"
148+
metric_descriptor {
149+
metric_kind = "DELTA"
150+
value_type = "INT64"
151+
}
152+
disabled = true
153+
}
154+
```
136155

137156
## Argument Reference
138157

@@ -166,6 +185,10 @@ The following arguments are supported:
166185
The resource name of the Log Bucket that owns the Log Metric. Only Log Buckets in projects
167186
are supported. The bucket has to be in the same project as the metric.
168187

188+
* `disabled` -
189+
(Optional)
190+
If set to True, then this metric is disabled and it does not generate any points.
191+
169192
* `metric_descriptor` -
170193
(Optional)
171194
The optional metric descriptor associated with the logs-based metric.

0 commit comments

Comments
 (0)