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

Allow tfe_organization_membership import by org name and user email #715

Merged
merged 3 commits into from
Feb 2, 2023

Conversation

JarrettSpiker
Copy link
Contributor

Description

Allow tfe_organization_membership resource to also be imported by org-name/user-email

Presently, the resource can only be imported through its ID, which is not presented to the user in the TFE UI. This makes it very difficult to import.

Testing plan

  1. Test that import by ID still works
  2. Test that importing by org/email works
  3. Test that importing by an invalid format errors
  4. Test that importing a non existent org name or email errors

External links

Output from acceptance tests

❯ TF_ACC=1 go test ./...  -run TestAccTFEOrganizationMembership -tags=integration -v
?       github.com/hashicorp/terraform-provider-tfe     [no test files]
=== RUN   TestAccTFEOrganizationMembershipDataSource_basic
--- PASS: TestAccTFEOrganizationMembershipDataSource_basic (17.87s)
=== RUN   TestAccTFEOrganizationMembershipDataSource_findByName
    data_source_organization_membership_test.go:47: Please set TFE_USER1 to run this test
--- SKIP: TestAccTFEOrganizationMembershipDataSource_findByName (0.36s)
=== RUN   TestAccTFEOrganizationMembershipDataSource_missingParams
--- PASS: TestAccTFEOrganizationMembershipDataSource_missingParams (4.41s)
=== RUN   TestAccTFEOrganizationMembership_basic
--- PASS: TestAccTFEOrganizationMembership_basic (6.66s)
=== RUN   TestAccTFEOrganizationMembershipImport_ByID
--- PASS: TestAccTFEOrganizationMembershipImport_ByID (6.94s)
=== RUN   TestAccTFEOrganizationMembershipImport_ByEmail
--- PASS: TestAccTFEOrganizationMembershipImport_ByEmail (7.05s)
=== RUN   TestAccTFEOrganizationMembershipImport_invalidImportId
--- PASS: TestAccTFEOrganizationMembershipImport_invalidImportId (7.72s)
PASS
ok      github.com/hashicorp/terraform-provider-tfe/tfe 51.182s


...

@JarrettSpiker JarrettSpiker requested a review from a team as a code owner December 9, 2022 15:55
@@ -108,3 +110,25 @@ func resourceTFEOrganizationMembershipDelete(d *schema.ResourceData, meta interf

return nil
}

func resourceTFEOrganizationMembershipImporter(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
tfeClient := meta.(*tfe.Client)
Copy link
Contributor

Choose a reason for hiding this comment

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

Panic ❗

Suggested change
tfeClient := meta.(*tfe.Client)
config := meta.(ConfiguredClient)
// you can use the tfe client: config.Client.Workspaces.Blah()

This change was introduced in #762

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed! Thanks for catching that

Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

This is great. Can you rebase the CHANGELOG?

@JarrettSpiker
Copy link
Contributor Author

This is great. Can you rebase the CHANGELOG?

Absolutely! I will merge this once I get some local dev issues figured out and I can test out the rebase

@brandonc
Copy link
Collaborator

brandonc commented Feb 2, 2023

We are struggling with some upstream test infrastructure changes today. I'm going to merge this now and ensure the tests pass later on.

@brandonc brandonc merged commit e5a76b8 into main Feb 2, 2023
@brandonc brandonc deleted the jspiker/import-org-membership branch February 2, 2023 23:43
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.

None yet

3 participants