Skip to content

Commit

Permalink
Handle slashes in email addresses for tfe_org_member import
Browse files Browse the repository at this point in the history
  • Loading branch information
JarrettSpiker committed Feb 2, 2023
1 parent 52ba3dc commit c5372af
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions tfe/resource_tfe_organization_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,8 @@ func resourceTFEOrganizationMembershipImporter(ctx context.Context, d *schema.Re
// Import formats:
// - <ORGANIZATION MEMBERSHIP ID>
// - <organization name>/<user email>
s := strings.Split(d.Id(), "/")
if len(s) >= 3 {
return nil, fmt.Errorf(
"invalid organization membership input format: %s (expected <ORGANIZATION>/<USER EMAIL> or <ORGANIZATION MEMBERSHIP ID>)",
d.Id(),
)
} else if len(s) == 2 {
s := strings.SplitN(d.Id(), "/", 2)
if len(s) == 2 {
org := s[0]
email := s[1]
orgMembership, err := fetchOrganizationMemberByNameOrEmail(ctx, config.Client, org, "", email)
Expand Down
2 changes: 1 addition & 1 deletion tfe/resource_tfe_organization_membership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestAccTFEOrganizationMembershipImport_invalidImportId(t *testing.T) {
ResourceName: "tfe_organization_membership.foobar",
ImportState: true,
ImportStateId: fmt.Sprintf("%s/%s/someOtherString", orgName, email),
ExpectError: regexp.MustCompile("invalid organization membership input format"),
ExpectError: regexp.MustCompile(fmt.Sprintf("error retrieving user with email %s/someOtherString from organization %s", email, orgName)),
},
{
ResourceName: "tfe_organization_membership.foobar",
Expand Down

0 comments on commit c5372af

Please sign in to comment.