Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type as computed attributes to service & business_service data sources + resources #364

Merged
merged 5 commits into from
Feb 5, 2022

Conversation

jjm
Copy link
Contributor

@jjm jjm commented Aug 1, 2021

As was discussed on this weeks PagerDuty Terraform round table, raising a PR to add a dependency_type commuted attribute for the following:

  • data pagerduty_service
  • data pagerduty_business_service
  • resource pagerduty_service
  • pagerduty_business_service

Also a correct the repo name in the README, as the repo is now owned by PagerDuty.

ToDo:

  • Update docs
  • Update tests.

@stmcallister
Copy link
Contributor

@jjm Super cool idea, as we discussed in the roundtable meeting. Remind me how the fact that the Business Service already having a type field is a blocker? 🤔

@jjm
Copy link
Contributor Author

jjm commented Jan 28, 2022

@stmcallister It was the following type in the schema for resourcePagerDutyBusinessService that I hit a block:

"type": {
Type: schema.TypeString,
Optional: true,
Default: "business_service",
ValidateFunc: validateValueFunc([]string{
"business_service",
"business_service_reference",
}),

As I had added a type to the 2 data sources and to resourcePagerDutyService.

I think maybe the best option is to add a dependancy_type to these resources & data sources instead, so that they don't have a clash with the existing schema.

@jjm jjm force-pushed the feat/jjm/add-service-types branch from d94ec7d to 73373d5 Compare January 28, 2022 09:18
@jjm jjm marked this pull request as ready for review January 28, 2022 09:35
@jjm jjm force-pushed the feat/jjm/add-service-types branch 2 times, most recently from ed2d7d0 to f9a4ada Compare January 28, 2022 10:55
…sources

docs: update the docs for the addition of dependency_type
feat: Use dependency_type instead of type due to a clash on resourcePagerDutyBusinessServiceRead
docs: Update clone instructions in README.md
@jjm jjm force-pushed the feat/jjm/add-service-types branch from f9a4ada to 4cd226b Compare January 28, 2022 10:56
@jjm
Copy link
Contributor Author

jjm commented Jan 28, 2022

I've successfully tested this change locally built, with the following config:

terraform {
  required_providers {
    pagerduty = {
      source  = "terraform.example.com/pagerduty/pagerduty"
      version = "2.3.0"
    }
  }
}

provider "pagerduty" {}

data "pagerduty_escalation_policy" "default" {
  name = "Default"
}

resource "pagerduty_business_service" "checkout_app" {
  name = "Checkout App"
}

resource "pagerduty_service" "web_app" {
  name                    = "Our Web App"
  auto_resolve_timeout    = 14400
  acknowledgement_timeout = 600

  escalation_policy = data.pagerduty_escalation_policy.default.id
}

resource "pagerduty_service" "shopping_cart" {
  name                    = "Shopping Cart"
  auto_resolve_timeout    = 14400
  acknowledgement_timeout = 600

  escalation_policy = data.pagerduty_escalation_policy.default.id
}

resource "pagerduty_service" "vault" {
  name                    = "Vault"
  auto_resolve_timeout    = 14400
  acknowledgement_timeout = 600

  escalation_policy = data.pagerduty_escalation_policy.default.id
}

locals {
  vault = [
    pagerduty_business_service.checkout_app,
    pagerduty_service.shopping_cart,
    pagerduty_service.web_app
  ]
}

resource "pagerduty_service_dependency" "vault" {
  for_each = { for k in local.vault : k.id => k.dependency_type }

  dependency {
    dependent_service {
      id   = each.key
      type = each.value
    }
    supporting_service {
      id   = pagerduty_service.vault.id
      type = pagerduty_service.vault.dependency_type
    }
  }
}

The for_each using the local was just what I was wanting to support. The services need created before the dependancies in this example due to Terraform not being able to determine the number of resources. However other use cases will be possible.

@jjm
Copy link
Contributor Author

jjm commented Jan 28, 2022

@stmcallister Ready for review now and the workflow needs to be approved as this is my first contribution.

@jjm jjm changed the title Add type's to service data sources and service resource Add dependency_type as computed attributes to service & business_service data sources + resources Jan 28, 2022
@stmcallister
Copy link
Contributor

Thanks @jjm! I love this idea in concept, but still not a fan of adding an additional field to the resources that doesn't exist on the PagerDuty API, if we don't have to.

On the pagerduty_business_service resource there is already a type field, as you mentioned, that is constrained to business_service or business_service_reference. Making this field editable in the provider was my mistake from the get go because the API ignores it on POST and PUT. And, if someone sets the value to business_service_reference in the provider they'll get stuck a permanent diff. However, there still is a possibility that some users are setting the value in their scripts.

With all of that said, I think we should change dependency_type to just type on the pagerduty_service resource.

For the pagerduty_business_service resource we have a couple of options I would love your input on. I would like to use the existing type field. To make sure it's going to provide a value that can be used we can either:

  1. Make the type field computed, thus introducing a breaking change, but staying uniform with the API.
  2. Leave the field "editable" to not break existing scripts but change the validation to only accept business_service as a value.

What are your thoughts as a user?

@jjm
Copy link
Contributor Author

jjm commented Feb 3, 2022

@stmcallister Thanks, I think type over dependency_type does makes sense.

I think going with the second option is best, but also mark this attribute as Deprecated following https://www.terraform.io/plugin/sdkv2/best-practices/deprecations#provider-attribute-removal and when there's a major version bump the Deprecated flag is changed to Commuted.

I'll make these changes later on today. I think causing a validation failure when there's a constant diff happening is not so much of an issue.

@jjm jjm changed the title Add dependency_type as computed attributes to service & business_service data sources + resources Add type as computed attributes to service & business_service data sources + resources Feb 3, 2022
…ice (+ make type on pagerduty_business_service as Deprecated)
@jjm jjm force-pushed the feat/jjm/add-service-types branch from ab0207a to c16f50a Compare February 3, 2022 16:23
@jjm
Copy link
Contributor Author

jjm commented Feb 3, 2022

@stmcallister I've made those changes.

Copy link
Contributor

@stmcallister stmcallister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just a few tweaks to the docs and we'll be good. Thanks @jjm !!

website/docs/d/business_service.html.markdown Outdated Show resolved Hide resolved
website/docs/d/service.html.markdown Outdated Show resolved Hide resolved
website/docs/r/service.html.markdown Outdated Show resolved Hide resolved
@jjm jjm force-pushed the feat/jjm/add-service-types branch from fc0a45e to ccd1246 Compare February 3, 2022 22:15
@jjm
Copy link
Contributor Author

jjm commented Feb 3, 2022

Thanks @stmcallister, I've addressed your review comments.

Copy link
Contributor

@stmcallister stmcallister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 🌮 👍 Awesome! Thank you @jjm !!!

@stmcallister stmcallister merged commit a07e62d into PagerDuty:master Feb 5, 2022
@jjm jjm deleted the feat/jjm/add-service-types branch February 5, 2022 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants