Skip to content

Commit

Permalink
resource/aws_storagegateway_smb_file_share: Support cache attributes …
Browse files Browse the repository at this point in the history
…and case sensitivity, remove errant docs (#14790)

* remove smb file share defaults as it doesnt exist

* plan time validation refactor

* add cache attributes

* disappears test

* use %w for errors

* use %#v for structs

* support case sensitivity
  • Loading branch information
DrFaust92 authored Aug 24, 2020
1 parent 6e47b9c commit bd0a750
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 43 deletions.
88 changes: 59 additions & 29 deletions aws/resource_aws_storagegateway_smb_file_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func resourceAwsStorageGatewaySmbFileShare() *schema.Resource {
"S3_ONEZONE_IA",
"S3_STANDARD_IA",
"S3_STANDARD",
"S3_INTELLIGENT_TIERING",
}, false),
},
"fileshare_id": {
Expand Down Expand Up @@ -87,6 +88,7 @@ func resourceAwsStorageGatewaySmbFileShare() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
RequiredWith: []string{"kms_encrypted"},
},
"location_arn": {
Type: schema.TypeString,
Expand All @@ -95,18 +97,24 @@ func resourceAwsStorageGatewaySmbFileShare() *schema.Resource {
ValidateFunc: validateArn,
},
"object_acl": {
Type: schema.TypeString,
Type: schema.TypeString,
Optional: true,
Default: storagegateway.ObjectACLPrivate,
ValidateFunc: validation.StringInSlice(storagegateway.ObjectACL_Values(), false),
},
"cache_attributes": {
Type: schema.TypeList,
Optional: true,
Default: storagegateway.ObjectACLPrivate,
ValidateFunc: validation.StringInSlice([]string{
storagegateway.ObjectACLAuthenticatedRead,
storagegateway.ObjectACLAwsExecRead,
storagegateway.ObjectACLBucketOwnerFullControl,
storagegateway.ObjectACLBucketOwnerRead,
storagegateway.ObjectACLPrivate,
storagegateway.ObjectACLPublicRead,
storagegateway.ObjectACLPublicReadWrite,
}, false),
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cache_stale_timeout_in_seconds": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(300, 2592000),
},
},
},
},
"path": {
Type: schema.TypeString,
Expand Down Expand Up @@ -137,6 +145,12 @@ func resourceAwsStorageGatewaySmbFileShare() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"case_sensitivity": {
Type: schema.TypeString,
Optional: true,
Default: storagegateway.CaseSensitivityClientSpecified,
ValidateFunc: validation.StringInSlice(storagegateway.CaseSensitivity_Values(), false),
},
"tags": tagsSchema(),
},
}
Expand All @@ -158,6 +172,7 @@ func resourceAwsStorageGatewaySmbFileShareCreate(d *schema.ResourceData, meta in
ReadOnly: aws.Bool(d.Get("read_only").(bool)),
RequesterPays: aws.Bool(d.Get("requester_pays").(bool)),
Role: aws.String(d.Get("role_arn").(string)),
CaseSensitivity: aws.String(d.Get("case_sensitivity").(string)),
ValidUserList: expandStringSet(d.Get("valid_user_list").(*schema.Set)),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().StoragegatewayTags(),
}
Expand All @@ -174,10 +189,14 @@ func resourceAwsStorageGatewaySmbFileShareCreate(d *schema.ResourceData, meta in
input.SMBACLEnabled = aws.Bool(v.(bool))
}

log.Printf("[DEBUG] Creating Storage Gateway SMB File Share: %s", input)
if v, ok := d.GetOk("cache_attributes"); ok {
input.CacheAttributes = expandStorageGatewayNfsFileShareCacheAttributes(v.([]interface{}))
}

log.Printf("[DEBUG] Creating Storage Gateway SMB File Share: %#v", input)
output, err := conn.CreateSMBFileShare(input)
if err != nil {
return fmt.Errorf("error creating Storage Gateway SMB File Share: %s", err)
return fmt.Errorf("error creating Storage Gateway SMB File Share: %w", err)
}

