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

Importing existing user #845

Open 80kk opened 6 months ago

80kk commented 6 months ago

Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.

Terraform Version

1.6.6

Affected Resource(s)

pagerduty_user

I am writing TF code for the existing PD configuration. The plan is for example to import users created manually so this is expected in plan output:

  # pagerduty_user.user["Name Surname"] will be created
  + resource "pagerduty_user" "user" {
      + avatar_url      = (known after apply)
      + color           = (known after apply)
      + description     = "Managed by Terraform"
      + email           = "name.surname@domain.com"
      + html_url        = (known after apply)
      + id              = (known after apply)
      + invitation_sent = (known after apply)
      + license         = (known after apply)
      + name            = "Name Surname"
      + role            = "user"
      + teams           = (known after apply)
      + time_zone       = (known after apply)
    }

to fail, but it proves that provider can talk to PD:

│ Error: POST API call to https://api.pagerduty.com/users failed 400 Bad Request. Code: 2001, Errors: [Email has already been taken], Message: Invalid Input Provided
│
│   with pagerduty_user.user["Name Surname"],
│   on pagerduty.tf line 57, in resource "pagerduty_user" "user":
│   57: resource "pagerduty_user" "user" {

So in the next step I am trying to import the resource in two ways, wrong one and the good one mentioned in provider documentation as proper way of doing it:

terraform import pagerduty_user.user "Name Surname"

and then:

terraform import pagerduty_user.user PUxxxxx

In both cases I am getting:

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

So just in case I've ran:

terraform import pagerduty_user.user whateveryouwant

and that succeeded too. Of course If I run plan again it want still add the user and there is nothing in the Terraform state related to pagerduty resources. Does this work at all, or I am doing something wrong here?