Skip to content

Commit c9868cf

Browse files
committed
Define default password policy var and change delete method name
1 parent 293835a commit c9868cf

File tree

3 files changed

+32
-34
lines changed

3 files changed

+32
-34
lines changed

sumologic/resource_sumologic_password_policy.go

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ import (
44
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
55
)
66

7+
var DefaultPasswordPolicy = PasswordPolicy{
8+
MinLength: 8,
9+
MaxLength: 128,
10+
MustContainLowercase: true,
11+
MustContainUppercase: true,
12+
MustContainDigits: true,
13+
MustContainSpecialChars: true,
14+
MaxPasswordAgeInDays: 365,
15+
MinUniquePasswords: 10,
16+
AccountLockoutThreshold: 6,
17+
FailedLoginResetDurationInMins: 10,
18+
AccountLockoutDurationInMins: 30,
19+
RequireMfa: false,
20+
RememberMfa: true,
21+
}
22+
723
func resourceSumologicPasswordPolicy() *schema.Resource {
824
return &schema.Resource{
925
Create: resourceSumologicPasswordPolicyCreate,
@@ -15,67 +31,67 @@ func resourceSumologicPasswordPolicy() *schema.Resource {
1531
"min_length": {
1632
Type: schema.TypeInt,
1733
Optional: true,
18-
Default: 8,
34+
Default: DefaultPasswordPolicy.MinLength,
1935
},
2036
"max_length": {
2137
Type: schema.TypeInt,
2238
Optional: true,
23-
Default: 128,
39+
Default: DefaultPasswordPolicy.MaxLength,
2440
},
2541
"must_contain_lowercase": {
2642
Type: schema.TypeBool,
2743
Optional: true,
28-
Default: true,
44+
Default: DefaultPasswordPolicy.MustContainLowercase,
2945
},
3046
"must_contain_uppercase": {
3147
Type: schema.TypeBool,
3248
Optional: true,
33-
Default: true,
49+
Default: DefaultPasswordPolicy.MustContainUppercase,
3450
},
3551
"must_contain_digits": {
3652
Type: schema.TypeBool,
3753
Optional: true,
38-
Default: true,
54+
Default: DefaultPasswordPolicy.MustContainDigits,
3955
},
4056
"must_contain_special_chars": {
4157
Type: schema.TypeBool,
4258
Optional: true,
43-
Default: true,
59+
Default: DefaultPasswordPolicy.MustContainSpecialChars,
4460
},
4561
"max_password_age_in_days": {
4662
Type: schema.TypeInt,
4763
Optional: true,
48-
Default: 365,
64+
Default: DefaultPasswordPolicy.MaxPasswordAgeInDays,
4965
},
5066
"min_unique_passwords": {
5167
Type: schema.TypeInt,
5268
Optional: true,
53-
Default: 10,
69+
Default: DefaultPasswordPolicy.MinUniquePasswords,
5470
},
5571
"account_lockout_threshold": {
5672
Type: schema.TypeInt,
5773
Optional: true,
58-
Default: 6,
74+
Default: DefaultPasswordPolicy.AccountLockoutThreshold,
5975
},
6076
"failed_login_reset_duration_in_mins": {
6177
Type: schema.TypeInt,
6278
Optional: true,
63-
Default: 10,
79+
Default: DefaultPasswordPolicy.FailedLoginResetDurationInMins,
6480
},
6581
"account_lockout_duration_in_mins": {
6682
Type: schema.TypeInt,
6783
Optional: true,
68-
Default: 30,
84+
Default: DefaultPasswordPolicy.AccountLockoutDurationInMins,
6985
},
7086
"require_mfa": {
7187
Type: schema.TypeBool,
7288
Optional: true,
73-
Default: false,
89+
Default: DefaultPasswordPolicy.RequireMfa,
7490
},
7591
"remember_mfa": {
7692
Type: schema.TypeBool,
7793
Optional: true,
78-
Default: true,
94+
Default: DefaultPasswordPolicy.RememberMfa,
7995
},
8096
},
8197
}
@@ -106,7 +122,7 @@ func resourceSumologicPasswordPolicyCreate(d *schema.ResourceData, meta interfac
106122

107123
func resourceSumologicPasswordPolicyDelete(d *schema.ResourceData, meta interface{}) error {
108124
c := meta.(*Client)
109-
return c.DeletePasswordPolicy()
125+
return c.ResetPasswordPolicy()
110126
}
111127

112128
func resourceSumologicPasswordPolicyUpdate(d *schema.ResourceData, meta interface{}) error {

sumologic/resource_sumologic_password_policy_test.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func testAccCheckPasswordPolicyDestroy() resource.TestCheckFunc {
112112
return fmt.Errorf("Encountered an error: " + err.Error())
113113
}
114114

115-
if (*passwordPolicy) != newDefaultPasswordPolicy() {
115+
if (*passwordPolicy) != DefaultPasswordPolicy {
116116
return fmt.Errorf("Password policy wasn't reset properly")
117117
}
118118
}
@@ -182,21 +182,3 @@ resource "sumologic_password_policy" "%s" {
182182
passwordPolicy.RequireMfa,
183183
passwordPolicy.RememberMfa)
184184
}
185-
186-
func newDefaultPasswordPolicy() PasswordPolicy {
187-
return PasswordPolicy{
188-
MinLength: 8,
189-
MaxLength: 128,
190-
MustContainLowercase: true,
191-
MustContainUppercase: true,
192-
MustContainDigits: true,
193-
MustContainSpecialChars: true,
194-
MaxPasswordAgeInDays: 365,
195-
MinUniquePasswords: 10,
196-
AccountLockoutThreshold: 6,
197-
FailedLoginResetDurationInMins: 10,
198-
AccountLockoutDurationInMins: 30,
199-
RequireMfa: false,
200-
RememberMfa: true,
201-
}
202-
}

sumologic/sumologic_password_policy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (s *Client) GetPasswordPolicy() (*PasswordPolicy, error) {
2121
return &passwordPolicy, nil
2222
}
2323

24-
func (s *Client) DeletePasswordPolicy() error {
24+
func (s *Client) ResetPasswordPolicy() error {
2525
url := "v1/passwordPolicy"
2626

2727
// Since password policy cannot be deleted, we just reset it back to the default by passing an empty request body.

0 commit comments

Comments
 (0)