Skip to content

Commit 43805c3

Browse files
Add support for links in Monitoring AlertPolicy (#11017) (#18549)
[upstream:c8d4f427e148d0c1a72869183303e787d8d93b08] Signed-off-by: Modular Magician <[email protected]>
1 parent d75028e commit 43805c3

File tree

4 files changed

+129
-4
lines changed

4 files changed

+129
-4
lines changed

.changelog/11017.txt

Whitespace-only changes.

google/services/monitoring/resource_monitoring_alert_policy.go

+96-3
Original file line numberDiff line numberDiff line change
@@ -920,15 +920,35 @@ limited capacity might not show this documentation.`,
920920
The content may not exceed 8,192 Unicode characters and may not
921921
exceed more than 10,240 bytes when encoded in UTF-8 format,
922922
whichever is smaller.`,
923-
AtLeastOneOf: []string{"documentation.0.content", "documentation.0.mime_type", "documentation.0.subject"},
923+
AtLeastOneOf: []string{"documentation.0.content", "documentation.0.mime_type", "documentation.0.subject", "documentation.0.links"},
924+
},
925+
"links": {
926+
Type: schema.TypeList,
927+
Optional: true,
928+
Description: `Links to content such as playbooks, repositories, and other resources. This field can contain up to 3 entries.`,
929+
Elem: &schema.Resource{
930+
Schema: map[string]*schema.Schema{
931+
"display_name": {
932+
Type: schema.TypeString,
933+
Optional: true,
934+
Description: `A short display name for the link. The display name must not be empty or exceed 63 characters. Example: "playbook".`,
935+
},
936+
"url": {
937+
Type: schema.TypeString,
938+
Optional: true,
939+
Description: `The url of a webpage. A url can be templatized by using variables in the path or the query parameters. The total length of a URL should not exceed 2083 characters before and after variable expansion. Example: "https://my_domain.com/playbook?name=${resource.name}".`,
940+
},
941+
},
942+
},
943+
AtLeastOneOf: []string{"documentation.0.content", "documentation.0.mime_type", "documentation.0.subject", "documentation.0.links"},
924944
},
925945
"mime_type": {
926946
Type: schema.TypeString,
927947
Optional: true,
928948
Description: `The format of the content field. Presently, only the value
929949
"text/markdown" is supported.`,
930950
Default: "text/markdown",
931-
AtLeastOneOf: []string{"documentation.0.content", "documentation.0.mime_type", "documentation.0.subject"},
951+
AtLeastOneOf: []string{"documentation.0.content", "documentation.0.mime_type", "documentation.0.subject", "documentation.0.links"},
932952
},
933953
"subject": {
934954
Type: schema.TypeString,
@@ -937,7 +957,7 @@ whichever is smaller.`,
937957
exceed 10,240 bytes. In notifications generated by this policy the contents
938958
of the subject line after variable expansion will be truncated to 255 bytes
939959
or shorter at the latest UTF-8 character boundary.`,
940-
AtLeastOneOf: []string{"documentation.0.content", "documentation.0.mime_type", "documentation.0.subject"},
960+
AtLeastOneOf: []string{"documentation.0.content", "documentation.0.mime_type", "documentation.0.subject", "documentation.0.links"},
941961
},
942962
},
943963
},
@@ -2049,6 +2069,8 @@ func flattenMonitoringAlertPolicyDocumentation(v interface{}, d *schema.Resource
20492069
flattenMonitoringAlertPolicyDocumentationMimeType(original["mimeType"], d, config)
20502070
transformed["subject"] =
20512071
flattenMonitoringAlertPolicyDocumentationSubject(original["subject"], d, config)
2072+
transformed["links"] =
2073+
flattenMonitoringAlertPolicyDocumentationLinks(original["links"], d, config)
20522074
return []interface{}{transformed}
20532075
}
20542076
func flattenMonitoringAlertPolicyDocumentationContent(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
@@ -2063,6 +2085,33 @@ func flattenMonitoringAlertPolicyDocumentationSubject(v interface{}, d *schema.R
20632085
return v
20642086
}
20652087

2088+
func flattenMonitoringAlertPolicyDocumentationLinks(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
2089+
if v == nil {
2090+
return v
2091+
}
2092+
l := v.([]interface{})
2093+
transformed := make([]interface{}, 0, len(l))
2094+
for _, raw := range l {
2095+
original := raw.(map[string]interface{})
2096+
if len(original) < 1 {
2097+
// Do not include empty json objects coming back from the api
2098+
continue
2099+
}
2100+
transformed = append(transformed, map[string]interface{}{
2101+
"display_name": flattenMonitoringAlertPolicyDocumentationLinksDisplayName(original["displayName"], d, config),
2102+
"url": flattenMonitoringAlertPolicyDocumentationLinksUrl(original["url"], d, config),
2103+
})
2104+
}
2105+
return transformed
2106+
}
2107+
func flattenMonitoringAlertPolicyDocumentationLinksDisplayName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
2108+
return v
2109+
}
2110+
2111+
func flattenMonitoringAlertPolicyDocumentationLinksUrl(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
2112+
return v
2113+
}
2114+
20662115
func expandMonitoringAlertPolicyDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
20672116
return v, nil
20682117
}
@@ -2927,6 +2976,13 @@ func expandMonitoringAlertPolicyDocumentation(v interface{}, d tpgresource.Terra
29272976
transformed["subject"] = transformedSubject
29282977
}
29292978

