Skip to content
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

27 new resource protocolscifsshares #165

Merged
merged 21 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ FEATURES:
* **New Resource:** `netapp-ontap_protocols_san_lun-maps_resource` ([#13](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/13))
* **New Resource:** `netapp-ontap_name_services_ldap_resource` ([#25](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/25))
* **New Resource:** `netapp-ontap_protocols_cifs_service_resource` ([#23](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/23))
* **New Resource:** `netapp-ontap_protocols_cifs_share_resource` ([#27](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/27))
* **New Resource:** `netapp-ontap_protocols_san_igroup_resource` ([#9](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/9))


ENHANCEMENTS:
* **netapp-ontap_protocols_nfs_export_policy_resource**: Add support for import ([#34](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/34))
* **netapp-ontap_cluster_licensing_license_resource**: Add support for import ([#30](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/30))
Expand Down
114 changes: 114 additions & 0 deletions docs/resources/protocols_cifs_share_resource.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "netapp-ontap_protocols_cifs_share_resource Resource - terraform-provider-netapp-ontap"
subcategory: "Protocols"
description: |-
ProtocolsCIFSShare resource
---

# netapp-ontap_protocols_cifs_share_resource (Resource)

Create/Modify/Delete a protocols cifs share resource

### Related ONTAP commands
vserver cifs share create
vserver cifs share properties add
vserver cifs share access-control create

## Example Usage

```terraform
resource "netapp-ontap_protocols_cifs_share_resource" "protocols_cifs_share" {
# required to know which system to interface with
cx_profile_name = "cluster4"
name = "testme"
path = "/wenjun_vol"
svm_name = "ansibleSVM"
acls = [
{
"permission": "read",
"type": "windows",
"user_or_group": "Everyone"
}
]
comment = "abedf"
}
```


<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `cx_profile_name` (String) Connection profile name
- `name` (String) Specifies the name of the CIFS share that you want to create. If this
is a home directory share then the share name includes the pattern as
%w (Windows user name), %u (UNIX user name) and %d (Windows domain name)
variables in any combination with this parameter to generate shares dynamically.
- `svm_name` (String) svm name

### Optional

- `acls` (Attributes Set) The permissions that users and groups have on a CIFS share. (see [below for nested schema](#nestedatt--acls))
- `change_notify` (Boolean) Specifies whether CIFS clients can request for change notifications for directories on this share.
- `comment` (String) Specify the CIFS share descriptions.
- `continuously_available` (Boolean) Specifies whether or not the clients connecting to this share can open files in a persistent manner.Files opened in this way are protected from disruptive events, such as, failover and giveback.
- `dir_umask` (Number) Directory Mode Creation Mask to be viewed as an octal number.
- `encryption` (Boolean) Specifies that SMB encryption must be used when accessing this share. Clients that do not support encryption are not able to access this share.
- `file_umask` (Number) File Mode Creation Mask to be viewed as an octal number.
- `force_group_for_create` (String) Specifies that all files that CIFS users create in a specific share belong to the same group
(also called the force-group). The force-group must be a predefined group in the UNIX group
database. This setting has no effect unless the security style of the volume is UNIX or mixed
security style.
- `home_directory` (Boolean) Specifies whether or not the share is a home directory share, where the share and path names are dynamic.
ONTAP home directory functionality automatically offer each user a dynamic share to their home directory without creating an
individual SMB share for each user.
The ONTAP CIFS home directory feature enable us to configure a share that maps to
different directories based on the user that connects to it. Instead of creating a separate shares for each user,
a single share with a home directory parameters can be created.
In a home directory share, ONTAP dynamically generates the share-name and share-path by substituting
%w, %u, and %d variables with the corresponding Windows user name, UNIX user name, and domain name, respectively.
- `namespace_caching` (Boolean) Specifies whether or not the SMB clients connecting to this share can cache the directory enumeration
results returned by the CIFS servers.
- `no_strict_security` (Boolean) Specifies whether or not CIFS clients can follow a unix symlinks outside the share boundaries.
- `offline_files` (String) Offline Files. The supported values are:
none - Clients are not permitted to cache files for offline access.
manual - Clients may cache files that are explicitly selected by the user for offline access.
documents - Clients may automatically cache files that are used by the user for offline access.
programs - Clients may automatically cache files that are used by the user for offline access
and may use those files in an offline mode even if the share is available.
- `oplocks` (Boolean) Specify whether opportunistic locks are enabled on this share. "Oplocks" allow clients to lock files and cache content locally,
which can increase performance for file operations.
- `path` (String) The fully-qualified pathname in the owning SVM namespace that is shared through this share.
If this is a home directory share then the path should be dynamic by specifying the pattern
%w (Windows user name), %u (UNIX user name), or %d (domain name) variables in any combination.
ONTAP generates the path dynamically for the connected user and this path is appended to each
search path to find the full Home Directory path.
- `show_snapshot` (Boolean) Specifies whether or not the Snapshot copies can be viewed and traversed by clients.
- `unix_symlink` (String) Controls the access of UNIX symbolic links to CIFS clients.
The supported values are:
* local - Enables only local symbolic links which is within the same CIFS share.
* widelink - Enables both local symlinks and widelinks.
* disable - Disables local symlinks and widelinks.
- `vscan_profile` (String) Vscan File-Operations Profile
The supported values are:
no_scan - Virus scans are never triggered for accesses to this share.
standard - Virus scans can be triggered by open, close, and rename operations.
strict - Virus scans can be triggered by open, read, close, and rename operations.
writes_only - Virus scans can be triggered only when a file that has been modified is closed.

### Read-Only

- `id` (String) The UUID of the CIFS share.

<a id="nestedatt--acls"></a>
### Nested Schema for `acls`

Optional:

- `permission` (String) Specifies the access rights that a user or group has on the defined CIFS Share.
- `type` (String) string Specifies the type of the user or group to add to the access control list of a CIFS share.
- `user_or_group` (String) Specifies the user or group name to add to the access control list of a CIFS share.


Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resource "netapp-ontap_protocols_cifs_share_resource" "protocols_cifs_share" {
# required to know which system to interface with
cx_profile_name = "cluster4"
name = "testme"
path = "/wenjun_vol"
svm_name = "ansibleSVM"
acls = [
{
"permission": "read",
"type": "windows",
"user_or_group": "Everyone"
}
]
comment = "abedf"
}
89 changes: 64 additions & 25 deletions internal/interfaces/protocols_cifs_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,60 @@ type ProtocolsCIFSShareGetDataModelONTAP struct {
Name string `mapstructure:"name"`
UUID string `mapstructure:"uuid"`

Acls []Acls `mapstructure:"acls"`
Acls []AclsGet `mapstructure:"acls"`
ChangeNotify bool `mapstructure:"change_notify"`
Comment string `mapstructure:"comment"`
ContinuouslyAvailable bool `mapstructure:"continuously_available"`
DirUmask int64 `mapstructure:"dir_umask"`
Encryption bool `mapstructure:"encryption"`
FileUmask int64 `mapstructure:"file_umask"`
ForceGroupForCreate string `mapstructure:"force_group_for_create"`
HomeDirectory bool `mapstructure:"home_directory"`
NamespaceCaching bool `mapstructure:"namespace_caching"`
NoStrictSecurity bool `mapstructure:"no_strict_security"`
OfflineFiles string `mapstructure:"offline_files"`
Oplocks bool `mapstructure:"oplocks"`
Path string `mapstructure:"path"`
ShowSnapshot bool `mapstructure:"show_snapshot"`
UnixSymlink string `mapstructure:"unix_symlink"`
VscanProfile string `mapstructure:"vscan_profile"`
}

// Acls describes the acls data model using go types for mapping in ProtocolsCIFSShareResourceBodyDataModelONTAP.
type Acls struct {
Permission string `json:"permission"` // Because Acls is nested in ProtocolsCIFSShareResourceBodyDataModelONTAP, when it unmarshal from API to go struct, 'mapstructure' does not work, and result in "Permission" instead of "permission". So, we need to use "json" tag to map the field.
Type string `json:"type"`
UserOrGroup string `json:"user_or_group"`
}

// AclsGet describes the acls data model using go types for mapping in ProtocolsCIFSShareGetDataModelONTAP.
type AclsGet struct {
Permission string `mapstructure:"permission"` // ProtocolsCIFSShareGetDataModelONTAP needs 'mapstructure'
Type string `mapstructure:"type"`
UserOrGroup string `mapstructure:"user_or_group"`
}

// ProtocolsCIFSShareResourceBodyDataModelONTAP describes the body data model using go types for mapping.
type ProtocolsCIFSShareResourceBodyDataModelONTAP struct {
Name string `mapstructure:"name,omitempty"` // can't be present in update, so omit empty.
SVM svm `mapstructure:"svm"`
Acls []Acls `mapstructure:"acls,omitempty"` // API complains if this is not omit empty
ChangeNotify bool `mapstructure:"change_notify"`
Comment string `mapstructure:"comment"`
Comment string `mapstructure:"comment,omitempty"` // API complains if this is not omit empty
ContinuouslyAvailable bool `mapstructure:"continuously_available"`
DirUmask int64 `mapstructure:"dir_umask"`
Encryption bool `mapstructure:"encryption"`
FileUmask int64 `mapstructure:"file_umask"`
ForceGroupForCreate string `mapstructure:"force_group_for_create"`
HomeDirectory bool `mapstructure:"home_directory"`
HomeDirectory bool `mapstructure:"home_directory,omitempty"` // can't be present in update, so omit empty.
NamespaceCaching bool `mapstructure:"namespace_caching"`
NoStrictSecurity bool `mapstructure:"no_strict_security"`
OfflineFiles string `mapstructure:"offline_files"`
OfflineFiles string `mapstructure:"offline_files,omitempty"` // API complains if this is not omit empty
Oplocks bool `mapstructure:"oplocks"`
Path string `mapstructure:"path"`
Path string `mapstructure:"path,omitempty"` // can't be present in update, so omit empty.
ShowSnapshot bool `mapstructure:"show_snapshot"`
UnixSymlink string `mapstructure:"unix_symlink"`
VscanProfile string `mapstructure:"vscan_profile"`
}

// Acls describes the acls data model using go types for mapping.
type Acls struct {
Permission string `mapstructure:"permission"`
Type string `mapstructure:"type"`
UserOrGroup string `mapstructure:"user_or_group"`
}

// ProtocolsCIFSShareResourceBodyDataModelONTAP describes the body data model using go types for mapping.
type ProtocolsCIFSShareResourceBodyDataModelONTAP struct {
Name string `mapstructure:"name"`
SVM svm `mapstructure:"svm"`
UnixSymlink string `mapstructure:"unix_symlink,omitempty"` // API complains if this is not omit empty
VscanProfile string `mapstructure:"vscan_profile,omitempty"` // API complains if this is not omit empty
}

// ProtocolsCIFSShareDataSourceFilterModel describes the data source data model for queries.
Expand Down Expand Up @@ -73,7 +97,7 @@ func GetProtocolsCIFSShareByName(errorHandler *utils.ErrorHandler, r restclient.
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_share data source: %#v", dataONTAP))
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read protocols_cifs_share: %#v", dataONTAP))
return &dataONTAP, nil
}

Expand Down Expand Up @@ -112,7 +136,8 @@ func GetProtocolsCIFSShares(errorHandler *utils.ErrorHandler, r restclient.RestC

// CreateProtocolsCIFSShare to create protocols_cifs_share
func CreateProtocolsCIFSShare(errorHandler *utils.ErrorHandler, r restclient.RestClient, body ProtocolsCIFSShareResourceBodyDataModelONTAP) (*ProtocolsCIFSShareGetDataModelONTAP, error) {
api := "api_url"
api := "/protocols/cifs/shares"

var bodyMap map[string]interface{}
if err := mapstructure.Decode(body, &bodyMap); err != nil {
return nil, errorHandler.MakeAndReportError("error encoding protocols_cifs_share body", fmt.Sprintf("error on encoding %s body: %s, body: %#v", api, err, body))
Expand All @@ -132,10 +157,24 @@ func CreateProtocolsCIFSShare(errorHandler *utils.ErrorHandler, r restclient.Res
return &dataONTAP, nil
}

// UpdateProtocolsCIFSShare to update protocols_cifs_share
func UpdateProtocolsCIFSShare(errorHandler *utils.ErrorHandler, r restclient.RestClient, body ProtocolsCIFSShareResourceBodyDataModelONTAP, name string, svmUUID string) error {
api := "/protocols/cifs/shares/"
var bodyMap map[string]interface{}
if err := mapstructure.Decode(body, &bodyMap); err != nil {
return errorHandler.MakeAndReportError("error encoding protocols_cifs_share body", fmt.Sprintf("error on encoding %s body: %s, body: %#v", api, err, body))
}
statusCode, _, err := r.CallUpdateMethod(api+"/"+svmUUID+"/"+name, nil, bodyMap)
if err != nil {
return errorHandler.MakeAndReportError("error updating protocols_cifs_share", fmt.Sprintf("error on POST %s: %s, statusCode %d", api, err, statusCode))
}
return nil
}

// DeleteProtocolsCIFSShare to delete protocols_cifs_share
func DeleteProtocolsCIFSShare(errorHandler *utils.ErrorHandler, r restclient.RestClient, uuid string) error {
api := "api_url"
statusCode, _, err := r.CallDeleteMethod(api+"/"+uuid, nil, nil)
func DeleteProtocolsCIFSShare(errorHandler *utils.ErrorHandler, r restclient.RestClient, name string, svmUUID string) error {
api := "/protocols/cifs/shares"
statusCode, _, err := r.CallDeleteMethod(api+"/"+svmUUID+"/"+name, nil, nil)
if err != nil {
return errorHandler.MakeAndReportError("error deleting protocols_cifs_share", fmt.Sprintf("error on DELETE %s: %s, statusCode %d", api, err, statusCode))
}
Expand Down
Loading
Loading