Skip to content

Commit

Permalink
GH-132 User's .Exists and .Read only needs d.Id() (#145)
Browse files Browse the repository at this point in the history
* GH-132 User's .Exists and .Read only needs d.Id()

* GH-132 add import to User's acceptance test
  • Loading branch information
wc-s authored Sep 27, 2021
1 parent 530680c commit 1bc3e3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 2 additions & 5 deletions pkg/artifactory/resource_artifactory_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ func resourceArtifactoryUser() *schema.Resource {
func resourceUserExists(data *schema.ResourceData, m interface{}) (bool, error) {

d := &ResourceData{data}
name := d.getString("name", false)
if name == "" {
return false, fmt.Errorf("'name' not supplied")
}
name := d.Id()
return userExists(m.(*resty.Client), name)
}

Expand Down Expand Up @@ -179,7 +176,7 @@ func resourceUserCreate(d *schema.ResourceData, m interface{}) error {
func resourceUserRead(rd *schema.ResourceData, m interface{}) error {
d := &ResourceData{rd}

userName := d.getString("name", false)
userName := d.Id()
user := &services.User{}
resp, err := m.(*resty.Client).R().SetResult(user).Get("artifactory/api/security/users/" + userName)

Expand Down
12 changes: 12 additions & 0 deletions pkg/artifactory/resource_artifactory_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ func TestAccUser_basic(t *testing.T) {
resource.TestCheckNoResourceAttr(fqrn, "profile_updatable"),
),
},
{
ResourceName: fqrn,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"password"}, // password is never returned via the API, so it cannot be "imported"
},
},
})
}
Expand Down Expand Up @@ -68,6 +74,12 @@ func TestAccUser_full(t *testing.T) {
resource.TestCheckResourceAttr(FQRN, "groups.#", "1"),
),
},
{
ResourceName: FQRN,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"password"}, // password is never returned via the API, so it cannot be "imported"
},
},
})
}
Expand Down

0 comments on commit 1bc3e3e

Please sign in to comment.