-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from NetApp/55-new-data-source-protocolscifsl…
…ocal-users 55 new data source protocolscifslocal users
- Loading branch information
Showing
21 changed files
with
659 additions
and
20 deletions.
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
47 changes: 47 additions & 0 deletions
47
docs/data-sources/netapp-ontap_protocols_cifs_local_user_data_source.md
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,47 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "netapp-ontap_protocols_cifs_local_user_data_source Data Source - terraform-provider-netapp-ontap" | ||
subcategory: "nas" | ||
description: |- | ||
Retrieve CifsLocalUser data source | ||
--- | ||
|
||
# Data Source netapp-ontap_protocols_cifs_local_user | ||
|
||
Retreives protocols cifs local user configuration | ||
|
||
## Example Usage | ||
```terraform | ||
data "netapp-ontap_protocols_cifs_local_user_data_source" "local_user" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
svm_name = "svm3" | ||
name = "test" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `cx_profile_name` (String) Connection profile name | ||
- `name` (String) CifsLocalUser name | ||
- `svm_name` (String) IPInterface svm name | ||
|
||
### Read-Only | ||
|
||
- `account_disabled` (Boolean) CifsLocalUser account disabled | ||
- `description` (String) CifsLocalUser description | ||
- `full_name` (String) CifsLocalUser full name | ||
- `id` (String) CifsLocalUser id | ||
- `membership` (Attributes List) CifsLocalUser membership (see [below for nested schema](#nestedatt--membership)) | ||
|
||
<a id="nestedatt--membership"></a> | ||
### Nested Schema for `membership` | ||
|
||
Read-Only: | ||
|
||
- `name` (String) CifsLocalUser membership name | ||
|
||
|
72 changes: 72 additions & 0 deletions
72
docs/data-sources/netapp-ontap_protocols_cifs_local_users_data_source.md
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,72 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "netapp-ontap_protocols_cifs_local_users_data_source Data Source - terraform-provider-netapp-ontap" | ||
subcategory: "nas" | ||
description: |- | ||
Retrieves list of Cifs Local Users. | ||
--- | ||
|
||
# Data Source protocols_cifs_local_users | ||
|
||
Retrieves a list of Cifs Local Users. | ||
|
||
## Example Usage | ||
```terraform | ||
data "netapp-ontap_protocols_cifs_local_users_data_source" "protocols_cifs_local_users" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
filter = { | ||
svm_name = "svm*" | ||
} | ||
} | ||
``` | ||
|
||
<!-- 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 | ||
|
||
- `protocols_cifs_local_users` (Attributes List) Protocols CIFS local users (see [below for nested schema](#nestedatt--protocols_cifs_local_users)) | ||
|
||
<a id="nestedatt--filter"></a> | ||
### Nested Schema for `filter` | ||
|
||
Optional: | ||
|
||
- `name` (String) CifsLocalUser name | ||
- `svm_name` (String) CifsLocalUser svm name | ||
|
||
|
||
<a id="nestedatt--protocols_cifs_local_users"></a> | ||
### Nested Schema for `protocols_cifs_local_users` | ||
|
||
Required: | ||
|
||
- `cx_profile_name` (String) Connection profile name | ||
- `name` (String) CifsLocalUser name | ||
|
||
Read-Only: | ||
|
||
- `account_disabled` (Boolean) CifsLocalUser account disabled | ||
- `description` (String) CifsLocalUser description | ||
- `full_name` (String) CifsLocalUser full name | ||
- `id` (String) CifsLocalUser id | ||
- `membership` (Attributes List) CifsLocalUser membership (see [below for nested schema](#nestedatt--protocols_cifs_local_users--membership)) | ||
- `svm_name` (String) CifsLocalUser svm name | ||
|
||
<a id="nestedatt--protocols_cifs_local_users--membership"></a> | ||
### Nested Schema for `protocols_cifs_local_users.membership` | ||
|
||
Read-Only: | ||
|
||
- `name` (String) CifsLocalUser membership name | ||
|
||
|
6 changes: 6 additions & 0 deletions
6
examples/data-sources/netapp-ontap_protocols_cifs_local_user/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,6 @@ | ||
data "netapp-ontap_protocols_cifs_local_user_data_source" "protocols_cifs_local_user" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
svm_name = "svm1" | ||
name = "testme" | ||
} |
1 change: 1 addition & 0 deletions
1
examples/data-sources/netapp-ontap_protocols_cifs_local_user/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_protocols_cifs_local_user/terraform.tfvars
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/terraform.tfvars |
1 change: 1 addition & 0 deletions
1
examples/data-sources/netapp-ontap_protocols_cifs_local_user/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 |
8 changes: 8 additions & 0 deletions
8
examples/data-sources/netapp-ontap_protocols_cifs_local_users/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,8 @@ | ||
data "netapp-ontap_protocols_cifs_local_users_data_source" "protocols_cifs_local_users" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
filter = { | ||
name = "user1" | ||
svm_name = "svm*" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
examples/data-sources/netapp-ontap_protocols_cifs_local_users/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_protocols_cifs_local_users/terraform.tfvars
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/terraform.tfvars |
1 change: 1 addition & 0 deletions
1
examples/data-sources/netapp-ontap_protocols_cifs_local_users/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,129 @@ | ||
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" | ||
) | ||
|
||
// CifsLocalUserGetDataModelONTAP describes the GET record data model using go types for mapping. | ||
type CifsLocalUserGetDataModelONTAP struct { | ||
Name string `mapstructure:"name"` | ||
SID string `mapstructure:"sid"` | ||
SVM svm `mapstructure:"svm"` | ||
FullName string `mapstructure:"full_name"` | ||
Description string `mapstructure:"description"` | ||
Membership []membership `mapstructure:"membership"` | ||
AccountDisabled bool `mapstructure:"account_disabled"` | ||
} | ||
|
||
// Membership describes the membership data model using go types for mapping. | ||
type membership struct { | ||
Name string `mapstructure:"name"` | ||
} | ||
|
||
// CifsLocalUserDataSourceFilterModel describes the data source data model for queries. | ||
type CifsLocalUserDataSourceFilterModel struct { | ||
Name string `mapstructure:"name"` | ||
SVMName string `mapstructure:"svm.name"` | ||
} | ||
|
||
// CifsLocalUserResourceBodyDataModelONTAP describes the body data model using go types for mapping. | ||
type CifsLocalUserResourceBodyDataModelONTAP struct { | ||
Name string `mapstructure:"name"` | ||
SVM svm `mapstructure:"svm"` | ||
} | ||
|
||
// GetCifsLocalUserByName to get protocols_cifs_local_user info | ||
func GetCifsLocalUserByName(errorHandler *utils.ErrorHandler, r restclient.RestClient, name string, svmName string) (*CifsLocalUserGetDataModelONTAP, error) { | ||
api := "protocols/cifs/local-users" | ||
query := r.NewQuery() | ||
query.Set("name", name) | ||
query.Set("svm.name", svmName) | ||
|
||
query.Fields([]string{"name", "svm.name", "full_name", "description", "membership", "account_disabled"}) | ||
statusCode, response, err := r.GetNilOrOneRecord(api, query, nil) | ||
if err == nil && response == nil { | ||
err = fmt.Errorf("no response for GET %s", api) | ||
} | ||
if err != nil { | ||
return nil, errorHandler.MakeAndReportError("error reading protocols_cifs_local_user info", fmt.Sprintf("error on GET %s: %s, statusCode %d", api, err, statusCode)) | ||
} | ||
|
||
var dataONTAP CifsLocalUserGetDataModelONTAP | ||
if err := mapstructure.Decode(response, &dataONTAP); err != nil { | ||
return nil, errorHandler.MakeAndReportError(fmt.Sprintf("failed to decode response from GET %s", api), | ||
fmt.Sprintf("error: %s, statusCode %d, response %#v", err, statusCode, response)) | ||
} | ||
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read protocols_cifs_local_user data source: %#v", dataONTAP)) | ||
return &dataONTAP, nil | ||
} | ||
|
||
// GetCifsLocalUsers to get protocols_cifs_local_user info for all resources matching a filter | ||
func GetCifsLocalUsers(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter *CifsLocalUserDataSourceFilterModel) ([]CifsLocalUserGetDataModelONTAP, error) { | ||
api := "protocols/cifs/local-users" | ||
query := r.NewQuery() | ||
query.Fields([]string{"name", "svm.name", "full_name", "description", "membership", "account_disabled"}) | ||
|
||
if filter != nil { | ||
var filterMap map[string]interface{} | ||
if err := mapstructure.Decode(filter, &filterMap); err != nil { | ||
return nil, errorHandler.MakeAndReportError("error encoding protocols_cifs_local_users filter info", fmt.Sprintf("error on filter %#v: %s", filter, err)) | ||
} | ||
query.SetValues(filterMap) | ||
} | ||
statusCode, response, err := r.GetZeroOrMoreRecords(api, query, nil) | ||
if err == nil && response == nil { | ||
err = fmt.Errorf("no response for GET %s", api) | ||
} | ||
if err != nil { | ||
return nil, errorHandler.MakeAndReportError("error reading protocols_cifs_local_users info", fmt.Sprintf("error on GET %s: %s, statusCode %d", api, err, statusCode)) | ||
} | ||
|
||
var dataONTAP []CifsLocalUserGetDataModelONTAP | ||
for _, info := range response { | ||
var record CifsLocalUserGetDataModelONTAP | ||
if err := mapstructure.Decode(info, &record); err != nil { | ||
return nil, errorHandler.MakeAndReportError(fmt.Sprintf("failed to decode response from GET %s", api), | ||
fmt.Sprintf("error: %s, statusCode %d, info %#v", err, statusCode, info)) | ||
} | ||
dataONTAP = append(dataONTAP, record) | ||
} | ||
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read protocols_cifs_local_users data source: %#v", dataONTAP)) | ||
return dataONTAP, nil | ||
} | ||
|
||
// CreateCifsLocalUser to create protocols_cifs_local_user | ||
func CreateCifsLocalUser(errorHandler *utils.ErrorHandler, r restclient.RestClient, body CifsLocalUserResourceBodyDataModelONTAP) (*CifsLocalUserGetDataModelONTAP, error) { | ||
api := "protocols/cifs/local-users" | ||
var bodyMap map[string]interface{} | ||
if err := mapstructure.Decode(body, &bodyMap); err != nil { | ||
return nil, errorHandler.MakeAndReportError("error encoding protocols_cifs_local_user body", fmt.Sprintf("error on encoding %s body: %s, body: %#v", api, err, body)) | ||
} | ||
query := r.NewQuery() | ||
query.Add("return_records", "true") | ||
statusCode, response, err := r.CallCreateMethod(api, query, bodyMap) | ||
if err != nil { | ||
return nil, errorHandler.MakeAndReportError("error creating protocols_cifs_local_user", fmt.Sprintf("error on POST %s: %s, statusCode %d", api, err, statusCode)) | ||
} | ||
|
||
var dataONTAP CifsLocalUserGetDataModelONTAP | ||
if err := mapstructure.Decode(response.Records[0], &dataONTAP); err != nil { | ||
return nil, errorHandler.MakeAndReportError("error decoding protocols_cifs_local_user info", fmt.Sprintf("error on decode storage/protocols_cifs_local_users info: %s, statusCode %d, response %#v", err, statusCode, response)) | ||
} | ||
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Create protocols_cifs_local_user source - udata: %#v", dataONTAP)) | ||
return &dataONTAP, nil | ||
} | ||
|
||
// DeleteCifsLocalUser to delete protocols_cifs_local_user | ||
func DeleteCifsLocalUser(errorHandler *utils.ErrorHandler, r restclient.RestClient, uuid string) error { | ||
api := "protocols/cifs/local-users" | ||
statusCode, _, err := r.CallDeleteMethod(api+"/"+uuid, nil, nil) | ||
if err != nil { | ||
return errorHandler.MakeAndReportError("error deleting protocols_cifs_local_user", fmt.Sprintf("error on DELETE %s: %s, statusCode %d", api, err, statusCode)) | ||
} | ||
return 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.