2979+
transformedLinks, err := expandMonitoringAlertPolicyDocumentationLinks(original["links"], d, config)
2980+
if err != nil {
2981+
return nil, err
2982+
} else if val := reflect.ValueOf(transformedLinks); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2983+
transformed["links"] = transformedLinks
2984+
}
2985+
29302986
return transformed, nil
29312987
}
29322988

@@ -2941,3 +2997,40 @@ func expandMonitoringAlertPolicyDocumentationMimeType(v interface{}, d tpgresour
29412997
func expandMonitoringAlertPolicyDocumentationSubject(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
29422998
return v, nil
29432999
}
3000+
3001+
func expandMonitoringAlertPolicyDocumentationLinks(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
3002+
l := v.([]interface{})
3003+
req := make([]interface{}, 0, len(l))
3004+
for _, raw := range l {
3005+
if raw == nil {
3006+
continue
3007+
}
3008+
original := raw.(map[string]interface{})
3009+
transformed := make(map[string]interface{})
3010+
3011+
transformedDisplayName, err := expandMonitoringAlertPolicyDocumentationLinksDisplayName(original["display_name"], d, config)
3012+
if err != nil {
3013+
return nil, err
3014+
} else if val := reflect.ValueOf(transformedDisplayName); val.IsValid() && !tpgresource.IsEmptyValue(val) {
3015+
transformed["displayName"] = transformedDisplayName
3016+
}
3017+
3018+
transformedUrl, err := expandMonitoringAlertPolicyDocumentationLinksUrl(original["url"], d, config)
3019+
if err != nil {
3020+
return nil, err
3021+
} else if val := reflect.ValueOf(transformedUrl); val.IsValid() && !tpgresource.IsEmptyValue(val) {
3022+
transformed["url"] = transformedUrl
3023+
}
3024+
3025+
req = append(req, transformed)
3026+
}
3027+
return req, nil
3028+
}
3029+
3030+
func expandMonitoringAlertPolicyDocumentationLinksDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
3031+
return v, nil
3032+
}
3033+
3034+
func expandMonitoringAlertPolicyDocumentationLinksUrl(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
3035+
return v, nil
3036+
}

google/services/monitoring/resource_monitoring_alert_policy_test.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ resource "google_monitoring_alert_policy" "full" {
331331
content = "test content"
332332
mime_type = "text/markdown"
333333
subject = "test subject"
334+
links {
335+
display_name = "link display name"
336+
url = "http://mydomain.com"
337+
}
334338
}
335339
}
336340
`, alertName, conditionName1, conditionName2)
@@ -362,6 +366,14 @@ resource "google_monitoring_alert_policy" "mql" {
362366
content = "test content"
363367
mime_type = "text/markdown"
364368
subject = "test subject"
369+
links {
370+
display_name = "link display name"
371+
url = "http://mydomain.com"
372+
}
373+
links {
374+
display_name = "link display name2"
375+
url = "http://mydomain2.com"
376+
}
365377
}
366378
}
367379
`, alertName, conditionName)
@@ -397,7 +409,7 @@ resource "google_monitoring_alert_policy" "log" {
397409
documentation {
398410
content = "test content"
399411
mime_type = "text/markdown"
400-
subject = "test subject"
412+
subject = "test subject"
401413
}
402414
}
403415
`, alertName, conditionName)
@@ -459,6 +471,10 @@ resource "google_monitoring_alert_policy" "promql" {
459471
content = "test content"
460472
mime_type = "text/markdown"
461473
subject = "test subject"
474+
links {
475+
display_name = "link display name"
476+
url = "http://mydomain.com"
477+
}
462478
}
463479
}
464480
`, alertName, conditionName)

website/docs/r/monitoring_alert_policy.html.markdown

+16
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,22 @@ The following arguments are supported:
943943
of the subject line after variable expansion will be truncated to 255 bytes
944944
or shorter at the latest UTF-8 character boundary.
945945

946+
* `links` -
947+
(Optional)
948+
Links to content such as playbooks, repositories, and other resources. This field can contain up to 3 entries.
949+
Structure is [documented below](#nested_links).
950+
951+
952+
<a name="nested_links"></a>The `links` block supports:
953+
954+
* `display_name` -
955+
(Optional)
956+
A short display name for the link. The display name must not be empty or exceed 63 characters. Example: "playbook".
957+
958+
* `url` -
959+
(Optional)
960+
The url of a webpage. A url can be templatized by using variables in the path or the query parameters. The total length of a URL should not exceed 2083 characters before and after variable expansion. Example: "https://my_domain.com/playbook?name=${resource.name}".
961+
946962
## Attributes Reference
947963

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

0 commit comments

Comments
 (0)