From 165cc9d0ba9b9c89d39ccefa470c95c07b028f64 Mon Sep 17 00:00:00 2001 From: Anthony Wat Date: Wed, 27 Sep 2023 00:09:15 -0400 Subject: [PATCH] aws_datasync_location_fsx_ontap_file_system: fix missing fields in smb block --- .../datasync/common_fsx_protocol_functions.go | 20 ++++++++++++++++--- .../location_fsx_ontap_file_system.go | 2 +- .../location_fsx_openzfs_file_system.go | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/internal/service/datasync/common_fsx_protocol_functions.go b/internal/service/datasync/common_fsx_protocol_functions.go index 3a3a007b2a26..61e474cba54f 100644 --- a/internal/service/datasync/common_fsx_protocol_functions.go +++ b/internal/service/datasync/common_fsx_protocol_functions.go @@ -4,7 +4,9 @@ package datasync import ( + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/datasync" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func expandProtocol(l []interface{}) *datasync.FsxProtocol { @@ -25,7 +27,7 @@ func expandProtocol(l []interface{}) *datasync.FsxProtocol { return protocol } -func flattenProtocol(protocol *datasync.FsxProtocol) []interface{} { +func flattenProtocol(protocol *datasync.FsxProtocol, d *schema.ResourceData) []interface{} { if protocol == nil { return []interface{}{} } @@ -36,7 +38,7 @@ func flattenProtocol(protocol *datasync.FsxProtocol) []interface{} { m["nfs"] = flattenNFS(protocol.NFS) } if protocol.SMB != nil { - m["smb"] = flattenSMB(protocol.SMB) + m["smb"] = flattenSMB(protocol.SMB, d) } return []interface{}{m} @@ -64,7 +66,10 @@ func expandSMB(l []interface{}) *datasync.FsxProtocolSmb { m := l[0].(map[string]interface{}) protocol := &datasync.FsxProtocolSmb{ + Domain: aws.String(m["domain"].(string)), MountOptions: expandSMBMountOptions(m["mount_options"].([]interface{})), + Password: aws.String(m["password"].(string)), + User: aws.String(m["user"].(string)), } return protocol @@ -83,13 +88,22 @@ func flattenNFS(nfs *datasync.FsxProtocolNfs) []interface{} { return []interface{}{m} } -func flattenSMB(smb *datasync.FsxProtocolSmb) []interface{} { +func flattenSMB(smb *datasync.FsxProtocolSmb, d *schema.ResourceData) []interface{} { if smb == nil { return []interface{}{} } + // Need to store the value for "password" from config in the state since it is write-only in the Describe API + password := "" + if d != nil { + password = d.Get("protocol.0.smb.0.password").(string) + } + m := map[string]interface{}{ + "domain": smb.Domain, "mount_options": flattenSMBMountOptions(smb.MountOptions), + "password": password, + "user": smb.User, } return []interface{}{m} diff --git a/internal/service/datasync/location_fsx_ontap_file_system.go b/internal/service/datasync/location_fsx_ontap_file_system.go index 27ff9ff235fd..bc063b62dd9b 100644 --- a/internal/service/datasync/location_fsx_ontap_file_system.go +++ b/internal/service/datasync/location_fsx_ontap_file_system.go @@ -244,7 +244,7 @@ func resourceLocationFSxONTAPFileSystemRead(ctx context.Context, d *schema.Resou d.Set("arn", output.LocationArn) d.Set("creation_time", output.CreationTime.Format(time.RFC3339)) d.Set("fsx_filesystem_arn", output.FsxFilesystemArn) - if err := d.Set("protocol", flattenProtocol(output.Protocol)); err != nil { + if err := d.Set("protocol", flattenProtocol(output.Protocol, d)); err != nil { return sdkdiag.AppendErrorf(diags, "setting protocol: %s", err) } d.Set("security_group_arns", aws.StringValueSlice(output.SecurityGroupArns)) diff --git a/internal/service/datasync/location_fsx_openzfs_file_system.go b/internal/service/datasync/location_fsx_openzfs_file_system.go index cb7bf5c2f723..e37a68e1da0d 100644 --- a/internal/service/datasync/location_fsx_openzfs_file_system.go +++ b/internal/service/datasync/location_fsx_openzfs_file_system.go @@ -185,7 +185,7 @@ func resourceLocationFSxOpenZFSFileSystemRead(ctx context.Context, d *schema.Res d.Set("arn", output.LocationArn) d.Set("creation_time", output.CreationTime.Format(time.RFC3339)) d.Set("fsx_filesystem_arn", d.Get("fsx_filesystem_arn")) - if err := d.Set("protocol", flattenProtocol(output.Protocol)); err != nil { + if err := d.Set("protocol", flattenProtocol(output.Protocol, d)); err != nil { return sdkdiag.AppendErrorf(diags, "setting protocol: %s", err) } d.Set("security_group_arns", aws.StringValueSlice(output.SecurityGroupArns))