Skip to content

Commit

Permalink
service/transfer: Refactor tagging logic to keyvaluetags package
Browse files Browse the repository at this point in the history
Reference: #10688

Output from acceptance testing:

```
--- PASS: TestAccAWSTransferUser_UserName_Validation (5.86s)
--- PASS: TestAccAWSTransferServer_disappears (11.20s)
--- PASS: TestAccAWSTransferUser_disappears (14.61s)
--- PASS: TestAccAWSTransferServer_forcedestroy (15.39s)
--- PASS: TestAccAWSTransferUser_basic (16.12s)
--- PASS: TestAccAWSTransferServer_apigateway (20.54s)
--- PASS: TestAccAWSTransferServer_basic (21.48s)
--- PASS: TestAccAWSTransferUser_modifyWithOptions (36.18s)
--- PASS: TestAccAWSTransferServer_vpcEndpointId (77.08s)
```
  • Loading branch information
bflad committed Nov 4, 2019
1 parent a5e7c55 commit f91e05b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 240 deletions.
13 changes: 8 additions & 5 deletions aws/resource_aws_transfer_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/transfer"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func resourceAwsTransferServer() *schema.Resource {
Expand Down Expand Up @@ -110,7 +110,7 @@ func resourceAwsTransferServer() *schema.Resource {

func resourceAwsTransferServerCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).transferconn
tags := tagsFromMapTransfer(d.Get("tags").(map[string]interface{}))
tags := keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().TransferTags()
createOpts := &transfer.CreateServerInput{}

if len(tags) != 0 {
Expand Down Expand Up @@ -192,7 +192,7 @@ func resourceAwsTransferServerRead(d *schema.ResourceData, meta interface{}) err
d.Set("identity_provider_type", resp.Server.IdentityProviderType)
d.Set("logging_role", resp.Server.LoggingRole)

if err := d.Set("tags", tagsToMapTransfer(resp.Server.Tags)); err != nil {
if err := d.Set("tags", keyvaluetags.TransferKeyValueTags(resp.Server.Tags).IgnoreAws().Map()); err != nil {
return fmt.Errorf("Error setting tags: %s", err)
}
return nil
Expand Down Expand Up @@ -249,8 +249,11 @@ func resourceAwsTransferServerUpdate(d *schema.ResourceData, meta interface{}) e
}
}

if err := setTagsTransfer(conn, d); err != nil {
return fmt.Errorf("Error update tags: %s", err)
if d.HasChange("tags") {
o, n := d.GetChange("tags")
if err := keyvaluetags.TransferUpdateTags(conn, d.Get("arn").(string), o, n); err != nil {
return fmt.Errorf("error updating tags: %s", err)
}
}

return resourceAwsTransferServerRead(d, meta)
Expand Down
13 changes: 8 additions & 5 deletions aws/resource_aws_transfer_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/transfer"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func resourceAwsTransferUser() *schema.Resource {
Expand Down Expand Up @@ -89,7 +89,7 @@ func resourceAwsTransferUserCreate(d *schema.ResourceData, meta interface{}) err
}

if attr, ok := d.GetOk("tags"); ok {
createOpts.Tags = tagsFromMapTransfer(attr.(map[string]interface{}))
createOpts.Tags = keyvaluetags.New(attr.(map[string]interface{})).IgnoreAws().TransferTags()
}

log.Printf("[DEBUG] Create Transfer User Option: %#v", createOpts)
Expand Down Expand Up @@ -135,7 +135,7 @@ func resourceAwsTransferUserRead(d *schema.ResourceData, meta interface{}) error
d.Set("policy", resp.User.Policy)
d.Set("role", resp.User.Role)

if err := d.Set("tags", tagsToMapTransfer(resp.User.Tags)); err != nil {
if err := d.Set("tags", keyvaluetags.TransferKeyValueTags(resp.User.Tags).IgnoreAws().Map()); err != nil {
return fmt.Errorf("Error setting tags: %s", err)
}
return nil
Expand Down Expand Up @@ -181,8 +181,11 @@ func resourceAwsTransferUserUpdate(d *schema.ResourceData, meta interface{}) err
}
}

if err := setTagsTransfer(conn, d); err != nil {
return fmt.Errorf("Error update tags: %s", err)
if d.HasChange("tags") {
o, n := d.GetChange("tags")
if err := keyvaluetags.TransferUpdateTags(conn, d.Get("arn").(string), o, n); err != nil {
return fmt.Errorf("error updating tags: %s", err)
}
}

return resourceAwsTransferUserRead(d, meta)
Expand Down
118 changes: 0 additions & 118 deletions aws/tagsTransfer.go

This file was deleted.

112 changes: 0 additions & 112 deletions aws/tagsTransfer_test.go

This file was deleted.

0 comments on commit f91e05b

Please sign in to comment.