d.SetId(aws.StringValue(output.FileShareARN))
Expand All @@ -192,7 +211,7 @@ func resourceAwsStorageGatewaySmbFileShareCreate(d *schema.ResourceData, meta in
}
_, err = stateConf.WaitForState()
if err != nil {
return fmt.Errorf("error waiting for Storage Gateway SMB File Share creation: %s", err)
return fmt.Errorf("error waiting for Storage Gateway SMB File Share creation: %w", err)
}

return resourceAwsStorageGatewaySmbFileShareRead(d, meta)
Expand All @@ -206,15 +225,15 @@ func resourceAwsStorageGatewaySmbFileShareRead(d *schema.ResourceData, meta inte
FileShareARNList: []*string{aws.String(d.Id())},
}

log.Printf("[DEBUG] Reading Storage Gateway SMB File Share: %s", input)
log.Printf("[DEBUG] Reading Storage Gateway SMB File Share: %#v", input)
output, err := conn.DescribeSMBFileShares(input)
if err != nil {
if isAWSErr(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified file share was not found.") {
log.Printf("[WARN] Storage Gateway SMB File Share %q not found, removing from state", d.Id())
d.SetId("")
return nil
}
return fmt.Errorf("error reading Storage Gateway SMB File Share: %s", err)
return fmt.Errorf("error reading Storage Gateway SMB File Share: %w", err)
}

