PagerDuty Terraform Provider

repository·master·Indexed 42 days ago

https://github.com/pagerduty/terraform-provider-pagerduty

The Terraform PagerDuty provider allows users to manage PagerDuty resources, such as users, teams, and notification rules, using HashiCorp Configuration Language (HCL). It supports caching mechanisms via in-memory or MongoDB to improve performance for specific resources and provides a SECURE log level for debugging API calls with obfuscated sensitive information.

Tokens
77K
Snippets
216
Records
376
Agent score
52%

What's inside PagerDuty Terraform Provider

  1. Manage shift-based schedules with pagerduty_schedulev2

    master

    The pagerduty_schedulev2 resource manages modern, shift-based on-call schedules using the PagerDuty v3 Schedules API. Unlike the legacy pagerduty_schedule (v2), this resource uses flexible rotation configurations based on RFC 5545 recurrence rules (RRULE) and per-event assignment strategies.

    Key differences from legacy schedules:

    • Legacy (pagerduty_schedule): Uses layer blocks with a fixed rotation_turn_length_seconds.
    • Shift-based (pagerduty_schedulev2): Uses rotation and event blocks where an assignment_strategy determines how members cover occurrences defined by an RRULE.

    In the PagerDuty UI, legacy schedules are identified by a legacy tag.

    resource "pagerduty_schedulev2" "example" {
      name        = "Engineering On-Call"
      time_zone   = "America/New_York"
      description = "Managed by Terraform"
    
      rotation {
        event {
          name            = "Weekday Business Hours"
          start_time      = "2026-06-01T09:00:00Z"
          end_time        = "2026-06-01T17:00:00Z"
          effective_since = "2026-06-01T09:00:00Z"
          recurrence      = ["RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR"]
    
          assignment_strategy {
            type             = "rotating_member_assignment_strategy"
            shifts_per_member = 1
    
            member {
              type    = "user_member"
              user_id = pagerduty_user.example.id
            }
          }
        }
      }
    }
  2. Manage Service Orchestration Sets and Rules

    master

    Service Orchestrations are structured as a graph of Sets containing Rules.

    Sets (set)

    Sets are containers for rules. Rules in other sets can route events into a specific set using the route_to action.

    • id: (Required) Unique identifier for the set.
    • rule: (Optional) A list of rules to evaluate. If no rules are provided, the API returns an empty list.

    Rules (rule)

    Rules are evaluated one at a time. The first rule where all conditions match will have its actions applied.

    • label: (Optional) Description of the rule.
    • condition: (Optional) A list of conditions. The rule matches if any condition matches. If no conditions are provided, the rule matches always.
    • actions: (Required) The operations to perform when a match occurs.
    • disabled: (Optional) If true, the rule is skipped.

    Conditions (condition)

    • expression: (Required) A PCL condition string used to evaluate the event.
  3. Understand the conceptual differences between v1 and v2 schedules

    master

    The two resources use different abstractions for on-call coverage:

    Conceptpagerduty_schedule (v1)pagerduty_schedulev2 (v2)
    Core unitlayer — users rotate through turnsrotation + event — explicit time window with fixed assignment
    RecurrenceImplied by rotation_turn_length_secondsExplicit RFC 5545 RRULE string
    Time restrictionrestriction block limits when a turn is activestart_time/end_time + recurrence define the window directly
    Layer lifecycleLayers can only be ended, never deletedRotations and events are fully mutable
  4. Manage PagerDuty maintenance windows with pagerduty_maintenance_window

    master

    The pagerduty_maintenance_window resource allows you to create and manage maintenance windows in PagerDuty. A maintenance window temporarily disables one or more services for a specified period, preventing incident triggers and notifications for those services.

    Important Lifecycle Note: Once a maintenance window has started, it cannot be deleted. It can only be ended immediately to re-enable the services.

    resource "pagerduty_maintenance_window" "example" {
      start_time  = "2015-11-09T20:00:00-05:00"
      end_time    = "2015-11-09T22:00:00-05:00"
      services    = [pagerduty_service.example.id]
    }
  5. Use the pagerduty_license data source to manage user licenses

    master

    The pagerduty_license data source allows you to retrieve information about a purchased PagerDuty license. This is primarily used to manage PagerDuty user resources by assigning a specific license ID to a pagerduty_user resource.

    Best Practices for Selection

    When selecting a license, you can use the id, name, or description:

    • Exact Match: Setting name and description to their exact values or using the id is preferred for precision.
    • Substring Match: To prevent configuration errors if account products change, you can use a valid substring for the name (e.g., "Full User" or "Stakeholder").

    Role Assignment Constraint

    When assigning a role to a pagerduty_user, the role must be included in the valid_roles list provided by the pagerduty_license data source for that specific license.

    data "pagerduty_license" "full_user" {
      name = "Full User"
      description = ""
    }
    
    resource "pagerduty_user" "example" {
      name    = "Earline Greenholt"
      email   = "125.greenholt.earline@graham.name"
      license = data.pagerduty_license.full_user.id
      role    = "user"
    }
  6. Manage feature enablements with pagerduty_enablement

    master

    The pagerduty_enablement resource allows you to enable or disable specific features for PagerDuty entities, such as services and event orchestrations. This is useful for managing feature flags like aiops via Terraform.

    data "pagerduty_service" "example" {
      name = "My Web Service"
    }
    
    resource "pagerduty_enablement" "example" {
      entity_type = "service"
      entity_id   = data.pagerduty_service.example.id
      feature     = "aiops"
      enabled     = true
    }
  7. Use the pagerduty_schedule data source

    master

    The pagerduty_schedule data source allows you to retrieve information about an existing PagerDuty schedule. This is particularly useful when a schedule is managed outside of your Terraform configuration (e.g., manually in the PagerDuty UI) but you need to reference its id in other Terraform resources, such as an escalation policy.

    data "pagerduty_schedule" "test" {
      name = "Daily Engineering Rotation"
    }
  8. Understand Action Data (action_data_reference)

    master

    The action_data_reference attribute provides detailed configuration for the specific type of action being retrieved. The required fields depend on the action_type:

    For process_automation action_type:

    • process_automation_job_id - (Required) The ID of the Process Automation job to execute.
    • process_automation_job_arguments - (Optional) The arguments to pass to the Process Automation job execution.
    • process_automation_node_filter - (Optional) The expression that filters on which nodes a Process Automation Job executes.

    For script action_type:

    • script - (Required) Body of the script to be executed on the Runner. Max length is 16777215 characters.
    • invocation_command - (Optional) The command to execute the script with.
  9. Manage Event Orchestrations with pagerduty_event_orchestration

    master

    The pagerduty_event_orchestration resource allows you to create and manage PagerDuty Event Orchestrations. Event Orchestrations define a set of Event Rules that route ingested events to the correct Global or Service Orchestration based on the event's content. Events are ingested using the Orchestration's unique Routing Key.

    resource "pagerduty_event_orchestration" "my_monitor" {
      name = "My Monitoring Orchestration"
      description = "Send events to a pair of services"
      team = pagerduty_team.engineering.id
    }
  10. Manage escalation policies with pagerduty_escalation_policy

    master

    The pagerduty_escalation_policy resource creates and manages an escalation policy in PagerDuty. An escalation policy determines the sequence of users or schedules to be notified when an incident is triggered. These policies are typically assigned to one or more services.

    resource "pagerduty_escalation_policy" "example" {
      name      = "Engineering Escalation Policy"
      num_loops = 2
      teams     = [pagerduty_team.example.id]
    
      rule {
        escalation_delay_in_minutes = 10
        target {
          type = "user_reference"
          id   = pagerduty_user.example.id
        }
        target {
          type = "user_reference"
          id   = pagerduty_user.example2.id
        }
      }
    }
  11. Manage Event Orchestration Integrations with pagerduty_event_orchestration_integration

    master

    The pagerduty_event_orchestration_integration resource allows you to create and manage multiple Integrations (and Routing Keys) for a single Event Orchestration. It also enables migrating Integrations between different Event Orchestrations by updating the event_orchestration argument.

    Note on Migration: Modifying the event_orchestration property triggers an Integration migration process. Once changed, all future events sent using this Integration's Routing Key will be evaluated against the new Event Orchestration.

    resource "pagerduty_event_orchestration_integration" "integration" {
      event_orchestration = pagerduty_event_orchestration.event_orchestration.id
      label = "Example integration"
    }