-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
22 new data source security account #114
Merged
carchi8py
merged 15 commits into
integration/main
from
22-new-data-source-security_account
Jan 24, 2024
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2dd831f
Add account skeleton
carchi8py b252be9
woring single security account with out application
carchi8py fe3706c
getting application to work
carchi8py ebfb484
save
carchi8py 14a19ad
Merge branch '50-new-data-source-clusterpeers' into 22-new-data-sourc…
carchi8py a314b50
updates
carchi8py 55c8ec7
working accounts
carchi8py 15e9f51
Merge branch 'integration/main' into 22-new-data-source-security_account
carchi8py 3118c69
add data source for accounts
carchi8py b731809
fix lint issues
carchi8py e222f88
fixes
carchi8py 9c3fefd
add cluster scopped users
carchi8py f461222
fixes
carchi8py 37ec925
update
carchi8py ebf573b
Merge branch 'integration/main' into 22-new-data-source-security_account
carchi8py File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "netapp-ontap_security_account_data_source Data Source - terraform-provider-netapp-ontap" | ||
subcategory: "Security" | ||
description: |- | ||
Retrieves a ONTAP User | ||
--- | ||
|
||
# Data Source Security_Account | ||
|
||
Retrieves a ONTAP User | ||
|
||
## Example Usage | ||
```terraform | ||
data "netapp-ontap_security_account_data_source" "security_accounts" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
owner = { | ||
name = "ansibleSVM" | ||
} | ||
name = "vsadmin" | ||
} | ||
``` | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `cx_profile_name` (String) Connection profile name | ||
- `name` (String) SecurityAccount name | ||
|
||
### Optional | ||
|
||
- `owner` (Attributes) SecurityAccount owner (see [below for nested schema](#nestedatt--owner)) | ||
|
||
### Read-Only | ||
|
||
- `applications` (Attributes List) SecurityAccount applications (see [below for nested schema](#nestedatt--applications)) | ||
- `comment` (String) SecurityAccount comment | ||
- `id` (String) SecurityAccount id | ||
- `locked` (Boolean) SecurityAccount locked | ||
- `role` (Attributes) SecurityAccount role (see [below for nested schema](#nestedatt--role)) | ||
- `scope` (String) SecurityAccount scope | ||
|
||
<a id="nestedatt--owner"></a> | ||
### Nested Schema for `owner` | ||
|
||
Required: | ||
|
||
- `name` (String) SecurityAccount owner name | ||
|
||
Read-Only: | ||
|
||
- `uuid` (String) SecurityAccount owner uuid | ||
|
||
|
||
<a id="nestedatt--applications"></a> | ||
### Nested Schema for `applications` | ||
|
||
Read-Only: | ||
|
||
- `application` (String) SecurityAccount application | ||
- `authentication_methods` (List of String) SecurityAccount authentication methods | ||
- `second_authentication_method` (String) SecurityAccount second authentication method | ||
|
||
|
||
<a id="nestedatt--role"></a> | ||
### Nested Schema for `role` | ||
|
||
Read-Only: | ||
|
||
- `name` (String) SecurityAccount role name | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "netapp-ontap_security_accounts_data_source Data Source - terraform-provider-netapp-ontap" | ||
subcategory: "Security" | ||
description: |- | ||
Retrieves the configuration of multiple user accounts | ||
--- | ||
|
||
# Data Source Security Accounts | ||
|
||
Retrieves the configuration of multiple user accounts | ||
|
||
## Example Usage | ||
```terraform | ||
data "netapp-ontap_security_accounts_data_source" "security_accounts" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
filter = { | ||
name = "vsadmin" | ||
svm_name = "testImport" | ||
} | ||
} | ||
``` | ||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `cx_profile_name` (String) Connection profile name | ||
|
||
### Optional | ||
|
||
- `filter` (Attributes) (see [below for nested schema](#nestedatt--filter)) | ||
|
||
### Read-Only | ||
|
||
- `security_accounts` (Attributes List) (see [below for nested schema](#nestedatt--security_accounts)) | ||
|
||
<a id="nestedatt--filter"></a> | ||
### Nested Schema for `filter` | ||
|
||
Optional: | ||
|
||
- `name` (String) SecurityAccount name | ||
- `svm_name` (String) SecurityAccount svm name (Owner name) | ||
|
||
|
||
<a id="nestedatt--security_accounts"></a> | ||
### Nested Schema for `security_accounts` | ||
|
||
Required: | ||
|
||
- `cx_profile_name` (String) Connection profile name | ||
- `name` (String) SecurityAccount name | ||
|
||
Read-Only: | ||
|
||
- `applications` (Attributes List) SecurityAccount applications (see [below for nested schema](#nestedatt--security_accounts--applications)) | ||
- `comment` (String) SecurityAccount comment | ||
- `id` (String) SecurityAccount id | ||
- `locked` (Boolean) SecurityAccount locked | ||
- `owner` (Attributes) SecurityAccount owner (see [below for nested schema](#nestedatt--security_accounts--owner)) | ||
- `role` (Attributes) SecurityAccount role (see [below for nested schema](#nestedatt--security_accounts--role)) | ||
- `scope` (String) SecurityAccount scope | ||
|
||
<a id="nestedatt--security_accounts--applications"></a> | ||
### Nested Schema for `security_accounts.applications` | ||
|
||
Read-Only: | ||
|
||
- `application` (String) SecurityAccount application | ||
- `authentication_methods` (List of String) SecurityAccount authentication methods | ||
- `second_authentication_method` (String) SecurityAccount second authentication method | ||
|
||
|
||
<a id="nestedatt--security_accounts--owner"></a> | ||
### Nested Schema for `security_accounts.owner` | ||
|
||
Read-Only: | ||
|
||
- `name` (String) SecurityAccount owner name | ||
- `uuid` (String) SecurityAccount owner uuid | ||
|
||
|
||
<a id="nestedatt--security_accounts--role"></a> | ||
### Nested Schema for `security_accounts.role` | ||
|
||
Read-Only: | ||
|
||
- `name` (String) SecurityAccount role name | ||
|
||
|
21 changes: 21 additions & 0 deletions
21
examples/data-sources/netapp-ontap_security_account/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
data "netapp-ontap_security_account_data_source" "security_accounts" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
scope = "cluster" | ||
name = "admin" | ||
} | ||
|
||
data "netapp-ontap_security_account_data_source" "security_accounts2" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
name = "admin" | ||
} | ||
|
||
data "netapp-ontap_security_account_data_source" "security_accounts3" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
owner = { | ||
name = "carchi-test" | ||
} | ||
name = "vsadmin" | ||
} |
1 change: 1 addition & 0 deletions
1
examples/data-sources/netapp-ontap_security_account/provider.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../provider/provider.tf |
1 change: 1 addition & 0 deletions
1
examples/data-sources/netapp-ontap_security_account/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../provider/variables.tf |
33 changes: 33 additions & 0 deletions
33
examples/data-sources/netapp-ontap_security_accounts/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
data "netapp-ontap_security_accounts_data_source" "security_accounts" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
filter = { | ||
name = "admin" | ||
} | ||
} | ||
|
||
data "netapp-ontap_security_accounts_data_source" "security_accounts2" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
filter = { | ||
name = "a*" | ||
} | ||
} | ||
|
||
data "netapp-ontap_security_accounts_data_source" "security_accounts3" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
filter = { | ||
name = "vsadmin" | ||
} | ||
} | ||
|
||
data "netapp-ontap_security_accounts_data_source" "security_accounts4" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
filter = { | ||
name = "vsadmin" | ||
svm_name = "carchi-test" | ||
} | ||
} | ||
|
1 change: 1 addition & 0 deletions
1
examples/data-sources/netapp-ontap_security_accounts/provider.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../provider/provider.tf |
1 change: 1 addition & 0 deletions
1
examples/data-sources/netapp-ontap_security_accounts/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../provider/variables.tf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package interfaces | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
"github.com/mitchellh/mapstructure" | ||
"github.com/netapp/terraform-provider-netapp-ontap/internal/restclient" | ||
"github.com/netapp/terraform-provider-netapp-ontap/internal/utils" | ||
) | ||
|
||
// SecurityAccountGetDataModelONTAP describes the GET record data model using go types for mapping. | ||
type SecurityAccountGetDataModelONTAP struct { | ||
Name string `mapstructure:"name"` | ||
Owner SecurityAccountOwner `mapstructure:"owner,omitempty"` | ||
Locked bool `mapstructure:"locked,omitempty"` | ||
Comment string `mapstructure:"comment,omitempty"` | ||
Role SecurityAccountRole `mapstructure:"role,omitempty"` | ||
Scope string `mapstructure:"scope,omitempty"` | ||
Applications []SecurityAccountApplication `mapstructure:"applications,omitempty"` | ||
} | ||
|
||
// SecurityAccountApplication describes the application data model using go types for mapping. | ||
type SecurityAccountApplication struct { | ||
Application string `mapstructure:"application,omitempty"` | ||
SecondAuthenticationMethod string `mapstructure:"second_authentication_method,omitempty"` | ||
AuthenticationMethods []string `mapstructure:"authentication_methods,omitempty"` | ||
} | ||
|
||
// SecurityAccountRole describes the role data model using go types for mapping. | ||
type SecurityAccountRole struct { | ||
Name string `mapstructure:"name,omitempty"` | ||
} | ||
|
||
// SecurityAccountOwner describes the owner data model using go types for mapping. | ||
type SecurityAccountOwner struct { | ||
Name string `mapstructure:"name,omitempty"` | ||
UUID string `mapstructure:"uuid,omitempty"` | ||
} | ||
|
||
// SecurityAccountDataSourceFilterModel describes the data source filter data model. | ||
type SecurityAccountDataSourceFilterModel struct { | ||
Name string `mapstructure:"name"` | ||
Owner *SecurityAccountOwner `mapstructure:"owner,omitempty"` | ||
} | ||
|
||
// GetSecurityAccountByName gets a security account by name. | ||
func GetSecurityAccountByName(errorHandler *utils.ErrorHandler, r restclient.RestClient, name string, ownerName string) (*SecurityAccountGetDataModelONTAP, error) { | ||
query := r.NewQuery() | ||
query.Fields([]string{"name", "owner", "locked", "comment", "role", "scope", "applications"}) | ||
query.Set("name", name) | ||
var err error | ||
var response map[string]interface{} | ||
var statusCode int | ||
if ownerName != "" { | ||
statusCode, response, err = r.GetNilOrOneRecord("security/accounts/"+ownerName+"/"+name, query, nil) | ||
} else { | ||
query.Set("scope", "cluster") | ||
statusCode, response, err = r.GetNilOrOneRecord("security/accounts/", query, nil) | ||
} | ||
if err != nil { | ||
return nil, errorHandler.MakeAndReportError("Error occurred when getting security account", fmt.Sprintf("error on get security/account: %s", err)) | ||
} | ||
if response == nil { | ||
return nil, errorHandler.MakeAndReportError("No Account found", fmt.Sprintf("No account with name: %s", name)) | ||
} | ||
var dataOntap *SecurityAccountGetDataModelONTAP | ||
if error := mapstructure.Decode(response, &dataOntap); error != nil { | ||
return nil, errorHandler.MakeAndReportError("Error occurred when decoding security account", fmt.Sprintf("error on decoding security/account: %s, statusCode: %d, response %+v", error, statusCode, response)) | ||
} | ||
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("security account: %+v", dataOntap)) | ||
return dataOntap, nil | ||
} | ||
|
||
// GetSecurityAccounts gets all security accounts. | ||
func GetSecurityAccounts(errorHandler *utils.ErrorHandler, r restclient.RestClient, svnName string, name string) ([]SecurityAccountGetDataModelONTAP, error) { | ||
query := r.NewQuery() | ||
query.Fields([]string{"name", "owner", "locked", "comment", "role", "scope", "applications"}) | ||
if svnName != "" { | ||
query.Set("owner.name", svnName) | ||
} | ||
if name != "" { | ||
query.Set("name", name) | ||
} | ||
|
||
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("security account filter: %+v", query)) | ||
statusCode, response, err := r.GetZeroOrMoreRecords("security/accounts", query, nil) | ||
if err != nil { | ||
return nil, errorHandler.MakeAndReportError("Error occurred when getting security accounts", fmt.Sprintf("error on get security/accounts: %s", err)) | ||
} | ||
if response == nil { | ||
return nil, errorHandler.MakeAndReportError("No Accounts found", fmt.Sprintf("No accounts found")) | ||
} | ||
var dataOntap []SecurityAccountGetDataModelONTAP | ||
for _, info := range response { | ||
var dataOntapItem SecurityAccountGetDataModelONTAP | ||
if error := mapstructure.Decode(info, &dataOntapItem); error != nil { | ||
return nil, errorHandler.MakeAndReportError("Error occurred when decoding security account", fmt.Sprintf("error on decoding security/account: %s, statusCode: %d, response %+v", error, statusCode, response)) | ||
} | ||
dataOntap = append(dataOntap, dataOntapItem) | ||
} | ||
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("security accounts: %+v", dataOntap)) | ||
return dataOntap, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user only provides "name", then it will be multiple records.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there a way around that.