if output == nil || len(output.SMBFileShareInfoList) == 0 || output.SMBFileShareInfoList[0] == nil {
Expand All @@ -232,9 +251,14 @@ func resourceAwsStorageGatewaySmbFileShareRead(d *schema.ResourceData, meta inte
d.Set("fileshare_id", fileshare.FileShareId)
d.Set("gateway_arn", fileshare.GatewayARN)
d.Set("guess_mime_type_enabled", fileshare.GuessMIMETypeEnabled)
d.Set("case_sensitivity", fileshare.CaseSensitivity)

if err := d.Set("invalid_user_list", flattenStringSet(fileshare.InvalidUserList)); err != nil {
return fmt.Errorf("error setting invalid_user_list: %s", err)
return fmt.Errorf("error setting invalid_user_list: %w", err)
}

if err := d.Set("cache_attributes", flattenStorageGatewayNfsFileShareCacheAttributes(fileshare.CacheAttributes)); err != nil {
return fmt.Errorf("error setting cache_attributes: %w", err)
}

d.Set("kms_encrypted", fileshare.KMSEncrypted)
Expand All @@ -249,11 +273,11 @@ func resourceAwsStorageGatewaySmbFileShareRead(d *schema.ResourceData, meta inte
d.Set("smb_acl_enabled", fileshare.SMBACLEnabled)

if err := d.Set("valid_user_list", flattenStringSet(fileshare.ValidUserList)); err != nil {
return fmt.Errorf("error setting valid_user_list: %s", err)
return fmt.Errorf("error setting valid_user_list: %w", err)
}

if err := d.Set("tags", keyvaluetags.StoragegatewayKeyValueTags(fileshare.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
return fmt.Errorf("error setting tags: %w", err)
}

return nil
Expand All @@ -265,13 +289,14 @@ func resourceAwsStorageGatewaySmbFileShareUpdate(d *schema.ResourceData, meta in
if d.HasChange("tags") {
o, n := d.GetChange("tags")
if err := keyvaluetags.StoragegatewayUpdateTags(conn, d.Get("arn").(string), o, n); err != nil {
return fmt.Errorf("error updating tags: %s", err)
return fmt.Errorf("error updating tags: %w", err)
}
}

if d.HasChanges("default_storage_class", "guess_mime_type_enabled", "invalid_user_list",
"kms_encrypted", "object_acl", "read_only", "requester_pays", "requester_pays",
"valid_user_list", "kms_key_arn", "audit_destination_arn", "smb_acl_enabled") {
"valid_user_list", "kms_key_arn", "audit_destination_arn", "smb_acl_enabled", "cache_attributes",
"case_sensitivity") {
input := &storagegateway.UpdateSMBFileShareInput{
DefaultStorageClass: aws.String(d.Get("default_storage_class").(string)),
FileShareARN: aws.String(d.Id()),
Expand All @@ -283,6 +308,7 @@ func resourceAwsStorageGatewaySmbFileShareUpdate(d *schema.ResourceData, meta in
RequesterPays: aws.Bool(d.Get("requester_pays").(bool)),
ValidUserList: expandStringSet(d.Get("valid_user_list").(*schema.Set)),
SMBACLEnabled: aws.Bool(d.Get("smb_acl_enabled").(bool)),
CaseSensitivity: aws.String(d.Get("case_sensitivity").(string)),
}

if v, ok := d.GetOk("kms_key_arn"); ok && v.(string) != "" {
Expand All @@ -293,10 +319,14 @@ func resourceAwsStorageGatewaySmbFileShareUpdate(d *schema.ResourceData, meta in
input.AuditDestinationARN = aws.String(v.(string))
}

log.Printf("[DEBUG] Updating Storage Gateway SMB File Share: %s", input)
if v, ok := d.GetOk("cache_attributes"); ok {
input.CacheAttributes = expandStorageGatewayNfsFileShareCacheAttributes(v.([]interface{}))
}

log.Printf("[DEBUG] Updating Storage Gateway SMB File Share: %#v", input)
_, err := conn.UpdateSMBFileShare(input)
if err != nil {
return fmt.Errorf("error updating Storage Gateway SMB File Share: %s", err)
return fmt.Errorf("error updating Storage Gateway SMB File Share: %w", err)
}

stateConf := &resource.StateChangeConf{
Expand All @@ -309,7 +339,7 @@ func resourceAwsStorageGatewaySmbFileShareUpdate(d *schema.ResourceData, meta in
}
_, err = stateConf.WaitForState()
if err != nil {
return fmt.Errorf("error waiting for Storage Gateway SMB File Share update: %s", err)
return fmt.Errorf("error waiting for Storage Gateway SMB File Share update: %w", err)
}
}

Expand All @@ -323,13 +353,13 @@ func resourceAwsStorageGatewaySmbFileShareDelete(d *schema.ResourceData, meta in
FileShareARN: aws.String(d.Id()),
}

log.Printf("[DEBUG] Deleting Storage Gateway SMB File Share: %s", input)
log.Printf("[DEBUG] Deleting Storage Gateway SMB File Share: %#v", input)
_, err := conn.DeleteFileShare(input)
if err != nil {
if isAWSErr(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified file share was not found.") {
return nil
}
return fmt.Errorf("error deleting Storage Gateway SMB File Share: %s", err)
return fmt.Errorf("error deleting Storage Gateway SMB File Share: %w", err)
}

stateConf := &resource.StateChangeConf{
Expand All @@ -346,7 +376,7 @@ func resourceAwsStorageGatewaySmbFileShareDelete(d *schema.ResourceData, meta in
if isResourceNotFoundError(err) {
return nil
}
return fmt.Errorf("error waiting for Storage Gateway SMB File Share deletion: %s", err)
return fmt.Errorf("error waiting for Storage Gateway SMB File Share deletion: %w", err)
}

return nil
Expand All @@ -358,13 +388,13 @@ func storageGatewaySmbFileShareRefreshFunc(fileShareArn string, conn *storagegat
FileShareARNList: []*string{aws.String(fileShareArn)},
}

log.Printf("[DEBUG] Reading Storage Gateway SMB File Share: %s", input)
log.Printf("[DEBUG] Reading Storage Gateway SMB File Share: %#v", input)
output, err := conn.DescribeSMBFileShares(input)
if err != nil {
if isAWSErr(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified file share was not found.") {
return nil, "MISSING", nil
}
return nil, "ERROR", fmt.Errorf("error reading Storage Gateway SMB File Share: %s", err)
return nil, "ERROR", fmt.Errorf("error reading Storage Gateway SMB File Share: %w", err)
}

if output == nil || len(output.SMBFileShareInfoList) == 0 || output.SMBFileShareInfoList[0] == nil {
Expand Down
Loading

0 comments on commit bd0a750

Please sign in to comment.