Skip to content

Commit 8970a31

Browse files
authored
Merge pull request #33641 from acwwat/b-datasync_loc_fsx_ontap_smb_missing_fields
aws_datasync_location_fsx_ontap_file_system: fix missing fields in smb
2 parents 327bc38 + 69aa59e commit 8970a31

File tree

4 files changed

+146
-8
lines changed

4 files changed

+146
-8
lines changed

.changelog/33641.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
```release-note:bug
3+
resource/aws_datasync_location_fsx_ontap_file_system: Correct handling of `protocol.smb.domain`, `protocol.smb.user` and `protocol.smb.password`
4+
```

internal/service/datasync/common_fsx_protocol_functions.go

+19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package datasync
55

66
import (
7+
"github.com/aws/aws-sdk-go/aws"
78
"github.com/aws/aws-sdk-go/service/datasync"
89
)
910

@@ -66,6 +67,15 @@ func expandSMB(l []interface{}) *datasync.FsxProtocolSmb {
6667
protocol := &datasync.FsxProtocolSmb{
6768
MountOptions: expandSMBMountOptions(m["mount_options"].([]interface{})),
6869
}
70+
if v, ok := m["domain"].(string); ok && v != "" {
71+
protocol.Domain = aws.String(v)
72+
}
73+
if v, ok := m["password"].(string); ok && v != "" {
74+
protocol.Password = aws.String(v)
75+
}
76+
if v, ok := m["user"].(string); ok && v != "" {
77+
protocol.User = aws.String(v)
78+
}
6979

7080
return protocol
7181
}
@@ -91,6 +101,15 @@ func flattenSMB(smb *datasync.FsxProtocolSmb) []interface{} {
91101
m := map[string]interface{}{
92102
"mount_options": flattenSMBMountOptions(smb.MountOptions),
93103
}
104+
if v := smb.Domain; v != nil {
105+
m["domain"] = aws.StringValue(v)
106+
}
107+
if v := smb.Password; v != nil {
108+
m["password"] = aws.StringValue(v)
109+
}
110+
if v := smb.User; v != nil {
111+
m["user"] = aws.StringValue(v)
112+
}
94113

95114
return []interface{}{m}
96115
}

internal/service/datasync/location_fsx_ontap_file_system.go

