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

Crash on tfe_team managing owners team (free plan) #179

Closed
lingrino opened this issue May 25, 2020 · 2 comments · Fixed by #181
Closed

Crash on tfe_team managing owners team (free plan) #179

lingrino opened this issue May 25, 2020 · 2 comments · Fixed by #181

Comments

@lingrino
Copy link

👋 I previously managed the 'owners' team in my (free plan) terraform cloud account. This is a default team that exists in all orgs (I think?). I imported that team into the tfe_team a while ago without issue. It's not actually that useful to manage a default team that cannot be changed 😄, but it's something I had set up.

It looks like the newest version of this provider no longer allows this configuration and currently crashes terraform. The crash occurs both on a plan/apply of the existing setup and on any attempt to import that team. Maybe it was never an intended feature, but crashes aren't great so here's some details to help resolve!

Here is the relevant part of the crash.log

2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: panic: runtime error: invalid memory address or nil pointer dereference
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x199d6a2]
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: 
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: goroutine 74 [running]:
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: github.com/terraform-providers/terraform-provider-tfe/tfe.resourceTFETeamRead(0xc0002bf0a0, 0x1b48ae0, 0xc0003a21e0, 0xc0002bf0a0, 0x0)
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-tfe/tfe/resource_tfe_team.go:126 +0x5c2
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc000117300, 0xc0001d6d20, 0x1b48ae0, 0xc0003a21e0, 0xc0005521a8, 0x0, 0x0)
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-tfe/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/resource.go:455 +0x11c
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadResource(0xc00000cab0, 0x1dd8c40, 0xc0001278c0, 0xc0001d6a50, 0xc00000cab0, 0xc000127830, 0x1ad8400)
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-tfe/vendor/github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin/grpc_provider.go:525 +0x3a8
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler(0x1be39e0, 0xc00000cab0, 0x1dd8c40, 0xc0001278c0, 0xc0005c0d80, 0x0, 0x0, 0x0, 0xc000245280, 0x7d)
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-tfe/vendor/github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5/tfplugin5.pb.go:3153 +0x23e
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: google.golang.org/grpc.(*Server).processUnaryRPC(0xc0000c4000, 0x1ddf740, 0xc00055e900, 0xc000444d00, 0xc0001263f0, 0x257c270, 0x0, 0x0, 0x0)
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-tfe/vendor/google.golang.org/grpc/server.go:995 +0x485
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: google.golang.org/grpc.(*Server).handleStream(0xc0000c4000, 0x1ddf740, 0xc00055e900, 0xc000444d00, 0x0)
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-tfe/vendor/google.golang.org/grpc/server.go:1275 +0xe02
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc000036540, 0xc0000c4000, 0x1ddf740, 0xc00055e900, 0xc000444d00)
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-tfe/vendor/google.golang.org/grpc/server.go:710 +0x9f
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: created by google.golang.org/grpc.(*Server).serveStreams.func1
2020-05-24T18:43:26.002-0500 [DEBUG] plugin.terraform-provider-tfe_v0.17.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-tfe/vendor/google.golang.org/grpc/server.go:708 +0xa1
2020/05/24 18:43:26 [ERROR] <root>: eval: *terraform.EvalRefresh, err: rpc error: code = Unavailable desc = transport is closing
2020/05/24 18:43:26 [ERROR] <root>: eval: *terraform.EvalSequence, err: rpc error: code = Unavailable desc = transport is closing
2020/05/24 18:43:26 [TRACE] [walkImport] Exiting eval tree: import tfe_team.owners result
2020/05/24 18:43:26 [TRACE] vertex "import tfe_team.owners result": visit complete

It looks like this bug was introduced in this PR (#155), since it's the only change to that file in the last 9 days (the last time I successfully applied). I haven't looked too deeply into the issue but the crash begins on line 126.

Here's the terraform that used to work and no longer does (I'm on the free plan, authenticating with a personal token).

# teams.tf

resource "tfe_team" "owners" {
  organization = tfe_organization.org.id
  name         = "owners"
}

resource "tfe_team_members" "owners" {
  team_id = tfe_team.owners.id

  usernames = [
    "lingrino",
    "api-org-lingrino",
    "gh-webhooks-lingrino",
  ]
}

This configuration was previously (months ago) imported successfully and recently started producing the crash. I resolve the issue for myself by removing the tfe_team and tfe_team_members from state with terraform state rm .... I then tried to re-import the team but it produced the same issue.

I hope this is enough information to resolve the panic! Thank you for a great provider 🙇

@ghost ghost added bug crash labels May 25, 2020
@bendrucker
Copy link
Contributor

Seems that team has no organization-settings key, from my account:

{
  "data": {
    "attributes": {
      "name": "owners",
      "permissions": {
        "can-destroy": false,
        "can-update-api-token": true,
        "can-update-membership": true,
        "can-update-organization-access": false,
        "can-update-visibility": false
      },
      "users-count": 3,
      "visibility": "secret"
    }
  }
}

This comes from the organization rather than team, as the attributes are there in TFE. As you note I don't think this is an intended feature since all the attributes are immutable. But I'll get the crash fixed.

bendrucker added a commit to bendrucker/terraform-provider-tfe that referenced this issue May 25, 2020
Applies to owners team on free plan

Closes hashicorp#179
@chrisarcand
Copy link
Member

Hi! Thanks for the awesome report, this is more than enough to resolve it! And thanks @bendrucker for following up.

The issue is indeed that the organization access key is not returned in all cases, so the updates to state must be conditional; I've explained a bit more in #181

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants