From 1bc3e3e1b53c19599712646a4112c4dfde37f13e Mon Sep 17 00:00:00 2001 From: Weichung Shaw Date: Mon, 27 Sep 2021 21:49:06 +0100 Subject: [PATCH] GH-132 User's .Exists and .Read only needs d.Id() (#145) * GH-132 User's .Exists and .Read only needs d.Id() * GH-132 add import to User's acceptance test --- pkg/artifactory/resource_artifactory_user.go | 7 ++----- pkg/artifactory/resource_artifactory_user_test.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/artifactory/resource_artifactory_user.go b/pkg/artifactory/resource_artifactory_user.go index 4c22d078c..56cd303bc 100644 --- a/pkg/artifactory/resource_artifactory_user.go +++ b/pkg/artifactory/resource_artifactory_user.go @@ -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) } @@ -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) diff --git a/pkg/artifactory/resource_artifactory_user_test.go b/pkg/artifactory/resource_artifactory_user_test.go index 6d0003fa0..d1e70d6c8 100644 --- a/pkg/artifactory/resource_artifactory_user_test.go +++ b/pkg/artifactory/resource_artifactory_user_test.go @@ -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" + }, }, }) } @@ -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" + }, }, }) }