Skip to content

Commit

Permalink
Merge pull request #27563 from mtt88/b-aws_transfer_user_remove_home_dir
Browse files Browse the repository at this point in the history
r/aws_transfer_user - fix error removing `home_directory_mappings`
  • Loading branch information
ewbankkit authored Mar 2, 2023
2 parents 04223fe + b9bbb40 commit b90f42b
Show file tree
Hide file tree
Showing 11 changed files with 322 additions and 503 deletions.
7 changes: 7 additions & 0 deletions .changelog/27563.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_transfer_user: Fix bug preventing removal of all `home_directory_mappings` due to empty list validation error
```

```release-note:enhancement
resource/aws_transfer_user: Add configurable timeout for Delete
```
26 changes: 0 additions & 26 deletions internal/service/transfer/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,6 @@ func FindServerByID(ctx context.Context, conn *transfer.Transfer, id string) (*t
return output.Server, nil
}

func FindUserByServerIDAndUserName(ctx context.Context, conn *transfer.Transfer, serverID, userName string) (*transfer.DescribedUser, error) {
input := &transfer.DescribeUserInput{
ServerId: aws.String(serverID),
UserName: aws.String(userName),
}

output, err := conn.DescribeUserWithContext(ctx, 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.User == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return output.User, nil
}

func FindWorkflowByID(ctx context.Context, conn *transfer.Transfer, id string) (*transfer.DescribedWorkflow, error) {
input := &transfer.DescribeWorkflowInput{
WorkflowId: aws.String(id),
Expand Down
3 changes: 2 additions & 1 deletion internal/service/transfer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func ResourceServer() *schema.Resource {
ReadWithoutTimeout: resourceServerRead,
UpdateWithoutTimeout: resourceServerUpdate,
DeleteWithoutTimeout: resourceServerDelete,

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Expand Down Expand Up @@ -689,7 +690,7 @@ func resourceServerDelete(ctx context.Context, d *schema.ResourceData, meta inte
}

for _, user := range page.Users {
err := userDelete(ctx, conn, d.Id(), aws.StringValue(user.UserName))
err := userDelete(ctx, conn, d.Id(), aws.StringValue(user.UserName), d.Timeout(schema.TimeoutDelete))

if err != nil {
deletionErrs = multierror.Append(deletionErrs, err)
Expand Down
12 changes: 6 additions & 6 deletions internal/service/transfer/server_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)

func TestAccTransferServerDataSource_basic(t *testing.T) {
func testAccServerDataSource_basic(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_transfer_server.test"
datasourceName := "data.aws_transfer_server.test"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); testAccPreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, transfer.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand All @@ -34,13 +34,13 @@ func TestAccTransferServerDataSource_basic(t *testing.T) {
})
}

func TestAccTransferServerDataSource_Service_managed(t *testing.T) {
func testAccServerDataSource_Service_managed(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandString(5)
resourceName := "aws_transfer_server.test"
datasourceName := "data.aws_transfer_server.test"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); testAccPreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, transfer.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand All @@ -64,13 +64,13 @@ func TestAccTransferServerDataSource_Service_managed(t *testing.T) {
})
}

func TestAccTransferServerDataSource_apigateway(t *testing.T) {
func testAccServerDataSource_apigateway(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandString(5)
resourceName := "aws_transfer_server.test"
datasourceName := "data.aws_transfer_server.test"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); testAccPreCheck(ctx, t); acctest.PreCheckAPIGatewayTypeEDGE(t) },
ErrorCheck: acctest.ErrorCheck(t, transfer.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down
20 changes: 0 additions & 20 deletions internal/service/transfer/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

const (
userStateExists = "exists"
)

func statusServerState(ctx context.Context, conn *transfer.Transfer, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := FindServerByID(ctx, conn, id)
Expand All @@ -28,19 +24,3 @@ func statusServerState(ctx context.Context, conn *transfer.Transfer, id string)
return output, aws.StringValue(output.State), nil
}
}

func statusUserState(ctx context.Context, conn *transfer.Transfer, serverID, userName string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := FindUserByServerIDAndUserName(ctx, conn, serverID, userName)

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

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

return output, userStateExists, nil
}
}
16 changes: 8 additions & 8 deletions internal/service/transfer/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
tftransfer "github.com/hashicorp/terraform-provider-aws/internal/service/transfer"
)

func TestAccTransferTag_basic(t *testing.T) {
func testAccTag_basic(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_transfer_tag.test"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, transfer.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand All @@ -39,12 +39,12 @@ func TestAccTransferTag_basic(t *testing.T) {
})
}

func TestAccTransferTag_disappears(t *testing.T) {
func testAccTag_disappears(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_transfer_tag.test"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, transfer.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand All @@ -62,12 +62,12 @@ func TestAccTransferTag_disappears(t *testing.T) {
})
}

func TestAccTransferTag_value(t *testing.T) {
func testAccTag_value(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_transfer_tag.test"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, transfer.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down Expand Up @@ -98,12 +98,12 @@ func TestAccTransferTag_value(t *testing.T) {
})
}

func TestAccTransferTag_system(t *testing.T) {
func testAccTag_system(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_transfer_tag.test"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, transfer.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down
10 changes: 10 additions & 0 deletions internal/service/transfer/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func TestAccTransfer_serial(t *testing.T) {
"APIGateway": testAccServer_apiGateway,
"APIGatewayForceDestroy": testAccServer_apiGateway_forceDestroy,
"AuthenticationLoginBanners": testAccServer_authenticationLoginBanners,
"DataSourceBasic": testAccServerDataSource_basic,
"DataSourceServiceManaged": testAccServerDataSource_Service_managed,
"DataSourceAPIGateway": testAccServerDataSource_apigateway,
"DirectoryService": testAccServer_directoryService,
"Domain": testAccServer_domain,
"ForceDestroy": testAccServer_forceDestroy,
Expand All @@ -45,9 +48,16 @@ func TestAccTransfer_serial(t *testing.T) {
"SSHKey": {
"basic": testAccSSHKey_basic,
},
"Tag": {
"basic": testAccTag_basic,
"disappears": testAccTag_disappears,
"Value": testAccTag_value,
"System": testAccTag_system,
},
"User": {
"basic": testAccUser_basic,
"disappears": testAccUser_disappears,
"tags": testAccUser_tags,
"HomeDirectoryMappings": testAccUser_homeDirectoryMappings,
"ModifyWithOptions": testAccUser_modifyWithOptions,
"Posix": testAccUser_posix,
Expand Down
Loading

0 comments on commit b90f42b

Please sign in to comment.