I am working on automating some PagerDuty resources and first started on service dependencies. What I thought was a fairly straight forward solve has proven not to be true. When we create service dependencies, we want to be able to attach many dependencies either that the service USES or that the service is USED BY. With this in mind, I created the following resource block in Terraform.
resource "pagerduty_service_dependency" "this" {
count = var.create_dependencies ? 1 : 0
dynamic "dependency" {
for_each = var.dependency
content {
type = dependency.value.type
dynamic "dependent_service" {
for_each = dependency.value.dependent_service
content {
id = dependent_service.value.id
type = dependent_service.value.type
}
}
dynamic "supporting_service" {
for_each = dependency.value.supporting_service
content {
id = supporting_service.value.id
type = supporting_service.value.type
}
}
}
}
}
With this block as the variable
variable "dependency" {
description = "value"
type = any
default = []
}
And using this block for inputs (Using Terragrunt 0.36.x)
// Service Dependencies
create_dependencies = true
dependency = [{
type = "service"
dependent_service = [
{
id = "DD4V04U" // The service we are applying the dependency to.
type = "service"
}
]
supporting_service = [
{
id = "BBF2LHB" // The service that is being used by "DD4V04U"
type = "service"
},
{
id = "AAILTY1" // Another service being used by "DD4V04U"
type = "service"
}
]
}]
The Terraform will apply the change but will only create the last dependency in the list(object). Subsequent additions to this list of objects result in all other dependencies before it being destroyed except for the last object in the list. This applies for both dependent and supporting service lists of objects.
The original path I went down in terms of providing inputs looked like this:
// Service Dependencies
create_dependencies = true
dependency = [
{
type = "service"
dependent_service = [{
id = "DD4V04U"
type = "service"
}],
supporting_service = [{
id = "BBF2LHB"
type = "service"
}]
},
{
type = "service"
dependent_service = [{
id = "DD4V04U"
type = "service"
}],
supporting_service = [{
id = "BBF2LHB"
type = "service"
}]
}
]
...and the API reponds
╷
│ Error: Too many dependency blocks
│
│ on main.tf line 160, in resource "pagerduty_service_dependency" "this":
│ 160: content {
│
│ No more than 1 "dependency" blocks are allowed
╵
Which seems to go against what the API documentation states can be done.
Any insight here as to what I am missing would be highly appreciated. Thanks for looking.
Cheers