Skip to content

Commit 109dac8

Browse files
committed
[opendistro_user] Add password hash.
1 parent 284af82 commit 109dac8

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

es/resource_elasticsearch_opendistro_user.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,18 @@ func resourceElasticsearchOpenDistroUser() *schema.Resource {
2525
Required: true,
2626
},
2727
"password": {
28-
Type: schema.TypeString,
29-
Required: true,
30-
Sensitive: true,
28+
Type: schema.TypeString,
29+
Optional: true,
30+
Sensitive: true,
31+
DiffSuppressFunc: onlyDiffOnCreate,
32+
ConflictsWith: []string{"password_hash"},
33+
},
34+
"password_hash": {
35+
Type: schema.TypeString,
36+
Optional: true,
37+
Sensitive: true,
38+
DiffSuppressFunc: onlyDiffOnCreate,
39+
ConflictsWith: []string{"password"},
3140
},
3241
"backend_roles": {
3342
Type: schema.TypeSet,
@@ -159,6 +168,7 @@ func resourceElasticsearchPutOpenDistroUser(d *schema.ResourceData, m interface{
159168
Description: d.Get("description").(string),
160169
Attributes: d.Get("attributes").(map[string]interface{}),
161170
Password: d.Get("password").(string),
171+
PasswordHash: d.Get("password_hash").(string),
162172
}
163173

164174
userJSON, err := json.Marshal(userDefinition)
@@ -204,6 +214,7 @@ type UserBody struct {
204214
Attributes map[string]interface{} `json:"attributes"`
205215
Description string `json:"description"`
206216
Password string `json:"password"`
217+
PasswordHash string `json:"hash"`
207218
}
208219

209220
// UserResponse sent by the odfe's API

es/resource_elasticsearch_opendistro_user_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ func TestAccElasticsearchOpenDistroUser(t *testing.T) {
9494
),
9595
),
9696
},
97+
{
98+
Config: testAccOpenDistroUserResourceHash(randomName),
99+
Check: resource.ComposeTestCheckFunc(
100+
testCheckElasticSearchOpenDistroUserExists("elasticsearch_opendistro_user.test"),
101+
resource.TestCheckResourceAttr(
102+
"elasticsearch_opendistro_user.test",
103+
"id",
104+
randomName,
105+
),
106+
),
107+
},
97108
},
98109
})
99110
}
@@ -200,6 +211,15 @@ func testAccOpenDistroUserResource(resourceName string) string {
200211
`, resourceName)
201212
}
202213

214+
func testAccOpenDistroUserResourceHash(resourceName string) string {
215+
return fmt.Sprintf(`
216+
resource "elasticsearch_opendistro_user" "test" {
217+
username = "%s"
218+
password_hash = "$2a$04$jQcEXpODnTFoGDuA7DPdSevA84CuH/7MOYkb80M3XZIrH76YMWS9G"
219+
}
220+
`, resourceName)
221+
}
222+
203223
func testAccOpenDistroUserResourceUpdated(resourceName string) string {
204224
return fmt.Sprintf(`
205225
resource "elasticsearch_opendistro_user" "test" {

0 commit comments

Comments
 (0)