Skip to content

Commit 2826569

Browse files
authored
Merge pull request #460 from acch/457-import-security_account
Set `owner` (SVM) when importing `security_account` resource
2 parents 4376651 + f5bd7e6 commit 2826569

5 files changed

Lines changed: 22 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ ENHANCEMENTS:
44

55
- **netapp-ontap_aggregate_data_source**, **netapp-ontap_aggregates_data_source**: added `space.block_storage.available` option ([#256](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/256))
66

7+
BUG FIXES:
8+
9+
- **netapp-ontap_security_account**: Error importing security_account resource if same account exists on multiple SVMs([#457](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/457))
10+
711
# 2.1.2 (not released)
812

913
BUG FIXES:

docs/resources/security_account.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Create/Modify/Delete a ONTAP user account
2323

2424
## Supported Platforms
2525

26-
* On-prem ONTAP system 9.6 or higher
27-
* Amazon FSx for NetApp ONTAP
26+
- On-prem ONTAP system 9.6 or higher
27+
- Amazon FSx for NetApp ONTAP
2828

2929
## Example Usage
3030

@@ -43,6 +43,7 @@ resource "netapp-ontap_security_account" "security_account" {
4343
```
4444

4545
<!-- schema generated by tfplugindocs -->
46+
4647
## Schema
4748

4849
### Required
@@ -96,17 +97,17 @@ Optional:
9697
## Import
9798

9899
This resource supports import, which allows you to import existing security account into the state of this resource.
99-
Import require a unique ID composed of the security account name and connection profile, separated by a comma.
100+
Import require a unique ID composed of the security account name, SVM name, and connection profile, separated by a comma.
100101

101-
id = `name`, `cx_profile_name`
102+
id = `name`,`svm`,`cx_profile_name`
102103

103104
### Terraform Import
104105

105-
For example
106+
For example
106107

107-
```shell
108-
terraform import netapp-ontap_security_account.act_import acc_user,cluster4
109-
```
108+
```shell
109+
terraform import netapp-ontap_security_account.act_import acc_user,acc_svm,cluster4
110+
```
110111

111112
### Terraform Import Block
112113

@@ -117,7 +118,7 @@ First create the block
117118
```terraform
118119
import {
119120
to = netapp-ontap_security_account.act_import
120-
id = "acc_user,cluster4"
121+
id = "acc_user,acc_svm,cluster4"
121122
}
122123
```
123124

@@ -132,7 +133,7 @@ This will generate a file called generated.tf, which will contain the configurat
132133
```terraform
133134
# __generated__ by Terraform
134135
# Please review these resources and move them into your main configuration files.
135-
# __generated__ by Terraform from "acc_user,cluster4"
136+
# __generated__ by Terraform from "acc_user,acc_svm,cluster4"
136137
resource "netapp-ontap_security_account" "act_import" {
137138
cx_profile_name = "cluster4"
138139
name = "acc_user"
@@ -146,7 +147,7 @@ resource "netapp-ontap_security_account" "act_import" {
146147
comment = null
147148
locked = false
148149
owner = {
149-
name = "abccluster-1"
150+
name = "acc_svm"
150151
}
151152
password = null # sensitive
152153
role = {

internal/provider/security/security_account_resource.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,14 +561,15 @@ func (r *SecurityAccountResource) ImportState(ctx context.Context, req resource.
561561
tflog.Debug(ctx, fmt.Sprintf("import req security account resource: %#v", req))
562562
// Parse the ID
563563
idParts := strings.Split(req.ID, ",")
564-
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
564+
if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" {
565565
resp.Diagnostics.AddError(
566566
"Unexpected Import Identifier",
567-
fmt.Sprint("Expected ID in the format 'name,cx_profile_name', got: ", req.ID),
567+
fmt.Sprint("Expected ID in the format 'name,svm,cx_profile_name', got: ", req.ID),
568568
)
569569
return
570570
}
571571

572572
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), idParts[0])...)
573-
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("cx_profile_name"), idParts[1])...)
573+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("owner").AtName("name"), idParts[1])...)
574+
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("cx_profile_name"), idParts[2])...)
574575
}

internal/provider/security/security_account_resource_alias_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestAccSecurityAccountResourceAlias(t *testing.T) {
2626
{
2727
ResourceName: "netapp-ontap_security_account_resource.security_account",
2828
ImportState: true,
29-
ImportStateId: fmt.Sprintf("%s,%s", "vsadmin", "cluster2"),
29+
ImportStateId: fmt.Sprintf("%s,%s,%s", "vsadmin", "tf_acc_svm", "cluster2"),
3030
Check: resource.ComposeTestCheckFunc(
3131
resource.TestCheckResourceAttr("netapp-ontap_security_account_resource.security_account", "name", "vsadmin"),
3232
),

internal/provider/security/security_account_resource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestAccSecurityAccountResource(t *testing.T) {
5353
{
5454
ResourceName: "netapp-ontap_security_account.security_account",
5555
ImportState: true,
56-
ImportStateId: fmt.Sprintf("%s,%s", "vsadmin", "cluster2"),
56+
ImportStateId: fmt.Sprintf("%s,%s,%s", "vsadmin", "tf_acc_svm", "cluster2"),
5757
Check: resource.ComposeTestCheckFunc(
5858
resource.TestCheckResourceAttr("netapp-ontap_security_account.security_account", "name", "vsadmin"),
5959
),

0 commit comments

Comments
 (0)