Skip to content

Commit

Permalink
Added Subject Field to Alert Policy Monitoring Resource (#9360) (#16414)
Browse files Browse the repository at this point in the history
* Added Alert Policy resource field for subject line.

* Added test for Alert Policy field.

* Included subject in one_of lists.

* Included subject in one_of lists.
[upstream:42f1940aece6274d74cafd6b25558a824fecf709]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Oct 31, 2023
1 parent 2445abc commit 8732919
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/9360.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
monitoring: added `subject` field to `google_monitoring_alert_policy` resource
```
30 changes: 28 additions & 2 deletions google/services/monitoring/resource_monitoring_alert_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,15 +918,24 @@ limited capacity might not show this documentation.`,
The content may not exceed 8,192 Unicode characters and may not
exceed more than 10,240 bytes when encoded in UTF-8 format,
whichever is smaller.`,
AtLeastOneOf: []string{"documentation.0.content", "documentation.0.mime_type"},
AtLeastOneOf: []string{"documentation.0.content", "documentation.0.mime_type", "documentation.0.subject"},
},
"mime_type": {
Type: schema.TypeString,
Optional: true,
Description: `The format of the content field. Presently, only the value
"text/markdown" is supported.`,
Default: "text/markdown",
AtLeastOneOf: []string{"documentation.0.content", "documentation.0.mime_type"},
AtLeastOneOf: []string{"documentation.0.content", "documentation.0.mime_type", "documentation.0.subject"},
},
"subject": {
Type: schema.TypeString,
Optional: true,
Description: `The subject line of the notification. The subject line may not
exceed 10,240 bytes. In notifications generated by this policy the contents
of the subject line after variable expansion will be truncated to 255 bytes
or shorter at the latest UTF-8 character boundary.`,
AtLeastOneOf: []string{"documentation.0.content", "documentation.0.mime_type", "documentation.0.subject"},
},
},
},
Expand Down Expand Up @@ -1996,6 +2005,8 @@ func flattenMonitoringAlertPolicyDocumentation(v interface{}, d *schema.Resource
flattenMonitoringAlertPolicyDocumentationContent(original["content"], d, config)
transformed["mime_type"] =
flattenMonitoringAlertPolicyDocumentationMimeType(original["mimeType"], d, config)
transformed["subject"] =
flattenMonitoringAlertPolicyDocumentationSubject(original["subject"], d, config)
return []interface{}{transformed}
}
func flattenMonitoringAlertPolicyDocumentationContent(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand All @@ -2006,6 +2017,10 @@ func flattenMonitoringAlertPolicyDocumentationMimeType(v interface{}, d *schema.
return v
}

func flattenMonitoringAlertPolicyDocumentationSubject(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func expandMonitoringAlertPolicyDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -2859,6 +2874,13 @@ func expandMonitoringAlertPolicyDocumentation(v interface{}, d tpgresource.Terra
transformed["mimeType"] = transformedMimeType
}

transformedSubject, err := expandMonitoringAlertPolicyDocumentationSubject(original["subject"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedSubject); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["subject"] = transformedSubject
}

return transformed, nil
}

Expand All @@ -2869,3 +2891,7 @@ func expandMonitoringAlertPolicyDocumentationContent(v interface{}, d tpgresourc
func expandMonitoringAlertPolicyDocumentationMimeType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandMonitoringAlertPolicyDocumentationSubject(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ resource "google_monitoring_alert_policy" "full" {
documentation {
content = "test content"
mime_type = "text/markdown"
subject = "test subject"
}
}
`, alertName, conditionName1, conditionName2)
Expand Down Expand Up @@ -352,6 +353,7 @@ resource "google_monitoring_alert_policy" "mql" {
documentation {
content = "test content"
mime_type = "text/markdown"
subject = "test subject"
}
}
`, alertName, conditionName)
Expand Down Expand Up @@ -385,6 +387,7 @@ resource "google_monitoring_alert_policy" "log" {
documentation {
content = "test content"
mime_type = "text/markdown"
subject = "test subject"
}
}
`, alertName, conditionName)
Expand Down Expand Up @@ -443,6 +446,7 @@ resource "google_monitoring_alert_policy" "promql" {
documentation {
content = "test content"
mime_type = "text/markdown"
subject = "test subject"
}
}
`, alertName, conditionName)
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/monitoring_alert_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,13 @@ The following arguments are supported:
The format of the content field. Presently, only the value
"text/markdown" is supported.

* `subject` -
(Optional)
The subject line of the notification. The subject line may not
exceed 10,240 bytes. In notifications generated by this policy the contents
of the subject line after variable expansion will be truncated to 255 bytes
or shorter at the latest UTF-8 character boundary.

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:
Expand Down

0 comments on commit 8732919

Please sign in to comment.