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

support FTP & FTPS protocols for the aws_transfer_server resource #13371

Merged
merged 14 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from 12 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
36 changes: 36 additions & 0 deletions aws/internal/service/transfer/finder/finder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package finder

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/transfer"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func ServerByID(conn *transfer.Transfer, id string) (*transfer.DescribedServer, error) {
input := &transfer.DescribeServerInput{
ServerId: aws.String(id),
}

output, err := conn.DescribeServer(input)

if tfawserr.ErrCodeEquals(err, transfer.ErrCodeResourceNotFoundException) {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil || output.Server == nil {
return nil, &resource.NotFoundError{
Message: "Empty result",
LastRequest: input,
}
}

return output.Server, nil
}
25 changes: 25 additions & 0 deletions aws/internal/service/transfer/id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package transfer

import (
"fmt"
"strings"
)

const userResourceIDSeparator = "/"

func UserCreateResourceID(serverID, userName string) string {
parts := []string{serverID, userName}
id := strings.Join(parts, userResourceIDSeparator)

return id
}

func UserParseResourceID(id string) (string, string, error) {
parts := strings.Split(id, userResourceIDSeparator)

if len(parts) == 2 && parts[0] != "" && parts[1] != "" {
return parts[0], parts[1], nil
}

return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected SERVERID%[2]sUSERNAME", id, userResourceIDSeparator)
}
25 changes: 25 additions & 0 deletions aws/internal/service/transfer/waiter/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package waiter

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/transfer"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/transfer/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

func ServerState(conn *transfer.Transfer, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := finder.ServerByID(conn, id)

if tfresource.NotFound(err) {
return nil, "", nil
}

if err != nil {
return nil, "", err
}

return output, aws.StringValue(output.State), nil
}
}
80 changes: 80 additions & 0 deletions aws/internal/service/transfer/waiter/waiter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package waiter

import (
"time"

"github.com/aws/aws-sdk-go/service/transfer"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

const (
ServerDeletedTimeout = 10 * time.Minute
)

func ServerCreated(conn *transfer.Transfer, id string, timeout time.Duration) (*transfer.DescribedServer, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{transfer.StateStarting},
Target: []string{transfer.StateOnline},
Refresh: ServerState(conn, id),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

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

return nil, err
}

func ServerDeleted(conn *transfer.Transfer, id string) (*transfer.DescribedServer, error) {
stateConf := &resource.StateChangeConf{
Pending: transfer.State_Values(),
Target: []string{},
Refresh: ServerState(conn, id),
Timeout: ServerDeletedTimeout,
}

outputRaw, err := stateConf.WaitForState()

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

return nil, err
}

func ServerStarted(conn *transfer.Transfer, id string, timeout time.Duration) (*transfer.DescribedServer, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{transfer.StateStarting, transfer.StateOffline, transfer.StateStopping},
Target: []string{transfer.StateOnline},
Refresh: ServerState(conn, id),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

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

return nil, err
}

func ServerStopped(conn *transfer.Transfer, id string, timeout time.Duration) (*transfer.DescribedServer, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{transfer.StateStarting, transfer.StateOnline, transfer.StateStopping},
Target: []string{transfer.StateOffline},
Refresh: ServerState(conn, id),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

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

return nil, err
}
Loading