ns1-terraform / terraform-provider-ns1

Terraform NS1 provider
https://www.terraform.io/docs/providers/ns1/
Mozilla Public License 2.0
31 stars 63 forks source link

Unable to link MonitoringJob to Record/Answers #43

Closed AppleMaster closed 5 years ago

AppleMaster commented 5 years ago

Terraform Version

Terraform 0.11.11

Affected Resource(s)

Terraform Configuration Files

resource "ns1_monitoringjob" "ftevif2_monitor_test" {
  name          = "FTE VIF #2"
  active        = true
  regions       = ["lga"]
  job_type      = "http"
  frequency     = 60
  rapid_recheck = true
  policy        = "quorum"
  notify_list   = "working_id"
  notify_failback = true

  config = {
    method = "GET"
    url = "http://example.com"
  }

  rules = {
    value      = "503"
    comparison = "=="
    key        = "status_code"
  }

}

Expected Behavior

There should be a data feed created that is linked to this new monitoring job, which then allows us to link the job to answer records - this can be observed when creating a monitoring job through the UI on NS1.

Actual Behavior

When a new monitoring job is created via terraform, it exists in the web UI and system , but no corresponding data feed is created, meaning the monitor job cannot then be linked to records.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Create a new monitoring job
  2. terraform plan
  3. terraform apply
  4. Observe created monitor job in UI
  5. Observe lack of data feed in UI
AppleMaster commented 5 years ago

We've now managed to create the feeds and datasources ourselves , using terraform but not specifically tied to the monitoring jobs, with the below configuration:

resource "ns1_datasource" "ftevif2" {
  name   = "ftevif2"
  sourcetype = "nsone_monitoring"
}
resource "ns1_datafeed" "ftevif2" {
  name   = "ftevif2"
  source_id = "${ns1_datasource.ftevif2.id}"
  config = {
    jobid = "${ns1_monitoringjob.ftevif2.id}"
  }
}

This works and creates the two, and in the UI we can then associate a record's "up" metadata with the feed that has been created - but we cannot do this with terraform or the NS1 API itself.

Is this supposed to be supported or can support be added?

Being able to do the majority of the configuration via terraform and then having to do the final step manually is kind of not ideal

warmfusion commented 5 years ago

So to paraphase the situation;

  1. We've created a monitor, datasource and data feed
  2. These three objects have been associated correctly to eachother
  3. We've created an ns1_record

Problem is; we can't associated the datafeed to the record using Terraform.

When viewing configuration via the API for systems setup through the UI we can see;

      {
         "meta" : {
            "up" : {
               "feed" : "5b646848bbccf900016f3a10"
            },
            "georegion" : [
               "US-WEST"
            ]
         },
         "answer" : [
            "REDACTED"
         ],
         "id" : "5be9ba81c9c79d0001109647",
         "feeds" : [
            {
               "source" : "91bb55a0a53b38761794e0c6f0d14ef8",
               "feed" : "5b646848bbccf900016f3a10"
            }
         ]
      }

So tried to setup the feed using this Terraform configuration;

  answers = {
    answer  = "REDACTED"
    meta    = {
      up        = {
         feed = "${ns1_datafeed.ftevif1.id}"
        }
    }
  }

but the provider expects up to be a String.

Can you tell us how we'd link a datafeed to a record with an example syntax please.

warmfusion commented 5 years ago

Paraphrased response from NS1 support team;

Due to a limitation in the terraform framework, it is only possible to define the up meta property as a boolean and not a more complex structure that'd support that field being either a boolean or another map.

As such, we can't automatically associate a data-feed with a record via Terraform at this time.

warmfusion commented 5 years ago

Related pull request on upstream NS1 go library which was closed as remarks on the same need for 0.12 of Terraform.

https://github.com/ns1/ns1-go/pull/54

mburtless commented 5 years ago

ns1/ns1-go#63 merges a similar fix to the one proposed in ns1/ns1-go#54 and is available in the latest release of this provider. This allows the value of a metadata key to be set to a raw JSON string that points at a feed (i.e. weight = "{\"feed\":\"${ns1_datafeed.foobar.id}\"}").

I'm going to close this issue as this should enable a workaround while we wait for the improvements in v0.12 to make it into the SDK.