From 165cc9d0ba9b9c89d39ccefa470c95c07b028f64 Mon Sep 17 00:00:00 2001 From: Anthony Wat Date: Wed, 27 Sep 2023 00:09:15 -0400 Subject: [PATCH 1/8] 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)) From 7d7e8ac3331674d511ee90945e45578c1f9f5653 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 27 Sep 2023 15:06:39 -0400 Subject: [PATCH 2/8] Add 'TestAccDataSyncLocationFSxONTAPFileSystem_smb'. --- .../location_fsx_ontap_file_system_test.go | 69 ++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/internal/service/datasync/location_fsx_ontap_file_system_test.go b/internal/service/datasync/location_fsx_ontap_file_system_test.go index 7ea0bad5bf9f..c8427ca3cf88 100644 --- a/internal/service/datasync/location_fsx_ontap_file_system_test.go +++ b/internal/service/datasync/location_fsx_ontap_file_system_test.go @@ -40,11 +40,16 @@ func TestAccDataSyncLocationFSxONTAPFileSystem_basic(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccLocationFSxONTAPFileSystemConfig_basic(rName), - Check: resource.ComposeTestCheckFunc( + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckLocationFSxONTAPExists(ctx, resourceName, &v), acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "datasync", regexache.MustCompile(`location/loc-.+`)), resource.TestCheckResourceAttrSet(resourceName, "creation_time"), resource.TestCheckResourceAttrPair(resourceName, "fsx_filesystem_arn", fsResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "protocol.#", "1"), + resource.TestCheckResourceAttr(resourceName, "protocol.0.nfs.#", "1"), + resource.TestCheckResourceAttr(resourceName, "protocol.0.nfs.0.mount_options.#", "1"), + resource.TestCheckResourceAttr(resourceName, "protocol.0.nfs.0.mount_options.0.version", "NFS3"), + resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.#", "0"), resource.TestCheckResourceAttr(resourceName, "subdirectory", "/"), resource.TestCheckResourceAttrPair(resourceName, "storage_virtual_machine_arn", svmResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), @@ -89,6 +94,46 @@ func TestAccDataSyncLocationFSxONTAPFileSystem_disappears(t *testing.T) { }) } +func TestAccDataSyncLocationFSxONTAPFileSystem_smb(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + var v datasync.DescribeLocationFsxOntapOutput + resourceName := "aws_datasync_location_fsx_ontap_file_system.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, fsx.EndpointsID) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, datasync.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckLocationFSxONTAPDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccLocationFSxONTAPFileSystemConfig_smb(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckLocationFSxONTAPExists(ctx, resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "protocol.#", "1"), + resource.TestCheckResourceAttr(resourceName, "protocol.0.nfs.#", "0"), + resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.#", "1"), + resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.domain", "aws.mydomain.com"), + resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.mounts_options.#", "1"), + resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.mounts_options.0.version", "SMB3"), + resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.password", "MyPassw0rd1"), + resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.user", "datasyncsa"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateIdFunc: testAccLocationFSxONTAPImportStateID(resourceName), + }, + }, + }) +} + func TestAccDataSyncLocationFSxONTAPFileSystem_subdirectory(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -292,6 +337,28 @@ resource "aws_datasync_location_fsx_ontap_file_system" "test" { `) } +func testAccLocationFSxONTAPFileSystemConfig_smb(rName string) string { + return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName), ` +resource "aws_datasync_location_fsx_ontap_file_system" "test" { + security_group_arns = [aws_security_group.test.arn] + storage_virtual_machine_arn = aws_fsx_ontap_storage_virtual_machine.test.arn + + protocol { + smb { + domain = "aws.mydomain.com" + + mount_options { + version = "SMB3" + } + + password = "MyPassw0rd1" + user = "datasyncsa" + } + } +} +`) +} + func testAccLocationFSxONTAPFileSystemConfig_subdirectory(rName, subdirectory string) string { return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName), fmt.Sprintf(` resource "aws_datasync_location_fsx_ontap_file_system" "test" { From 2c13acc675a46e547ce19e7027906827b4c3ad9c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 27 Sep 2023 16:11:36 -0400 Subject: [PATCH 3/8] Acceptance test output: % make testacc TESTARGS='-run=TestAccDataSyncLocationFSxONTAPFileSystem_basic\|TestAccDataSyncLocationFSxONTAPFileSystem_smb' PKG=datasync ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/datasync/... -v -count 1 -parallel 20 -run=TestAccDataSyncLocationFSxONTAPFileSystem_basic\|TestAccDataSyncLocationFSxONTAPFileSystem_smb -timeout 360m === RUN TestAccDataSyncLocationFSxONTAPFileSystem_basic === PAUSE TestAccDataSyncLocationFSxONTAPFileSystem_basic === RUN TestAccDataSyncLocationFSxONTAPFileSystem_smb === PAUSE TestAccDataSyncLocationFSxONTAPFileSystem_smb === CONT TestAccDataSyncLocationFSxONTAPFileSystem_basic === CONT TestAccDataSyncLocationFSxONTAPFileSystem_smb location_fsx_ontap_file_system_test.go:103: Step 1/2 error: Error running apply: exit status 1 Error: creating DataSync Location FSx for NetApp ONTAP File System: InvalidParameter: 2 validation error(s) found. - missing required field, CreateLocationFsxOntapInput.Protocol.SMB.Password. - missing required field, CreateLocationFsxOntapInput.Protocol.SMB.User. with aws_datasync_location_fsx_ontap_file_system.test, on terraform_plugin_test.tf line 72, in resource "aws_datasync_location_fsx_ontap_file_system" "test": 72: resource "aws_datasync_location_fsx_ontap_file_system" "test" { --- PASS: TestAccDataSyncLocationFSxONTAPFileSystem_basic (2365.08s) --- FAIL: TestAccDataSyncLocationFSxONTAPFileSystem_smb (2408.72s) FAIL FAIL github.com/hashicorp/terraform-provider-aws/internal/service/datasync 2414.085s FAIL make: *** [testacc] Error 1 From a904926220270912d3cbf9d452987e714f644c1a Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 28 Sep 2023 07:53:55 -0400 Subject: [PATCH 4/8] datasync: Handle 'domain', 'password' and 'user' in expandSMB/flattenSMB. --- .../datasync/common_fsx_protocol_functions.go | 19 +++++ .../location_fsx_ontap_file_system_test.go | 75 ++++++++++++++----- 2 files changed, 77 insertions(+), 17 deletions(-) diff --git a/internal/service/datasync/common_fsx_protocol_functions.go b/internal/service/datasync/common_fsx_protocol_functions.go index 3a3a007b2a26..2bb97e5e83a4 100644 --- a/internal/service/datasync/common_fsx_protocol_functions.go +++ b/internal/service/datasync/common_fsx_protocol_functions.go @@ -4,6 +4,7 @@ package datasync import ( + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/datasync" ) @@ -66,6 +67,15 @@ func expandSMB(l []interface{}) *datasync.FsxProtocolSmb { protocol := &datasync.FsxProtocolSmb{ MountOptions: expandSMBMountOptions(m["mount_options"].([]interface{})), } + if v, ok := m["domain"].(string); ok && v != "" { + protocol.Domain = aws.String(v) + } + if v, ok := m["password"].(string); ok && v != "" { + protocol.Password = aws.String(v) + } + if v, ok := m["user"].(string); ok && v != "" { + protocol.User = aws.String(v) + } return protocol } @@ -91,6 +101,15 @@ func flattenSMB(smb *datasync.FsxProtocolSmb) []interface{} { m := map[string]interface{}{ "mount_options": flattenSMBMountOptions(smb.MountOptions), } + if v := smb.Domain; v != nil { + m["domain"] = aws.StringValue(v) + } + if v := smb.Password; v != nil { + m["password"] = aws.StringValue(v) + } + if v := smb.User; v != nil { + m["user"] = aws.StringValue(v) + } return []interface{}{m} } diff --git a/internal/service/datasync/location_fsx_ontap_file_system_test.go b/internal/service/datasync/location_fsx_ontap_file_system_test.go index c8427ca3cf88..675441e510c0 100644 --- a/internal/service/datasync/location_fsx_ontap_file_system_test.go +++ b/internal/service/datasync/location_fsx_ontap_file_system_test.go @@ -97,6 +97,9 @@ func TestAccDataSyncLocationFSxONTAPFileSystem_disappears(t *testing.T) { func TestAccDataSyncLocationFSxONTAPFileSystem_smb(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + netBiosName := "tftest-" + sdkacctest.RandString(7) + domainNetbiosName := "tftest" + sdkacctest.RandString(4) + domainName := domainNetbiosName + ".local" var v datasync.DescribeLocationFsxOntapOutput resourceName := "aws_datasync_location_fsx_ontap_file_system.test" @@ -111,17 +114,17 @@ func TestAccDataSyncLocationFSxONTAPFileSystem_smb(t *testing.T) { CheckDestroy: testAccCheckLocationFSxONTAPDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccLocationFSxONTAPFileSystemConfig_smb(rName), + Config: testAccLocationFSxONTAPFileSystemConfig_smb(rName, netBiosName, domainNetbiosName, domainName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckLocationFSxONTAPExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "protocol.#", "1"), resource.TestCheckResourceAttr(resourceName, "protocol.0.nfs.#", "0"), resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.#", "1"), - resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.domain", "aws.mydomain.com"), - resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.mounts_options.#", "1"), - resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.mounts_options.0.version", "SMB3"), + resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.domain", domainName), + resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.mount_options.#", "1"), + resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.mount_options.0.version", "SMB3"), resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.password", "MyPassw0rd1"), - resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.user", "datasyncsa"), + resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.user", "Admin"), ), }, { @@ -276,8 +279,8 @@ func testAccLocationFSxONTAPImportStateID(n string) resource.ImportStateIdFunc { } } -func testAccFSxOntapFileSystemConfig_base(rName string) string { - return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` +func testAccFSxOntapFileSystemConfig_base(rName string, nSubnets int, deploymentType string) string { + return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, nSubnets), fmt.Sprintf(` resource "aws_security_group" "test" { name = %[1]q vpc_id = aws_vpc.test.id @@ -304,7 +307,7 @@ resource "aws_security_group" "test" { resource "aws_fsx_ontap_file_system" "test" { storage_capacity = 1024 subnet_ids = aws_subnet.test[*].id - deployment_type = "SINGLE_AZ_1" + deployment_type = %[2]q throughput_capacity = 512 preferred_subnet_id = aws_subnet.test[0].id @@ -312,7 +315,11 @@ resource "aws_fsx_ontap_file_system" "test" { Name = %[1]q } } +`, rName, deploymentType)) +} +func testAccFSxOntapFileSystemConfig_baseNFS(rName string) string { + return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName, 1, "SINGLE_AZ_1"), fmt.Sprintf(` resource "aws_fsx_ontap_storage_virtual_machine" "test" { file_system_id = aws_fsx_ontap_file_system.test.id name = %[1]q @@ -320,8 +327,24 @@ resource "aws_fsx_ontap_storage_virtual_machine" "test" { `, rName)) } +func testAccFSxOntapFileSystemConfig_baseSMB(rName, domainName string) string { + return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName, 2, "MULTI_AZ_1"), fmt.Sprintf(` +resource "aws_directory_service_directory" "test" { + edition = "Standard" + name = %[1]q + password = "MyPassw0rd1" + type = "MicrosoftAD" + + vpc_settings { + subnet_ids = aws_subnet.test[*].id + vpc_id = aws_vpc.test.id + } +} +`, domainName)) +} + func testAccLocationFSxONTAPFileSystemConfig_basic(rName string) string { - return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName), ` + return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_baseNFS(rName), ` resource "aws_datasync_location_fsx_ontap_file_system" "test" { security_group_arns = [aws_security_group.test.arn] storage_virtual_machine_arn = aws_fsx_ontap_storage_virtual_machine.test.arn @@ -337,30 +360,48 @@ resource "aws_datasync_location_fsx_ontap_file_system" "test" { `) } -func testAccLocationFSxONTAPFileSystemConfig_smb(rName string) string { - return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName), ` +func testAccLocationFSxONTAPFileSystemConfig_smb(rName, netBiosName, domainNetbiosName, domainName string) string { + return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_baseSMB(rName, domainName), fmt.Sprintf(` +resource "aws_fsx_ontap_storage_virtual_machine" "test" { + file_system_id = aws_fsx_ontap_file_system.test.id + name = %[1]q + depends_on = [aws_directory_service_directory.test] + + active_directory_configuration { + netbios_name = %[2]q + self_managed_active_directory_configuration { + dns_ips = aws_directory_service_directory.test.dns_ip_addresses + domain_name = %[3]q + password = "MyPassw0rd1" + username = "Admin" + organizational_unit_distinguished_name = "OU=computers,OU=%[4]s" + file_system_administrators_group = "Admins" + } + } +} + resource "aws_datasync_location_fsx_ontap_file_system" "test" { security_group_arns = [aws_security_group.test.arn] storage_virtual_machine_arn = aws_fsx_ontap_storage_virtual_machine.test.arn protocol { smb { - domain = "aws.mydomain.com" + domain = %[3]q mount_options { version = "SMB3" } password = "MyPassw0rd1" - user = "datasyncsa" + user = "Admin" } } } -`) +`, rName, netBiosName, domainName, domainNetbiosName)) } func testAccLocationFSxONTAPFileSystemConfig_subdirectory(rName, subdirectory string) string { - return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_baseNFS(rName), fmt.Sprintf(` resource "aws_datasync_location_fsx_ontap_file_system" "test" { security_group_arns = [aws_security_group.test.arn] storage_virtual_machine_arn = aws_fsx_ontap_storage_virtual_machine.test.arn @@ -378,7 +419,7 @@ resource "aws_datasync_location_fsx_ontap_file_system" "test" { } func testAccLocationFSxONTAPFileSystemConfig_tags1(rName, key1, value1 string) string { - return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_baseNFS(rName), fmt.Sprintf(` resource "aws_datasync_location_fsx_ontap_file_system" "test" { security_group_arns = [aws_security_group.test.arn] storage_virtual_machine_arn = aws_fsx_ontap_storage_virtual_machine.test.arn @@ -399,7 +440,7 @@ resource "aws_datasync_location_fsx_ontap_file_system" "test" { } func testAccLocationFSxONTAPFileSystemConfig_tags2(rName, key1, value1, key2, value2 string) string { - return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_baseNFS(rName), fmt.Sprintf(` resource "aws_datasync_location_fsx_ontap_file_system" "test" { security_group_arns = [aws_security_group.test.arn] storage_virtual_machine_arn = aws_fsx_ontap_storage_virtual_machine.test.arn From d91f6d52f01bb624bce80f61483f7529c49daef3 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 28 Sep 2023 12:56:50 -0400 Subject: [PATCH 5/8] Acceptance test output: % ACCTEST_TIMEOUT=720m make testacc TESTARGS='-run=TestAccDataSyncLocationFSxONTAPFileSystem_smb' PKG=datasync ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/datasync/... -v -count 1 -parallel 20 -run=TestAccDataSyncLocationFSxONTAPFileSystem_smb -timeout 720m === RUN TestAccDataSyncLocationFSxONTAPFileSystem_smb === PAUSE TestAccDataSyncLocationFSxONTAPFileSystem_smb === CONT TestAccDataSyncLocationFSxONTAPFileSystem_smb location_fsx_ontap_file_system_test.go:106: Step 1/2 error: Check failed: 1 error occurred: * Check 8/9 error: aws_datasync_location_fsx_ontap_file_system.test: Attribute 'protocol.0.smb.0.password' expected "MyPassw0rd1", got "" --- FAIL: TestAccDataSyncLocationFSxONTAPFileSystem_smb (2705.00s) FAIL FAIL github.com/hashicorp/terraform-provider-aws/internal/service/datasync 2710.293s FAIL make: *** [testacc] Error 1 From cc2fc6377d54d63d2c6706540ecd12a773eeba92 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 28 Sep 2023 12:58:10 -0400 Subject: [PATCH 6/8] Revert "aws_datasync_location_fsx_ontap_file_system: fix missing fields in smb" This reverts commit 165cc9d0ba9b9c89d39ccefa470c95c07b028f64. --- .../datasync/common_fsx_protocol_functions.go | 20 +++---------------- .../location_fsx_ontap_file_system.go | 2 +- .../location_fsx_openzfs_file_system.go | 2 +- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/internal/service/datasync/common_fsx_protocol_functions.go b/internal/service/datasync/common_fsx_protocol_functions.go index 61e474cba54f..3a3a007b2a26 100644 --- a/internal/service/datasync/common_fsx_protocol_functions.go +++ b/internal/service/datasync/common_fsx_protocol_functions.go @@ -4,9 +4,7 @@ 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 { @@ -27,7 +25,7 @@ func expandProtocol(l []interface{}) *datasync.FsxProtocol { return protocol } -func flattenProtocol(protocol *datasync.FsxProtocol, d *schema.ResourceData) []interface{} { +func flattenProtocol(protocol *datasync.FsxProtocol) []interface{} { if protocol == nil { return []interface{}{} } @@ -38,7 +36,7 @@ func flattenProtocol(protocol *datasync.FsxProtocol, d *schema.ResourceData) []i m["nfs"] = flattenNFS(protocol.NFS) } if protocol.SMB != nil { - m["smb"] = flattenSMB(protocol.SMB, d) + m["smb"] = flattenSMB(protocol.SMB) } return []interface{}{m} @@ -66,10 +64,7 @@ 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 @@ -88,22 +83,13 @@ func flattenNFS(nfs *datasync.FsxProtocolNfs) []interface{} { return []interface{}{m} } -func flattenSMB(smb *datasync.FsxProtocolSmb, d *schema.ResourceData) []interface{} { +func flattenSMB(smb *datasync.FsxProtocolSmb) []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 bc063b62dd9b..27ff9ff235fd 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, d)); err != nil { + if err := d.Set("protocol", flattenProtocol(output.Protocol)); 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 e37a68e1da0d..cb7bf5c2f723 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, d)); err != nil { + if err := d.Set("protocol", flattenProtocol(output.Protocol)); err != nil { return sdkdiag.AppendErrorf(diags, "setting protocol: %s", err) } d.Set("security_group_arns", aws.StringValueSlice(output.SecurityGroupArns)) From 6a5fc45252c7cf5843ed07f1e4cab4279d764fd1 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 28 Sep 2023 14:02:13 -0400 Subject: [PATCH 7/8] r/aws_datasync_location_fsx_ontap_file_system: SMB Password is not returned from the API, so propagate from configuration. --- .../service/datasync/location_fsx_ontap_file_system.go | 6 ++++++ .../datasync/location_fsx_ontap_file_system_test.go | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/service/datasync/location_fsx_ontap_file_system.go b/internal/service/datasync/location_fsx_ontap_file_system.go index 27ff9ff235fd..20263884cf2f 100644 --- a/internal/service/datasync/location_fsx_ontap_file_system.go +++ b/internal/service/datasync/location_fsx_ontap_file_system.go @@ -244,6 +244,12 @@ 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) + // SMB Password is not returned from the API. + if output.Protocol != nil && output.Protocol.SMB != nil && aws.StringValue(output.Protocol.SMB.Password) == "" { + if smbPassword := d.Get("protocol.0.smb.0.password").(string); smbPassword != "" { + output.Protocol.SMB.Password = aws.String(smbPassword) + } + } if err := d.Set("protocol", flattenProtocol(output.Protocol)); err != nil { return sdkdiag.AppendErrorf(diags, "setting protocol: %s", err) } diff --git a/internal/service/datasync/location_fsx_ontap_file_system_test.go b/internal/service/datasync/location_fsx_ontap_file_system_test.go index 675441e510c0..2fb8c704294b 100644 --- a/internal/service/datasync/location_fsx_ontap_file_system_test.go +++ b/internal/service/datasync/location_fsx_ontap_file_system_test.go @@ -128,10 +128,11 @@ func TestAccDataSyncLocationFSxONTAPFileSystem_smb(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateIdFunc: testAccLocationFSxONTAPImportStateID(resourceName), + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"protocol.0.smb.0.password"}, // Not returned from API. + ImportStateIdFunc: testAccLocationFSxONTAPImportStateID(resourceName), }, }, }) From 69aa59ef924f9a3f98d1e496c47821fd065fd5aa Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 28 Sep 2023 14:06:01 -0400 Subject: [PATCH 8/8] Add CHANGELOG entry. --- .changelog/33641.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .changelog/33641.txt diff --git a/.changelog/33641.txt b/.changelog/33641.txt new file mode 100644 index 000000000000..ae2973973ae1 --- /dev/null +++ b/.changelog/33641.txt @@ -0,0 +1,4 @@ + +```release-note:bug +resource/aws_datasync_location_fsx_ontap_file_system: Correct handling of `protocol.smb.domain`, `protocol.smb.user` and `protocol.smb.password` +``` \ No newline at end of file