Skip to content

Commit

Permalink
Merge pull request #20234 from sylr/improve-storagegateway-smb-file-s…
Browse files Browse the repository at this point in the history
…hare

aws_storagegateway_smb_file_share: Add `bucket_region`, `oplocks_enabled` and `vpc_endpoint_dns_name` arguments
  • Loading branch information
ewbankkit authored Jul 20, 2021
2 parents 5e6e4df + 51e4c95 commit 60a86a2
Show file tree
Hide file tree
Showing 9 changed files with 488 additions and 270 deletions.
3 changes: 3 additions & 0 deletions .changelog/20234.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_storagegateway_smb_file_share: Add `bucket_region`, `oplocks_enabled` and `vpc_endpoint_dns_name` arguments
```
37 changes: 37 additions & 0 deletions aws/internal/service/storagegateway/enum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package storagegateway

const (
AuthenticationActiveDirectory = "ActiveDirectory"
AuthenticationGuestAccess = "GuestAccess"
)

func Authentication_Values() []string {
return []string{
AuthenticationActiveDirectory,
AuthenticationGuestAccess,
}
}

const (
DefaultStorageClassS3IntelligentTiering = "S3_INTELLIGENT_TIERING"
DefaultStorageClassS3OneZoneIA = "S3_ONEZONE_IA"
DefaultStorageClassS3Standard = "S3_STANDARD"
DefaultStorageClassS3StandardIA = "S3_STANDARD_IA"
)

func DefaultStorageClass_Values() []string {
return []string{
DefaultStorageClassS3IntelligentTiering,
DefaultStorageClassS3OneZoneIA,
DefaultStorageClassS3Standard,
DefaultStorageClassS3StandardIA,
}
}

const (
FileShareStatusAvailable = "AVAILABLE"
FileShareStatusCreating = "CREATING"
FileShareStatusDeleting = "DELETING"
FileShareStatusForceDeleting = "FORCE_DELETING"
FileShareStatusUpdating = "UPDATING"
)
28 changes: 28 additions & 0 deletions aws/internal/service/storagegateway/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package storagegateway

import (
"errors"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/storagegateway"
)

const (
OperationErrCodeFileShareNotFound = "FileShareNotFound"
)

// OperationErrorCode returns the operation error code from the specified error:
// * err is of type awserr.Error and represents a storagegateway.InternalServerError or storagegateway.InvalidGatewayRequestException
// * Error_ is not nil
// See https://docs.aws.amazon.com/storagegateway/latest/userguide/AWSStorageGatewayAPI.html#APIErrorResponses for details.
func OperationErrorCode(err error) string {
if inner := (*storagegateway.InternalServerError)(nil); errors.As(err, &inner) && inner.Error_ != nil {
return aws.StringValue(inner.Error_.ErrorCode)
}

if inner := (*storagegateway.InvalidGatewayRequestException)(nil); errors.As(err, &inner) && inner.Error_ != nil {
return aws.StringValue(inner.Error_.ErrorCode)
}

return ""
}
33 changes: 33 additions & 0 deletions aws/internal/service/storagegateway/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package finder
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/storagegateway"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
tfstoragegateway "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/storagegateway"
)

func LocalDiskByDiskId(conn *storagegateway.StorageGateway, gatewayARN string, diskID string) (*storagegateway.Disk, error) {
Expand Down Expand Up @@ -79,3 +81,34 @@ func UploadBufferDisk(conn *storagegateway.StorageGateway, gatewayARN string, di

return result, err
}

func SMBFileShareByARN(conn *storagegateway.StorageGateway, arn string) (*storagegateway.SMBFileShareInfo, error) {
input := &storagegateway.DescribeSMBFileSharesInput{
FileShareARNList: aws.StringSlice([]string{arn}),
}

output, err := conn.DescribeSMBFileShares(input)

if tfstoragegateway.OperationErrorCode(err) == tfstoragegateway.OperationErrCodeFileShareNotFound {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil || len(output.SMBFileShareInfoList) == 0 || output.SMBFileShareInfoList[0] == nil {
return nil, &resource.NotFoundError{
Message: "Empty result",
LastRequest: input,
}
}

// TODO Check for multiple results.
// TODO https://github.com/hashicorp/terraform-provider-aws/pull/17613.

return output.SMBFileShareInfoList[0], nil
}
25 changes: 9 additions & 16 deletions aws/internal/service/storagegateway/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/aws/aws-sdk-go/service/storagegateway"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/storagegateway/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

const (
Expand Down Expand Up @@ -111,27 +113,18 @@ func NfsFileShareStatus(conn *storagegateway.StorageGateway, fileShareArn string
}
}

func SmbFileShareStatus(conn *storagegateway.StorageGateway, fileShareArn string) resource.StateRefreshFunc {
func SMBFileShareStatus(conn *storagegateway.StorageGateway, arn string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &storagegateway.DescribeSMBFileSharesInput{
FileShareARNList: []*string{aws.String(fileShareArn)},
}
output, err := finder.SMBFileShareByARN(conn, arn)

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

if output == nil || len(output.SMBFileShareInfoList) == 0 || output.SMBFileShareInfoList[0] == nil {
return nil, SmbFileShareStatusNotFound, nil
if err != nil {
return nil, "", err
}

fileshare := output.SMBFileShareInfoList[0]

return fileshare, aws.StringValue(fileshare.FileShareStatus), nil
return output, aws.StringValue(output.FileShareStatus), nil
}
}
34 changes: 26 additions & 8 deletions aws/internal/service/storagegateway/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/aws/aws-sdk-go/service/storagegateway"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
tfstoragegateway "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/storagegateway"
)

const (
Expand Down Expand Up @@ -111,12 +112,11 @@ func NfsFileShareDeleted(conn *storagegateway.StorageGateway, fileShareArn strin
return nil, err
}

// SmbFileShareAvailable waits for a SMB File Share to return Available
func SmbFileShareAvailable(conn *storagegateway.StorageGateway, fileShareArn string, timeout time.Duration) (*storagegateway.SMBFileShareInfo, error) {
func SMBFileShareCreated(conn *storagegateway.StorageGateway, arn string, timeout time.Duration) (*storagegateway.SMBFileShareInfo, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{"CREATING", "UPDATING"},
Target: []string{"AVAILABLE"},
Refresh: SmbFileShareStatus(conn, fileShareArn),
Pending: []string{tfstoragegateway.FileShareStatusCreating},
Target: []string{tfstoragegateway.FileShareStatusAvailable},
Refresh: SMBFileShareStatus(conn, arn),
Timeout: timeout,
Delay: SmbFileShareAvailableDelay,
}
Expand All @@ -130,11 +130,11 @@ func SmbFileShareAvailable(conn *storagegateway.StorageGateway, fileShareArn str
return nil, err
}

func SmbFileShareDeleted(conn *storagegateway.StorageGateway, fileShareArn string, timeout time.Duration) (*storagegateway.SMBFileShareInfo, error) {
func SMBFileShareDeleted(conn *storagegateway.StorageGateway, arn string, timeout time.Duration) (*storagegateway.SMBFileShareInfo, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{"AVAILABLE", "DELETING", "FORCE_DELETING"},
Pending: []string{tfstoragegateway.FileShareStatusAvailable, tfstoragegateway.FileShareStatusDeleting, tfstoragegateway.FileShareStatusForceDeleting},
Target: []string{},
Refresh: SmbFileShareStatus(conn, fileShareArn),
Refresh: SMBFileShareStatus(conn, arn),
Timeout: timeout,
Delay: SmbFileShareDeletedDelay,
NotFoundChecks: 1,
Expand All @@ -148,3 +148,21 @@ func SmbFileShareDeleted(conn *storagegateway.StorageGateway, fileShareArn strin

return nil, err
}

func SMBFileShareUpdated(conn *storagegateway.StorageGateway, arn string, timeout time.Duration) (*storagegateway.SMBFileShareInfo, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{tfstoragegateway.FileShareStatusUpdating},
Target: []string{tfstoragegateway.FileShareStatusAvailable},
Refresh: SMBFileShareStatus(conn, arn),
Timeout: timeout,
Delay: SmbFileShareAvailableDelay,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*storagegateway.SMBFileShareInfo); ok {
return output, err
}

return nil, err
}
Loading

0 comments on commit 60a86a2

Please sign in to comment.