Skip to content

Commit

Permalink
aws_datasync_location_fsx_ontap_file_system: fix missing fields in smb
Browse files Browse the repository at this point in the history
block
  • Loading branch information
acwwat committed Sep 27, 2023
1 parent 93743ec commit 165cc9d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
20 changes: 17 additions & 3 deletions internal/service/datasync/common_fsx_protocol_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{}{}
}
Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 165cc9d

Please sign in to comment.