Skip to content

Commit

Permalink
Added missing import function
Browse files Browse the repository at this point in the history
  • Loading branch information
micahlmartin committed Sep 14, 2021
1 parent 96de803 commit 1aebf8d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/provider/resource_add_user_to_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"log"
"strings"

"github.com/harness-io/harness-go-sdk/harness/api"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -34,6 +35,16 @@ func resourceAddUserToGroup() *schema.Resource {
ForceNew: true,
},
},

Importer: &schema.ResourceImporter{
StateContext: func(ctx context.Context, d *schema.ResourceData, i interface{}) ([]*schema.ResourceData, error) {
// <user_id>/<group_id>
parts := strings.Split(d.Id(), "/")
d.Set("user_id", parts[0])
d.Set("group_id", parts[1])
return []*schema.ResourceData{d}, nil
},
},
}
}

Expand Down
11 changes: 11 additions & 0 deletions internal/provider/resource_add_user_to_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ func TestAccResourceAddUserToGroup(t *testing.T) {
testAccUserNotInGroup(t, "data.harness_user.test", "harness_user_group.first"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: func(s *terraform.State) (string, error) {
primary := s.RootModule().Resources[resourceName].Primary
user_id := primary.Attributes["user_id"]
group_id := primary.Attributes["group_id"]
return fmt.Sprintf("%s/%s", user_id, group_id), nil
},
},
},
})
}
Expand Down

0 comments on commit 1aebf8d

Please sign in to comment.