通过 terraform 将监控连接到 ns1 记录

connect monitoring to ns1 record via terraform

我有一个创建 ns1 记录的 terraform 代码:​​

answers {
    answer = "MY_FIRST_IP"
    meta = {
      up = true
      georegion = "US-WEST,ASIAPAC"
    }
  }
  answers {
    answer = "MY_SECOUND_IP"
    meta = {
      up = true
      georegion = "EUROPE"
    }

我希望在第二个答案中,这将取决于我的监控是否启动,UI 看起来像这样:

它按预期工作,但是当我尝试使用类似的东西在 terraform 中创建它时:

answers {
    answer = "MY_FIRST_IP"
    meta = {
      up = true
      georegion = "US-WEST,ASIAPAC"
    }
  }
  answers {
    answer = "MY_SECOUND_IP"
    meta = {
      up = "My Monitoring Name"
      georegion = "EUROPE"
    }

我收到这个错误:

Error: found error/s in answer metadata,found type mismatch for meta field 'Up'. expected [bool], got: string

我在文档中搜索过,但没有找到任何提及此选项的内容

谢谢!

以下应该适合您:

  • 创建数据源:

    resource "ns1_datasource" "example" {
     name       = "example"
     sourcetype = "nsone_monitoring"
    }
    
  • 创建监控作业:

    resource "ns1_monitoringjob" "uswest_monitor" {
     name          = "uswest"
     active        = true
     regions       = ["sjc", "sin", "lga"]
     job_type      = "tcp"
     frequency     = 60
     rapid_recheck = true
     policy        = "quorum"
    
     config = {
      ssl  = 1
      send = "HEAD / HTTP/1.0\r\n\r\n"
      port = 443
      host = "example-elb-uswest.aws.amazon.com"
     }
    
     rules {
      value      = "200 OK"
      comparison = "contains"
      key        = "output"
     }
    }
    
  • 创建数据馈送:

    resource "ns1_datafeed" "uswest_feed" {
     name      = "uswest_feed"
     source_id = "${ns1_datasource.example.id}"
    
     config = {
      jobid = "${ns1_monitoringjob.uswest_monitor.id}"
     }
    }
    
  • 然后,您可以使用以下答案模式创建您的记录:

    answers {
     answer = "MY_SECOND_IP"
     meta    = {
      georegion = "EUROPE"
      up    = "{\"feed\":\"${ns1_datafeed.uswest_feed.id}\"}"
     }
    }