+6
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ func resourceLocationFSxONTAPFileSystemRead(ctx context.Context, d *schema.Resou
244244
d.Set("arn", output.LocationArn)
245245
d.Set("creation_time", output.CreationTime.Format(time.RFC3339))
246246
d.Set("fsx_filesystem_arn", output.FsxFilesystemArn)
247+
// SMB Password is not returned from the API.
248+
if output.Protocol != nil && output.Protocol.SMB != nil && aws.StringValue(output.Protocol.SMB.Password) == "" {
249+
if smbPassword := d.Get("protocol.0.smb.0.password").(string); smbPassword != "" {
250+
output.Protocol.SMB.Password = aws.String(smbPassword)
251+
}
252+
}
247253
if err := d.Set("protocol", flattenProtocol(output.Protocol)); err != nil {
248254
return sdkdiag.AppendErrorf(diags, "setting protocol: %s", err)
249255
}

internal/service/datasync/location_fsx_ontap_file_system_test.go

+117-8
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@ func TestAccDataSyncLocationFSxONTAPFileSystem_basic(t *testing.T) {
4040
Steps: []resource.TestStep{
4141
{
4242
Config: testAccLocationFSxONTAPFileSystemConfig_basic(rName),
43-
Check: resource.ComposeTestCheckFunc(
43+
Check: resource.ComposeAggregateTestCheckFunc(
4444
testAccCheckLocationFSxONTAPExists(ctx, resourceName, &v),
4545
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "datasync", regexache.MustCompile(`location/loc-.+`)),
4646
resource.TestCheckResourceAttrSet(resourceName, "creation_time"),
4747
resource.TestCheckResourceAttrPair(resourceName, "fsx_filesystem_arn", fsResourceName, "arn"),
48+
resource.TestCheckResourceAttr(resourceName, "protocol.#", "1"),
49+
resource.TestCheckResourceAttr(resourceName, "protocol.0.nfs.#", "1"),
50+
resource.TestCheckResourceAttr(resourceName, "protocol.0.nfs.0.mount_options.#", "1"),
51+
resource.TestCheckResourceAttr(resourceName, "protocol.0.nfs.0.mount_options.0.version", "NFS3"),
52+
resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.#", "0"),
4853
resource.TestCheckResourceAttr(resourceName, "subdirectory", "/"),
4954
resource.TestCheckResourceAttrPair(resourceName, "storage_virtual_machine_arn", svmResourceName, "arn"),
5055
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
@@ -89,6 +94,50 @@ func TestAccDataSyncLocationFSxONTAPFileSystem_disappears(t *testing.T) {
8994
})
9095
}
9196

97+
func TestAccDataSyncLocationFSxONTAPFileSystem_smb(t *testing.T) {
98+
ctx := acctest.Context(t)
99+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
100+
netBiosName := "tftest-" + sdkacctest.RandString(7)
101+
domainNetbiosName := "tftest" + sdkacctest.RandString(4)
102+
domainName := domainNetbiosName + ".local"
103+
var v datasync.DescribeLocationFsxOntapOutput
104+
resourceName := "aws_datasync_location_fsx_ontap_file_system.test"
105+
106+
resource.ParallelTest(t, resource.TestCase{
107+
PreCheck: func() {
108+
acctest.PreCheck(ctx, t)
109+
acctest.PreCheckPartitionHasService(t, fsx.EndpointsID)
110+
testAccPreCheck(ctx, t)
111+
},
112+
ErrorCheck: acctest.ErrorCheck(t, datasync.EndpointsID),
113+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
114+
CheckDestroy: testAccCheckLocationFSxONTAPDestroy(ctx),
115+
Steps: []resource.TestStep{
116+
{
117+
Config: testAccLocationFSxONTAPFileSystemConfig_smb(rName, netBiosName, domainNetbiosName, domainName),
118+
Check: resource.ComposeAggregateTestCheckFunc(
119+
testAccCheckLocationFSxONTAPExists(ctx, resourceName, &v),
120+
resource.TestCheckResourceAttr(resourceName, "protocol.#", "1"),
121+
resource.TestCheckResourceAttr(resourceName, "protocol.0.nfs.#", "0"),
122+
resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.#", "1"),
123+
resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.domain", domainName),
124+
resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.mount_options.#", "1"),
125+
resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.mount_options.0.version", "SMB3"),
126+
resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.password", "MyPassw0rd1"),
127+
resource.TestCheckResourceAttr(resourceName, "protocol.0.smb.0.user", "Admin"),
128+
),
129+
},
130+
{
131+
ResourceName: resourceName,
132+
ImportState: true,
133+
ImportStateVerify: true,
134+
ImportStateVerifyIgnore: []string{"protocol.0.smb.0.password"}, // Not returned from API.
135+
ImportStateIdFunc: testAccLocationFSxONTAPImportStateID(resourceName),
136+
},
137+
},
138+
})
139+
}
140+
92141
func TestAccDataSyncLocationFSxONTAPFileSystem_subdirectory(t *testing.T) {
93142
ctx := acctest.Context(t)
94143
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
@@ -231,8 +280,8 @@ func testAccLocationFSxONTAPImportStateID(n string) resource.ImportStateIdFunc {
231280
}
232281
}
233282

234-
func testAccFSxOntapFileSystemConfig_base(rName string) string {
235-
return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(`
283+
func testAccFSxOntapFileSystemConfig_base(rName string, nSubnets int, deploymentType string) string {
284+
return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, nSubnets), fmt.Sprintf(`
236285
resource "aws_security_group" "test" {
237286
name = %[1]q
238287
vpc_id = aws_vpc.test.id
@@ -259,24 +308,44 @@ resource "aws_security_group" "test" {
259308
resource "aws_fsx_ontap_file_system" "test" {
260309
storage_capacity = 1024
261310
subnet_ids = aws_subnet.test[*].id
262-
deployment_type = "SINGLE_AZ_1"
311+
deployment_type = %[2]q
263312
throughput_capacity = 512
264313
preferred_subnet_id = aws_subnet.test[0].id
265314
266315
tags = {
267316
Name = %[1]q
268317
}
269318
}
319+
`, rName, deploymentType))
320+
}
270321

322+
func testAccFSxOntapFileSystemConfig_baseNFS(rName string) string {
323+
return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName, 1, "SINGLE_AZ_1"), fmt.Sprintf(`
271324
resource "aws_fsx_ontap_storage_virtual_machine" "test" {
272325
file_system_id = aws_fsx_ontap_file_system.test.id
273326
name = %[1]q
274327
}
275328
`, rName))
276329
}
277330

331+
func testAccFSxOntapFileSystemConfig_baseSMB(rName, domainName string) string {
332+
return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName, 2, "MULTI_AZ_1"), fmt.Sprintf(`
333+
resource "aws_directory_service_directory" "test" {
334+
edition = "Standard"
335+
name = %[1]q
336+
password = "MyPassw0rd1"
337+
type = "MicrosoftAD"
338+
339+
vpc_settings {
340+
subnet_ids = aws_subnet.test[*].id
341+
vpc_id = aws_vpc.test.id
342+
}
343+
}
344+
`, domainName))
345+
}
346+
278347
func testAccLocationFSxONTAPFileSystemConfig_basic(rName string) string {
279-
return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName), `
348+
return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_baseNFS(rName), `
280349
resource "aws_datasync_location_fsx_ontap_file_system" "test" {
281350
security_group_arns = [aws_security_group.test.arn]
282351
storage_virtual_machine_arn = aws_fsx_ontap_storage_virtual_machine.test.arn
@@ -292,8 +361,48 @@ resource "aws_datasync_location_fsx_ontap_file_system" "test" {
292361
`)
293362
}
294363

364+
func testAccLocationFSxONTAPFileSystemConfig_smb(rName, netBiosName, domainNetbiosName, domainName string) string {
365+
return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_baseSMB(rName, domainName), fmt.Sprintf(`
366+
resource "aws_fsx_ontap_storage_virtual_machine" "test" {
367+
file_system_id = aws_fsx_ontap_file_system.test.id
368+
name = %[1]q
369+
depends_on = [aws_directory_service_directory.test]
370+
371+
active_directory_configuration {
372+
netbios_name = %[2]q
373+
self_managed_active_directory_configuration {
374+
dns_ips = aws_directory_service_directory.test.dns_ip_addresses
375+
domain_name = %[3]q
376+
password = "MyPassw0rd1"
377+
username = "Admin"
378+
organizational_unit_distinguished_name = "OU=computers,OU=%[4]s"
379+
file_system_administrators_group = "Admins"
380+
}
381+
}
382+
}
383+
384+
resource "aws_datasync_location_fsx_ontap_file_system" "test" {
385+
security_group_arns = [aws_security_group.test.arn]
386+
storage_virtual_machine_arn = aws_fsx_ontap_storage_virtual_machine.test.arn
387+
388+
protocol {
389+
smb {
390+
domain = %[3]q
391+
392+
mount_options {
393+
version = "SMB3"
394+
}
395+
396+
password = "MyPassw0rd1"
397+
user = "Admin"
398+
}
399+
}
400+
}
401+
`, rName, netBiosName, domainName, domainNetbiosName))
402+
}
403+
295404
func testAccLocationFSxONTAPFileSystemConfig_subdirectory(rName, subdirectory string) string {
296-
return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName), fmt.Sprintf(`
405+
return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_baseNFS(rName), fmt.Sprintf(`
297406
resource "aws_datasync_location_fsx_ontap_file_system" "test" {
298407
security_group_arns = [aws_security_group.test.arn]
299408
storage_virtual_machine_arn = aws_fsx_ontap_storage_virtual_machine.test.arn
@@ -311,7 +420,7 @@ resource "aws_datasync_location_fsx_ontap_file_system" "test" {
311420
}
312421

313422
func testAccLocationFSxONTAPFileSystemConfig_tags1(rName, key1, value1 string) string {
314-
return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName), fmt.Sprintf(`
423+
return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_baseNFS(rName), fmt.Sprintf(`
315424
resource "aws_datasync_location_fsx_ontap_file_system" "test" {
316425
security_group_arns = [aws_security_group.test.arn]
317426
storage_virtual_machine_arn = aws_fsx_ontap_storage_virtual_machine.test.arn
@@ -332,7 +441,7 @@ resource "aws_datasync_location_fsx_ontap_file_system" "test" {
332441
}
333442

334443
func testAccLocationFSxONTAPFileSystemConfig_tags2(rName, key1, value1, key2, value2 string) string {
335-
return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_base(rName), fmt.Sprintf(`
444+
return acctest.ConfigCompose(testAccFSxOntapFileSystemConfig_baseNFS(rName), fmt.Sprintf(`
336445
resource "aws_datasync_location_fsx_ontap_file_system" "test" {
337446
security_group_arns = [aws_security_group.test.arn]
338447
storage_virtual_machine_arn = aws_fsx_ontap_storage_virtual_machine.test.arn

0 commit comments

Comments
 (0)