Skip to content

Commit

Permalink
resource/aws_fsx_windows_file_system: Prevent panic when update inclu…
Browse files Browse the repository at this point in the history
…des `self_managed_active_directory` settings (#12630)

Reference: #11500

Previously:

```
=== CONT  TestAccAWSFsxWindowsFileSystem_SelfManagedActiveDirectory_Username
panic: interface conversion: interface {} is *schema.Set, not []interface {}

goroutine 4434 [running]:
github.com/terraform-providers/terraform-provider-aws/aws.expandFsxSelfManagedActiveDirectoryConfigurationUpdate(0xc000488de0, 0x1, 0x1, 0x5b2f000)
	/Users/bflad/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_fsx_windows_file_system.go:413 +0x2d7
github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsFsxWindowsFileSystemUpdate(0xc00004ed20, 0x62e3060, 0xc0003c3900, 0x0, 0x0)
	/Users/bflad/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_fsx_windows_file_system.go:269 +0x637
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).Apply(0xc00099b580, 0xc001cf2cd0, 0xc000ddebe0, 0x62e3060, 0xc0003c3900, 0x6168e01, 0xc001e73760, 0xc001914db0)
	/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.8.0/helper/schema/resource.go:311 +0x263
```

Output from acceptance testing:

```
--- PASS: TestAccAWSFsxWindowsFileSystem_AutomaticBackupRetentionDays (3063.70s)
--- PASS: TestAccAWSFsxWindowsFileSystem_basic (2915.15s)
--- PASS: TestAccAWSFsxWindowsFileSystem_CopyTagsToBackups (4140.35s)
--- PASS: TestAccAWSFsxWindowsFileSystem_DailyAutomaticBackupStartTime (3034.18s)
--- PASS: TestAccAWSFsxWindowsFileSystem_disappears (3045.25s)
--- PASS: TestAccAWSFsxWindowsFileSystem_KmsKeyId (4148.71s)
--- PASS: TestAccAWSFsxWindowsFileSystem_SecurityGroupIds (4179.82s)
--- PASS: TestAccAWSFsxWindowsFileSystem_SelfManagedActiveDirectory (2905.75s)
--- PASS: TestAccAWSFsxWindowsFileSystem_SelfManagedActiveDirectory_Username (3731.46s)
--- PASS: TestAccAWSFsxWindowsFileSystem_StorageCapacity (4120.68s)
--- PASS: TestAccAWSFsxWindowsFileSystem_Tags (2968.90s)
--- PASS: TestAccAWSFsxWindowsFileSystem_ThroughputCapacity (4056.94s)
--- PASS: TestAccAWSFsxWindowsFileSystem_WeeklyMaintenanceStartTime (3012.74s)
```
  • Loading branch information
bflad authored Apr 28, 2020
1 parent 2264dc2 commit a8973be
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aws/resource_aws_fsx_windows_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func expandFsxSelfManagedActiveDirectoryConfigurationUpdate(l []interface{}) *fs

data := l[0].(map[string]interface{})
req := &fsx.SelfManagedActiveDirectoryConfigurationUpdates{
DnsIps: expandStringList(data["dns_ips"].([]interface{})),
DnsIps: expandStringSet(data["dns_ips"].(*schema.Set)),
Password: aws.String(data["password"].(string)),
UserName: aws.String(data["username"].(string)),
}
Expand Down
54 changes: 54 additions & 0 deletions aws/resource_aws_fsx_windows_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,43 @@ func TestAccAWSFsxWindowsFileSystem_SelfManagedActiveDirectory(t *testing.T) {
})
}

func TestAccAWSFsxWindowsFileSystem_SelfManagedActiveDirectory_Username(t *testing.T) {
var filesystem fsx.FileSystem
resourceName := "aws_fsx_windows_file_system.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckFsxWindowsFileSystemDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsFsxWindowsFileSystemConfigSelfManagedActiveDirectoryUsername("Admin"),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxWindowsFileSystemExists(resourceName, &filesystem),
resource.TestCheckResourceAttr(resourceName, "self_managed_active_directory.#", "1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"security_group_ids",
"self_managed_active_directory",
"skip_final_backup",
},
},
{
Config: testAccAwsFsxWindowsFileSystemConfigSelfManagedActiveDirectoryUsername("Administrator"),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxWindowsFileSystemExists(resourceName, &filesystem),
resource.TestCheckResourceAttr(resourceName, "self_managed_active_directory.#", "1"),
),
},
},
})
}

func TestAccAWSFsxWindowsFileSystem_StorageCapacity(t *testing.T) {
var filesystem1, filesystem2 fsx.FileSystem
resourceName := "aws_fsx_windows_file_system.test"
Expand Down Expand Up @@ -827,6 +864,23 @@ resource "aws_fsx_windows_file_system" "test" {
`)
}

func testAccAwsFsxWindowsFileSystemConfigSelfManagedActiveDirectoryUsername(username string) string {
return testAccAwsFsxWindowsFileSystemConfigBase() + fmt.Sprintf(`
resource "aws_fsx_windows_file_system" "test" {
skip_final_backup = true
storage_capacity = 32
subnet_ids = ["${aws_subnet.test1.id}"]
throughput_capacity = 8
self_managed_active_directory {
dns_ips = aws_directory_service_directory.test.dns_ip_addresses
domain_name = aws_directory_service_directory.test.name
password = aws_directory_service_directory.test.password
username = %[1]q
}
}
`, username)
}

func testAccAwsFsxWindowsFileSystemConfigStorageCapacity(storageCapacity int) string {
return testAccAwsFsxWindowsFileSystemConfigBase() + fmt.Sprintf(`
resource "aws_fsx_windows_file_system" "test" {
Expand Down

0 comments on commit a8973be

Please sign in to comment.