PagerDuty / terraform-provider-pagerduty

Terraform PagerDuty provider
https://www.terraform.io/docs/providers/pagerduty/
Mozilla Public License 2.0
206 stars 210 forks source link

Problem creating an user, an eschedule for they and associate that eschedule to a pre-existing escalation policies. #831

Open Zarzaparro opened 7 months ago

Zarzaparro commented 7 months ago

I'm trying to create a user, an eschedule for him and associate that eschedule to a pre-existing escalation policies

This is the code that is working:

New user creation

resource "pagerduty_user" "new_user" { name = "Pedro Palotes" email = "palotes@example.com" role = "user" }

New eschedule for him and its association with the new user

resource "pagerduty_schedule" "new_user_schedule" { name = "Schedule de Pedro Palotes" description = "Horario de lunes a viernes de 8am a 6pm en horario de España" time_zone = "Europe/Madrid" # Zona horaria de España

layer configuration

layer { name = "Layer 1" start = "08:00:00" end = "18:00:00" rotation_virtual_start = "2024-03-11T08:00:00" rotation_turn_length_seconds = 86400 users = [pagerduty_user.new_user.id] } }

But this is the part that does not work:

Associate that new schedule to varios pre-existence escalation policies

resource "null_resource" "associate_schedule_to_policy" { triggers = { schedule_id = data.pagerduty_schedule.new_user_schedule_data.id name = each.value for_each = var.escalation_policy_id } }

In the variables I have this set: variable "escalation_policy_id" { description = "Id de los escalation" type = set(string) }

And in the tfvars I have this set: escalation_policy_id = ["PRDZEJ1", "P99R45N"]

But if I "Terraform plan" I get this error:

A data resource "pagerduty_schedule" "new_user_schedule_data" has not been declared in the root module.

What am I doing wrong?

THanks in advance.