terraform-provider-uptimerobot icon indicating copy to clipboard operation
terraform-provider-uptimerobot copied to clipboard

Add new resource "uptimerobot_alert_contact_assignment"

Open c33s opened this issue 3 years ago • 0 comments

currently the mapping of an alert_contact to a monitor is a little bit unhandy as it is defined inside of the monitor. this leads also to problems like https://github.com/louy/terraform-provider-uptimerobot/pull/97#issuecomment-916059540

my suggestion would be to add a separate resource "uptimerobot_alert_contact_assignment" which would also allow the easy use of the terraform each functionality.

this would be like the hetzner hcloud network resources: https://registry.terraform.io/providers/hetznercloud/hcloud/latest/docs/resources/server_network

resource "hcloud_server" "node1" {
  name        = "node1"
  image       = "debian-9"
  server_type = "cx11"
}
resource "hcloud_network" "mynet" {
  name     = "my-net"
  ip_range = "10.0.0.0/8"
}
resource "hcloud_network_subnet" "foonet" {
  network_id   = hcloud_network.mynet.id
  type         = "cloud"
  network_zone = "eu-central"
  ip_range     = "10.0.1.0/24"
}

resource "hcloud_server_network" "srvnetwork" {
  server_id  = hcloud_server.node1.id
  network_id = hcloud_network.mynet.id
  ip         = "10.0.1.5"
}

from:

resource "uptimerobot_monitor" "my_monitor" {
  ...
  alert_contact {
    id = resource.uptimerobot_alert_contact.email_alerts["NameOfContact1"].id
  }
  alert_contact {
    id = resource.uptimerobot_alert_contact.email_alerts["NameOfContact2"].id
  }
  ...
}

to

resource "uptimerobot_monitor" "my_monitor" {
  ...
}

resource "uptimerobot_alert_contact_assignment" "all_email_contacts" {
  for_each = resource.uptimerobot_alert_contact.email_alerts
  monitor_id: resource .uptimerobot_monitor.my_monitor.id
  alert_id: each.value["id"]
}

c33s avatar Jan 18 '22 16:01 c33s