lapras-inc / terraform-provider-uptimerobot

A terraform provider for UptimeRobot
https://registry.terraform.io/providers/lapras-inc/uptimerobot/latest
Mozilla Public License 2.0
3 stars 1 forks source link

Add new resource "uptimerobot_alert_contact_assignment" #12

Open c33s opened 1 year ago

c33s commented 1 year ago

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"]
}

related issues:

https://github.com/louy/terraform-provider-uptimerobot/issues/116 https://github.com/vexxhost/terraform-provider-uptimerobot/issues/11

yktakaha4 commented 1 year ago

This is a backward incompatible change, but I prefer it this way too. I would like to specify Deprecated to alert_contact attribute. https://developer.hashicorp.com/terraform/plugin/sdkv2/best-practices/deprecations

Could you please create a PR?