You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terraform使用3.13.0版New Relic Provider崩溃问题求助

问题诊断与修复方案

核心错误:monitor_id参数取值错误

你的newrelic_synthetics_alert_condition资源中,monitor_id字段错误使用了监控名称(local.finishedList[count.index]),但该字段要求传入New Relic Synthetics监控的唯一资源ID,而非自定义名称。这会导致Terraform Provider无法匹配对应监控资源,进而引发执行阶段崩溃。

其他潜在问题

  1. 告警通道未关联策略:你创建了newrelic_alert_channel但未将其绑定到告警策略,告警触发后无法发送通知。
  2. 收件人格式错误:recipients字段需要合法邮箱地址(如"admin@example.com"),而非单纯域名"foo.com"。

修正后的完整代码

terraform {
 required_version = "~> 1.3.7"
 required_providers{
  newrelic = {
   source  = "newrelic/newrelic"
   version = "~> 3.13"
    }
  } 
}

locals{
 splitList = [for url in var.urlList: split(".", url)[1]]
 finishedList = [for split in local.splitList: join("-", [split, "Cert Check"])]
}

resource "newrelic_alert_policy" "certChecks" {
 name = "SSL Cert Check Expirations"
 incident_preference = "PER_POLICY"
}

resource "newrelic_alert_channel" "SSL_Alert" {
 name = "SSL Expiration Alert"
 type = "email"

 config {
  recipients              = "admin@example.com" # 修正为合法邮箱
  include_json_attachment = "true"
 }
}

# 新增:关联告警通道与策略
resource "newrelic_alert_policy_channel" "ssl_alert_binding" {
 policy_id  = newrelic_alert_policy.certChecks.id
 channel_id = newrelic_alert_channel.SSL_Alert.id
}

resource "newrelic_synthetics_cert_check_monitor" "monitor"{
 count                  = length(var.urlList)
 name                   = local.finishedList[count.index]
 domain                 = var.urlList[count.index]
 locations_public       = ["US_EAST_1"]
 certificate_expiration = "350"
 period                 = "EVERY_DAY"
 status                 = "ENABLED"
}

resource "newrelic_synthetics_alert_condition" "foo" {
 policy_id   = newrelic_alert_policy.certChecks.id
 count       = length(var.urlList)
 name        = "SSL Expiration"
 monitor_id  = newrelic_synthetics_cert_check_monitor.monitor[count.index].id # 修正为监控ID
}

验证步骤

  1. 执行terraform init确保Provider版本匹配
  2. 执行terraform plan确认资源依赖关系正常
  3. 执行terraform apply完成资源创建

内容的提问来源于stack exchange,提问作者santonijoe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 09:55:31