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

r/datasync_location_object_storage: fix issue when updating agent_arns #36819

Merged
merged 6 commits into from
Apr 10, 2024
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/costandusagereportservice v1.23.4
github.com/aws/aws-sdk-go-v2/service/costoptimizationhub v1.4.4
github.com/aws/aws-sdk-go-v2/service/customerprofiles v1.36.4
github.com/aws/aws-sdk-go-v2/service/datasync v1.36.4
github.com/aws/aws-sdk-go-v2/service/datazone v1.8.0
github.com/aws/aws-sdk-go-v2/service/dax v1.19.4
github.com/aws/aws-sdk-go-v2/service/devopsguru v1.30.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ github.com/aws/aws-sdk-go-v2/service/costoptimizationhub v1.4.4 h1:gSO6kMlH4cXxB
github.com/aws/aws-sdk-go-v2/service/costoptimizationhub v1.4.4/go.mod h1:UkyRWEyu3iT7oPmPri8xwPnKXqJQzSUDK9MOKq7xyZE=
github.com/aws/aws-sdk-go-v2/service/customerprofiles v1.36.4 h1:UBo3t3uliQIP3f8duZhmJ1Z62bz/j5o7LH8f/BTt1mU=
github.com/aws/aws-sdk-go-v2/service/customerprofiles v1.36.4/go.mod h1:NGHeOPrlK475HqycL4V02Ubc67Wm+D09Xh4pO6g2c8g=
github.com/aws/aws-sdk-go-v2/service/datasync v1.36.4 h1:B5avI4R+VxroaKOgZGLQW9yBj0qOHssVi+jJqSCOwEw=
github.com/aws/aws-sdk-go-v2/service/datasync v1.36.4/go.mod h1:AT/X92EowfcC8JIqYweBLUN9js/BcHwzAYC5XwWtaYk=
github.com/aws/aws-sdk-go-v2/service/datazone v1.8.0 h1:wJ4bVNXoSTJIMfxgebI32qbxEVLqGVdGCC2f/yyvNxs=
github.com/aws/aws-sdk-go-v2/service/datazone v1.8.0/go.mod h1:6UUbvwSg1ADRoK5rYXGDWjwzSyy8mElzIhVSqCXwNYE=
github.com/aws/aws-sdk-go-v2/service/dax v1.19.4 h1:S3mvtYjRVVsg1R4EuV1LWZUiD72t+pfnBbK8TL7zEmo=
Expand Down
6 changes: 3 additions & 3 deletions internal/conns/awsclient_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions internal/service/datasync/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"net/http"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/datasync"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/datasync"
awstypes "github.com/aws/aws-sdk-go-v2/service/datasync/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -99,7 +99,7 @@ func ResourceAgent() *schema.Resource {

func resourceAgentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DataSyncConn(ctx)
conn := meta.(*conns.AWSClient).DataSyncClient(ctx)

activationKey := d.Get("activation_key").(string)
agentIpAddress := d.Get("ip_address").(string)
Expand Down Expand Up @@ -189,24 +189,24 @@ func resourceAgentCreate(ctx context.Context, d *schema.ResourceData, meta inter
}

if v, ok := d.GetOk("security_group_arns"); ok {
input.SecurityGroupArns = flex.ExpandStringSet(v.(*schema.Set))
input.SecurityGroupArns = flex.ExpandStringValueSet(v.(*schema.Set))
}

if v, ok := d.GetOk("subnet_arns"); ok {
input.SubnetArns = flex.ExpandStringSet(v.(*schema.Set))
input.SubnetArns = flex.ExpandStringValueSet(v.(*schema.Set))
}

if v, ok := d.GetOk("vpc_endpoint_id"); ok {
input.VpcEndpointId = aws.String(v.(string))
}

output, err := conn.CreateAgentWithContext(ctx, input)
output, err := conn.CreateAgent(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating DataSync Agent: %s", err)
}

d.SetId(aws.StringValue(output.AgentArn))
d.SetId(aws.ToString(output.AgentArn))

