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 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
7 changes: 7 additions & 0 deletions .changelog/13371.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_transfer_server: Add `protocols` argument
```

```release-note:enhancement
data-source/aws_transfer_server: Add `certificate`, `endpoint_type`, `protocols` and `security_policy_name` attributes
```
83 changes: 58 additions & 25 deletions aws/data_source_aws_transfer_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,108 @@ package aws

import (
"fmt"
"log"

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

func dataSourceAwsTransferServer() *schema.Resource {
return &schema.Resource{
Read: dataSourceAwsTransferServerRead,
Schema: map[string]*schema.Schema{
"server_id": {
"arn": {
Type: schema.TypeString,
Required: true,
Computed: true,
},
"arn": {

"certificate": {
Type: schema.TypeString,
Computed: true,
},

"endpoint": {
Type: schema.TypeString,
Computed: true,
},
"invocation_role": {

"endpoint_type": {
Type: schema.TypeString,
Computed: true,
},
"url": {

"identity_provider_type": {
Type: schema.TypeString,
Computed: true,
},
"identity_provider_type": {

"invocation_role": {
Type: schema.TypeString,
Computed: true,
},

"logging_role": {
Type: schema.TypeString,
Computed: true,
},

"protocols": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"security_policy_name": {
Type: schema.TypeString,
Computed: true,
},

"server_id": {
Type: schema.TypeString,
Required: true,
},

"url": {
Type: schema.TypeString,
Computed: true,
},
},

Read: dataSourceAwsTransferServerRead,
}
}

func dataSourceAwsTransferServerRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).transferconn

serverID := d.Get("server_id").(string)
input := &transfer.DescribeServerInput{
ServerId: aws.String(serverID),
}

log.Printf("[DEBUG] Describe Transfer Server Option: %#v", input)
output, err := finder.ServerByID(conn, serverID)

resp, err := conn.DescribeServer(input)
if err != nil {
return fmt.Errorf("error describing Transfer Server (%s): %w", serverID, err)
return fmt.Errorf("error reading Transfer Server (%s): %w", serverID, err)
}

endpoint := meta.(*AWSClient).RegionalHostname(fmt.Sprintf("%s.server.transfer", serverID))

d.SetId(serverID)
d.Set("arn", resp.Server.Arn)
d.Set("endpoint", endpoint)
if resp.Server.IdentityProviderDetails != nil {
d.Set("invocation_role", resp.Server.IdentityProviderDetails.InvocationRole)
d.Set("url", resp.Server.IdentityProviderDetails.Url)
d.SetId(aws.StringValue(output.ServerId))
d.Set("arn", output.Arn)
d.Set("certificate", output.Certificate)
d.Set("endpoint", meta.(*AWSClient).RegionalHostname(fmt.Sprintf("%s.server.transfer", serverID)))
d.Set("endpoint_type", output.EndpointType)
d.Set("identity_provider_type", output.IdentityProviderType)
if output.IdentityProviderDetails != nil {
d.Set("invocation_role", output.IdentityProviderDetails.InvocationRole)
} else {
d.Set("invocation_role", "")
}
d.Set("logging_role", output.LoggingRole)
d.Set("protocols", aws.StringValueSlice(output.Protocols))
d.Set("security_policy_name", output.SecurityPolicyName)
if output.IdentityProviderDetails != nil {
d.Set("url", output.IdentityProviderDetails.Url)
} else {
d.Set("url", "")
}
d.Set("identity_provider_type", resp.Server.IdentityProviderType)
d.Set("logging_role", resp.Server.LoggingRole)

return nil
}
6 changes: 6 additions & 0 deletions aws/data_source_aws_transfer_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ func TestAccDataSourceAwsTransferServer_service_managed(t *testing.T) {
Config: testAccDataSourceAwsTransferServerConfig_service_managed(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(datasourceName, "certificate", resourceName, "certificate"),
resource.TestCheckResourceAttrPair(datasourceName, "endpoint", resourceName, "endpoint"),
resource.TestCheckResourceAttrPair(datasourceName, "endpoint_type", resourceName, "endpoint_type"),
resource.TestCheckResourceAttrPair(datasourceName, "identity_provider_type", resourceName, "identity_provider_type"),
resource.TestCheckResourceAttrPair(datasourceName, "invocation_role", resourceName, "invocation_role"),
resource.TestCheckResourceAttrPair(datasourceName, "logging_role", resourceName, "logging_role"),
resource.TestCheckResourceAttrPair(datasourceName, "protocols.#", resourceName, "protocols.#"),
resource.TestCheckResourceAttrPair(datasourceName, "security_policy_name", resourceName, "security_policy_name"),
resource.TestCheckResourceAttrPair(datasourceName, "url", resourceName, "url"),
),
},
},
Expand Down
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