PagerDuty / terraform-provider-pagerduty

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

PAGERDUTY_TOKEN env variable doesn't really work #682

Open graudeejs opened 1 year ago

graudeejs commented 1 year ago

Terraform Version

Terraform v1.4.6 on darwin_arm64

Affected Resource(s)

Provider

Terraform Configuration Files

terraform {
  backend "remote" {
    hostname = "app.terraform.io"
    organization = "example-org"

    workspaces {
      name = "pagerduty"
    }
  }

  required_providers {
    pagerduty = {
      source  = "pagerduty/pagerduty"
      version = "2.14.3"
    }
  }

  required_version = ">= 1.3.9"
}

provider "pagerduty" {
  service_region = "eu"
}

data "pagerduty_user" "example" {
  email = "example@example.com"
}

Debug Output

https://gist.github.com/graudeejs/9c5a265088aef7e3937504d8f7021be6

Expected Behavior

token set in PAGERDUTY_TOKEN environment variable should be used

Actual Behavior

Terraform complains about missing required argument token

Steps to Reproduce

Setup minimal terraform project using PagerDuty. Provide PAGERDUTY_TOKEN as environment variable as mentioned in documentation.

References

benlangfeld commented 1 year ago

Is there any workaround available for this? It looks like this provider is unusable in GH Actions without this working.

benlangfeld commented 1 year ago

It looks like this is a usable workaround:

variable "pagerduty_token" {}

provider "pagerduty" {
  token = var.pagerduty_token
}

TF_VAR_pagerduty_token=foobar terraform plan ...

carusooo commented 1 year ago

The documentation seems to indicate that the token doesn't need to be passed in as plaintext, with no examples, support and it's broken right out of the box.

It can also be sourced from the PAGERDUTY_USER_TOKEN environment variable. See [API Documentation](https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTUx-authentication) for more information.
benlangfeld commented 1 year ago

Looks like this was fixed in https://github.com/PagerDuty/terraform-provider-pagerduty/pull/708. Setting PAGERDUTY_TOKEN works for me now.