我们在Terraform中配置的GCP中有一个监控警报策略。我们还想使用Terraform创建一个文档。
我们在GCP中使用以下命令创建文档。
gcloud alpha monitoring policies update projects/project_name/alertPolicies/5861347861929375791 \
--documentation-format="text/markdown" \
--documentation="API has exceeded its quota limit. The systems load has increased beyond capacity, consider increasing your Global and Regional quotas. If this is unexpected behaviour, validate that this is not a bug within your platform."我们有没有办法在Terraform中创建同样的东西?
监控策略配置:
# Alerts when API seeing errors
resource "google_monitoring_alert_policy" "dlp_api_see_errors" {
project = PROJECT_NAME
display_name = "API is seeing errors"
combiner = "OR"
conditions {
display_name = "API is seeing errors"
condition_threshold {
filter = "metric.type=\"serviceruntime.googleapis.com/api/request_count\" resource.type=\"consumed_api\" metric.label.\"response_code\"!=\"200\" resource.label.\"service\"=\"dlp.googleapis.com\""
duration = "60s"
comparison = "COMPARISON_GT"
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_SUM"
cross_series_reducer = "REDUCE_SUM"
}
trigger {
count = 1
}
}
}
notification_channels = "${concat(google_monitoring_notification_channel.ndw_alerting_email.*.id, google_monitoring_notification_channel.ndw_alerting_phone.*.id)}"
}发布于 2020-10-12 18:42:23
google_monitoring_alert_policy resource具有documentation block parameter,可用于设置警报的Markdown文档。
然后,您的资源应如下所示:
# Alerts when API seeing errors
resource "google_monitoring_alert_policy" "dlp_api_see_errors" {
project = PROJECT_NAME
display_name = "API is seeing errors"
combiner = "OR"
conditions {
display_name = "API is seeing errors"
condition_threshold {
filter = "metric.type=\"serviceruntime.googleapis.com/api/request_count\" resource.type=\"consumed_api\" metric.label.\"response_code\"!=\"200\" resource.label.\"service\"=\"dlp.googleapis.com\""
duration = "60s"
comparison = "COMPARISON_GT"
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_SUM"
cross_series_reducer = "REDUCE_SUM"
}
trigger {
count = 1
}
}
}
notification_channels = "${concat(google_monitoring_notification_channel.ndw_alerting_email.*.id, google_monitoring_notification_channel.ndw_alerting_phone.*.id)}"
documentation {
mime_type = "text/markdown"
content = "API has exceeded its quota limit. The systems load has increased beyond capacity, consider increasing your Global and Regional quotas. If this is unexpected behaviour, validate that this is not a bug within your platform."
}
}发布于 2020-10-12 19:10:16
您可以使用Terraform创建/更新 ,但有一些限制。
documentationblock支持:
content -(可选)文档文本,根据mimeType解释。内容不能超过8,192个Unicode字符,以UTF-8格式编码时也不能超过10,240个字节,以较小者为准。
mime_type -(可选)内容字段的格式。目前仅支持"text/markdown“值。
但是,您可以使用"mime/text“格式,并直接包含所有信息。
此外,在此功能中查看一下GCP's official documentation regarding documentation block可能会很有用,但从外部文件加载内容也没有文档记录。
官方文档中只在Modyfying Policy's Documentation中提到了这一特性。
但是既然你可以用gcloud alpha来做这件事,那么我会尝试使用Terraform,也许你会找到一个解决方案,如何在文档块中放入“文件”类型……
https://stackoverflow.com/questions/64312963
复制相似问题