Skip to content

Commit 97985f7

Browse files
authored
Merge pull request #500 from acch/499-security-account-locked
fix: allow unlocking existing `security_account` resources
2 parents 974c84a + 26b654a commit 97985f7

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ DOCUMENTATION:
66

77
BUG FIXES:
88

9+
- **netapp-ontap_security_account**: unable to unlock existing `security_account` resource ([#499](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/499))
910
- **netapp-ontap_port**: fixed error when importing VLANs in multi-node clusters ([#479](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/479))
1011
- **netapp-ontap_san_igroup**: fixed issue with adding initiators to new igroup ([#274](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/274))
1112

internal/interfaces/security_account.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type SecurityAccountResourceBodyDataModelONTAP struct {
1717
Role SecurityAccountRole `mapstructure:"role,omitempty"`
1818
Password string `mapstructure:"password,omitempty"`
1919
Comment string `mapstructure:"comment,omitempty"`
20-
Locked bool `mapstructure:"locked,omitempty"`
20+
Locked *bool `mapstructure:"locked,omitempty"`
2121
}
2222

2323
// SecurityAccountGetDataModelONTAP describes the GET record data model using go types for mapping.
@@ -38,7 +38,7 @@ type SecurityAccountResourceUpdateBodyDataModelONTAP struct {
3838
Role SecurityAccountRole `mapstructure:"role,omitempty"`
3939
Password string `mapstructure:"password,omitempty"`
4040
Comment string `mapstructure:"comment,omitempty"`
41-
Locked bool `mapstructure:"locked,omitempty"`
41+
Locked *bool `mapstructure:"locked,omitempty"`
4242
}
4343

4444
// SecurityAccountApplication describes the application data model using go types for mapping.

internal/provider/security/security_account_resource.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"github.com/hashicorp/terraform-plugin-framework/path"
1010
"github.com/hashicorp/terraform-plugin-framework/resource"
1111
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
12-
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
13-
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
1412
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1513
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
1614
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
@@ -166,8 +164,6 @@ func (r *SecurityAccountResource) Schema(ctx context.Context, req resource.Schem
166164
MarkdownDescription: "Account locked",
167165
Optional: true,
168166
Computed: true,
169-
Default: booldefault.StaticBool(false),
170-
PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()},
171167
},
172168
"id": schema.StringAttribute{
173169
MarkdownDescription: "SecurityAccount id",
@@ -346,7 +342,7 @@ func (r *SecurityAccountResource) Create(ctx context.Context, req resource.Creat
346342
body.Comment = data.Comment.ValueString()
347343
}
348344
if !data.Locked.IsNull() {
349-
body.Locked = data.Locked.ValueBool()
345+
body.Locked = data.Locked.ValueBoolPointer()
350346
}
351347

352348
client, err := connection.GetRestClient(errorHandler, r.config, data.CxProfileName)
@@ -410,6 +406,7 @@ func (r *SecurityAccountResource) Create(ctx context.Context, req resource.Creat
410406

411407
data.ID = types.StringValue(resource.Name)
412408
data.OwnerID = types.StringValue(resource.Owner.UUID)
409+
data.Locked = types.BoolValue(resource.Locked)
413410

414411
tflog.Trace(ctx, "created a resource")
415412

@@ -472,7 +469,7 @@ func (r *SecurityAccountResource) Update(ctx context.Context, req resource.Updat
472469

473470
// locked update
474471
if !plan.Locked.IsNull() {
475-
request.Locked = plan.Locked.ValueBool()
472+
request.Locked = plan.Locked.ValueBoolPointer()
476473
}
477474

478475
// comment update

internal/provider/security/security_account_resource_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,27 @@ func TestAccSecurityAccountResource(t *testing.T) {
2020
Check: resource.ComposeTestCheckFunc(
2121
resource.TestCheckResourceAttr("netapp-ontap_security_account.security_account", "name", "tf_acc_test"),
2222
resource.TestCheckResourceAttr("netapp-ontap_security_account.security_account", "password", "password123"),
23+
resource.TestCheckResourceAttr("netapp-ontap_security_account.security_account", "locked", "false"),
2324
),
2425
},
2526
// Test updating a resource with comment and locked
2627
{
27-
Config: testAccSecurityAccountResourceConfig("tf_acc_test", "update", true),
28+
Config: testAccSecurityAccountResourceConfig("tf_acc_test", "locked", true),
2829
Check: resource.ComposeTestCheckFunc(
2930
resource.TestCheckResourceAttr("netapp-ontap_security_account.security_account", "name", "tf_acc_test"),
30-
resource.TestCheckResourceAttr("netapp-ontap_security_account.security_account", "comment", "update"),
31+
resource.TestCheckResourceAttr("netapp-ontap_security_account.security_account", "comment", "locked"),
3132
resource.TestCheckResourceAttr("netapp-ontap_security_account.security_account", "locked", "true"),
3233
),
3334
},
35+
// Test updating a resource with comment and unlocked
36+
{
37+
Config: testAccSecurityAccountResourceConfig("tf_acc_test", "unlocked", false),
38+
Check: resource.ComposeTestCheckFunc(
39+
resource.TestCheckResourceAttr("netapp-ontap_security_account.security_account", "name", "tf_acc_test"),
40+
resource.TestCheckResourceAttr("netapp-ontap_security_account.security_account", "comment", "unlocked"),
41+
resource.TestCheckResourceAttr("netapp-ontap_security_account.security_account", "locked", "false"),
42+
),
43+
},
3444
// Test updating a resource with application and secondAuthenticationMethod
3545
{
3646
Config: testAccSecurityAccountResourceConfigUpdateAndCheckIdempotency("tf_acc_test"),

0 commit comments

Comments
 (0)