_, err = tfresource.RetryWhenNotFound(ctx, d.Timeout(schema.TimeoutCreate), func() (interface{}, error) {
return FindAgentByARN(ctx, conn, d.Id())
Expand All @@ -221,7 +221,7 @@ func resourceAgentCreate(ctx context.Context, d *schema.ResourceData, meta inter

func resourceAgentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DataSyncConn(ctx)
conn := meta.(*conns.AWSClient).DataSyncClient(ctx)

output, err := FindAgentByARN(ctx, conn, d.Id())

Expand All @@ -239,8 +239,8 @@ func resourceAgentRead(ctx context.Context, d *schema.ResourceData, meta interfa
d.Set("name", output.Name)
if plc := output.PrivateLinkConfig; plc != nil {
d.Set("private_link_endpoint", plc.PrivateLinkEndpoint)
d.Set("security_group_arns", flex.FlattenStringList(plc.SecurityGroupArns))
d.Set("subnet_arns", flex.FlattenStringList(plc.SubnetArns))
d.Set("security_group_arns", flex.FlattenStringValueList(plc.SecurityGroupArns))
d.Set("subnet_arns", flex.FlattenStringValueList(plc.SubnetArns))
d.Set("vpc_endpoint_id", plc.VpcEndpointId)
} else {
d.Set("private_link_endpoint", "")
Expand All @@ -254,15 +254,15 @@ func resourceAgentRead(ctx context.Context, d *schema.ResourceData, meta interfa

func resourceAgentUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DataSyncConn(ctx)
conn := meta.(*conns.AWSClient).DataSyncClient(ctx)

if d.HasChange("name") {
input := &datasync.UpdateAgentInput{
AgentArn: aws.String(d.Id()),
Name: aws.String(d.Get("name").(string)),
}

_, err := conn.UpdateAgentWithContext(ctx, input)
_, err := conn.UpdateAgent(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "updating DataSync Agent (%s): %s", d.Id(), err)
Expand All @@ -274,14 +274,14 @@ func resourceAgentUpdate(ctx context.Context, d *schema.ResourceData, meta inter

func resourceAgentDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DataSyncConn(ctx)
conn := meta.(*conns.AWSClient).DataSyncClient(ctx)

log.Printf("[DEBUG] Deleting DataSync Agent: %s", d.Id())
_, err := conn.DeleteAgentWithContext(ctx, &datasync.DeleteAgentInput{
_, err := conn.DeleteAgent(ctx, &datasync.DeleteAgentInput{
AgentArn: aws.String(d.Id()),
})

if tfawserr.ErrMessageContains(err, datasync.ErrCodeInvalidRequestException, "does not exist") {
if errs.IsAErrorMessageContains[*awstypes.InvalidRequestException](err, "does not exist") {
return diags
}

Expand All @@ -292,14 +292,14 @@ func resourceAgentDelete(ctx context.Context, d *schema.ResourceData, meta inter
return diags
}

func FindAgentByARN(ctx context.Context, conn *datasync.DataSync, arn string) (*datasync.DescribeAgentOutput, error) {
func FindAgentByARN(ctx context.Context, conn *datasync.Client, arn string) (*datasync.DescribeAgentOutput, error) {
input := &datasync.DescribeAgentInput{
AgentArn: aws.String(arn),
}

output, err := conn.DescribeAgentWithContext(ctx, input)
output, err := conn.DescribeAgent(ctx, input)

if tfawserr.ErrMessageContains(err, datasync.ErrCodeInvalidRequestException, "does not exist") {
if errs.IsAErrorMessageContains[*awstypes.InvalidRequestException](err, "does not exist") {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
Expand Down
10 changes: 5 additions & 5 deletions internal/service/datasync/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"testing"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/datasync"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/datasync"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestAccDataSyncAgent_vpcEndpointID(t *testing.T) {

func testAccCheckAgentDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).DataSyncConn(ctx)
conn := acctest.Provider.Meta().(*conns.AWSClient).DataSyncClient(ctx)

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_datasync_agent" {
Expand Down Expand Up @@ -236,7 +236,7 @@ func testAccCheckAgentExists(ctx context.Context, n string, v *datasync.Describe
return fmt.Errorf("Not found: %s", n)
}

conn := acctest.Provider.Meta().(*conns.AWSClient).DataSyncConn(ctx)
conn := acctest.Provider.Meta().(*conns.AWSClient).DataSyncClient(ctx)

output, err := tfdatasync.FindAgentByARN(ctx, conn, rs.Primary.ID)

Expand All @@ -252,7 +252,7 @@ func testAccCheckAgentExists(ctx context.Context, n string, v *datasync.Describe

func testAccCheckAgentNotRecreated(i, j *datasync.DescribeAgentOutput) resource.TestCheckFunc {
return func(s *terraform.State) error {
if !aws.TimeValue(i.CreationTime).Equal(aws.TimeValue(j.CreationTime)) {
if !aws.ToTime(i.CreationTime).Equal(aws.ToTime(j.CreationTime)) {
return errors.New("DataSync Agent was recreated")
}

Expand Down
28 changes: 14 additions & 14 deletions internal/service/datasync/common_fsx_protocol_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
package datasync

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/datasync"
"github.com/aws/aws-sdk-go-v2/aws"
awstypes "github.com/aws/aws-sdk-go-v2/service/datasync/types"
)

func expandProtocol(l []interface{}) *datasync.FsxProtocol {
func expandProtocol(l []interface{}) *awstypes.FsxProtocol {
if len(l) == 0 || l[0] == nil {
return nil
}

m := l[0].(map[string]interface{})
protocol := &datasync.FsxProtocol{}
protocol := &awstypes.FsxProtocol{}

if v, ok := m["nfs"].([]interface{}); ok {
protocol.NFS = expandNFS(v)
Expand All @@ -26,7 +26,7 @@ func expandProtocol(l []interface{}) *datasync.FsxProtocol {
return protocol
}

func flattenProtocol(protocol *datasync.FsxProtocol) []interface{} {
func flattenProtocol(protocol *awstypes.FsxProtocol) []interface{} {
if protocol == nil {
return []interface{}{}
}
Expand All @@ -43,28 +43,28 @@ func flattenProtocol(protocol *datasync.FsxProtocol) []interface{} {
return []interface{}{m}
}

func expandNFS(l []interface{}) *datasync.FsxProtocolNfs {
func expandNFS(l []interface{}) *awstypes.FsxProtocolNfs {
if len(l) == 0 || l[0] == nil {
return nil
}

m := l[0].(map[string]interface{})

protocol := &datasync.FsxProtocolNfs{
protocol := &awstypes.FsxProtocolNfs{
MountOptions: expandNFSMountOptions(m["mount_options"].([]interface{})),
}

return protocol
}

func expandSMB(l []interface{}) *datasync.FsxProtocolSmb {
func expandSMB(l []interface{}) *awstypes.FsxProtocolSmb {
if len(l) == 0 || l[0] == nil {
return nil
}

m := l[0].(map[string]interface{})

protocol := &datasync.FsxProtocolSmb{
protocol := &awstypes.FsxProtocolSmb{
MountOptions: expandSMBMountOptions(m["mount_options"].([]interface{})),
}
if v, ok := m["domain"].(string); ok && v != "" {
Expand All @@ -81,7 +81,7 @@ func expandSMB(l []interface{}) *datasync.FsxProtocolSmb {
}

// todo: go another level down?
func flattenNFS(nfs *datasync.FsxProtocolNfs) []interface{} {
func flattenNFS(nfs *awstypes.FsxProtocolNfs) []interface{} {
if nfs == nil {
return []interface{}{}
}
Expand All @@ -93,7 +93,7 @@ func flattenNFS(nfs *datasync.FsxProtocolNfs) []interface{} {
return []interface{}{m}
}

func flattenSMB(smb *datasync.FsxProtocolSmb) []interface{} {
func flattenSMB(smb *awstypes.FsxProtocolSmb) []interface{} {
if smb == nil {
return []interface{}{}
}
Expand All @@ -102,13 +102,13 @@ func flattenSMB(smb *datasync.FsxProtocolSmb) []interface{} {
"mount_options": flattenSMBMountOptions(smb.MountOptions),
}
if v := smb.Domain; v != nil {
m["domain"] = aws.StringValue(v)
m["domain"] = aws.ToString(v)
}
if v := smb.Password; v != nil {
m["password"] = aws.StringValue(v)
m["password"] = aws.ToString(v)
}
if v := smb.User; v != nil {
m["user"] = aws.StringValue(v)
m["user"] = aws.ToString(v)
}

return []interface{}{m}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/datasync/generate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:generate go run ../../generate/tags/main.go -ListTags -ServiceTagsSlice -TagType=TagListEntry -UntagInTagsElem=Keys -UpdateTags
//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTags -ServiceTagsSlice -TagType=TagListEntry -UntagInTagsElem=Keys -UpdateTags
//go:generate go run ../../generate/servicepackage/main.go
// ONLY generate directives and package declaration! Do not add anything else to this file.

Expand Down
Loading
Loading