Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/fsx_windows_file_system - add support for multi-az #12676

Merged
43 changes: 41 additions & 2 deletions aws/resource_aws_fsx_windows_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ func resourceAwsFsxWindowsFileSystem() *schema.Resource {
Required: true,
MinItems: 1,
MaxItems: 2,
Elem: &schema.Schema{Type: schema.TypeString},
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.IsIPAddress,
},
},
"domain_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -151,7 +154,6 @@ func resourceAwsFsxWindowsFileSystem() *schema.Resource {
Required: true,
ForceNew: true,
MinItems: 1,
MaxItems: 1,
Elem: &schema.Schema{Type: schema.TypeString},
},
"tags": tagsSchema(),
Expand All @@ -174,6 +176,31 @@ func resourceAwsFsxWindowsFileSystem() *schema.Resource {
validation.StringMatch(regexp.MustCompile(`^[1-7]:([01]\d|2[0-3]):?([0-5]\d)$`), "must be in the format d:HH:MM"),
),
},
"deployment_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: fsx.WindowsDeploymentTypeSingleAz1,
ValidateFunc: validation.StringInSlice([]string{
fsx.WindowsDeploymentTypeMultiAz1,
fsx.WindowsDeploymentTypeSingleAz1,
fsx.WindowsDeploymentTypeSingleAz2,
}, false),
DrFaust92 marked this conversation as resolved.
Show resolved Hide resolved
},
"preferred_subnet_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"preferred_file_server_ip": {
Type: schema.TypeString,
Computed: true,
},
"remote_administration_endpoint": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand All @@ -197,6 +224,14 @@ func resourceAwsFsxWindowsFileSystemCreate(d *schema.ResourceData, meta interfac
input.WindowsConfiguration.ActiveDirectoryId = aws.String(v.(string))
}

if v, ok := d.GetOk("deployment_type"); ok {
input.WindowsConfiguration.DeploymentType = aws.String(v.(string))
}

if v, ok := d.GetOk("preferred_subnet_id"); ok {
input.WindowsConfiguration.PreferredSubnetId = aws.String(v.(string))
}

if v, ok := d.GetOk("daily_automatic_backup_start_time"); ok {
input.WindowsConfiguration.DailyAutomaticBackupStartTime = aws.String(v.(string))
}
Expand Down Expand Up @@ -320,6 +355,10 @@ func resourceAwsFsxWindowsFileSystemRead(d *schema.ResourceData, meta interface{
d.Set("automatic_backup_retention_days", filesystem.WindowsConfiguration.AutomaticBackupRetentionDays)
d.Set("copy_tags_to_backups", filesystem.WindowsConfiguration.CopyTagsToBackups)
d.Set("daily_automatic_backup_start_time", filesystem.WindowsConfiguration.DailyAutomaticBackupStartTime)
d.Set("deployment_type", filesystem.WindowsConfiguration.DeploymentType)
d.Set("preferred_subnet_id", filesystem.WindowsConfiguration.PreferredSubnetId)
d.Set("preferred_file_server_ip", filesystem.WindowsConfiguration.PreferredFileServerIp)
d.Set("remote_administration_endpoint", filesystem.WindowsConfiguration.RemoteAdministrationEndpoint)
d.Set("dns_name", filesystem.DNSName)
d.Set("kms_key_id", filesystem.KmsKeyId)

Expand Down
145 changes: 125 additions & 20 deletions aws/resource_aws_fsx_windows_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,104 @@ func TestAccAWSFsxWindowsFileSystem_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "throughput_capacity", "8"),
resource.TestMatchResourceAttr(resourceName, "vpc_id", regexp.MustCompile(`^vpc-.+`)),
resource.TestCheckResourceAttrPair(resourceName, "vpc_id", "aws_vpc.test", "id"),
resource.TestMatchResourceAttr(resourceName, "weekly_maintenance_start_time", regexp.MustCompile(`^\d:\d\d:\d\d$`)),
resource.TestCheckResourceAttr(resourceName, "deployment_type", "SINGLE_AZ_1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"security_group_ids",
"skip_final_backup",
},
},
{
Config: testAccAwsFsxWindowsFileSystemConfigSubnetIds1WithSingleType("SINGLE_AZ_1"),
PlanOnly: true,
},
},
})
}

func TestAccAWSFsxWindowsFileSystem_singleAz2(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: testAccAwsFsxWindowsFileSystemConfigSubnetIds1WithSingleType("SINGLE_AZ_2"),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxWindowsFileSystemExists(resourceName, &filesystem),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "fsx", regexp.MustCompile(`file-system/fs-.+`)),
resource.TestCheckResourceAttr(resourceName, "automatic_backup_retention_days", "7"),
resource.TestCheckResourceAttr(resourceName, "copy_tags_to_backups", "false"),
resource.TestMatchResourceAttr(resourceName, "daily_automatic_backup_start_time", regexp.MustCompile(`^\d\d:\d\d$`)),
resource.TestMatchResourceAttr(resourceName, "dns_name", regexp.MustCompile(`^amznfsx\w{8}\.corp\.notexample\.com$`)),
testAccMatchResourceAttrRegionalARN(resourceName, "kms_key_id", "kms", regexp.MustCompile(`key/.+`)),
resource.TestCheckResourceAttr(resourceName, "network_interface_ids.#", "1"),
testAccCheckResourceAttrAccountID(resourceName, "owner_id"),
resource.TestCheckResourceAttr(resourceName, "security_group_ids.#", "0"),
resource.TestCheckResourceAttr(resourceName, "self_managed_active_directory.#", "0"),
resource.TestCheckResourceAttr(resourceName, "skip_final_backup", "true"),
resource.TestCheckResourceAttr(resourceName, "storage_capacity", "32"),
resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "throughput_capacity", "8"),
resource.TestCheckResourceAttrPair(resourceName, "vpc_id", "aws_vpc.test", "id"),
resource.TestMatchResourceAttr(resourceName, "weekly_maintenance_start_time", regexp.MustCompile(`^\d:\d\d:\d\d$`)),
resource.TestCheckResourceAttr(resourceName, "deployment_type", "SINGLE_AZ_2"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"security_group_ids",
"skip_final_backup",
},
},
},
})
}

func TestAccAWSFsxWindowsFileSystem_multiAz(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: testAccAwsFsxWindowsFileSystemConfigSubnetIds2(),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxWindowsFileSystemExists(resourceName, &filesystem),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "fsx", regexp.MustCompile(`file-system/fs-.+`)),
resource.TestCheckResourceAttr(resourceName, "automatic_backup_retention_days", "7"),
resource.TestCheckResourceAttr(resourceName, "copy_tags_to_backups", "false"),
resource.TestMatchResourceAttr(resourceName, "daily_automatic_backup_start_time", regexp.MustCompile(`^\d\d:\d\d$`)),
resource.TestMatchResourceAttr(resourceName, "dns_name", regexp.MustCompile(`^amznfsx\w{8}\.corp\.notexample\.com$`)),
testAccMatchResourceAttrRegionalARN(resourceName, "kms_key_id", "kms", regexp.MustCompile(`key/.+`)),
resource.TestCheckResourceAttr(resourceName, "network_interface_ids.#", "2"),
testAccCheckResourceAttrAccountID(resourceName, "owner_id"),
resource.TestCheckResourceAttr(resourceName, "self_managed_active_directory.#", "0"),
resource.TestCheckResourceAttr(resourceName, "skip_final_backup", "true"),
resource.TestCheckResourceAttr(resourceName, "storage_capacity", "32"),
resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "throughput_capacity", "8"),
resource.TestCheckResourceAttrPair(resourceName, "vpc_id", "aws_vpc.test", "id"),
resource.TestMatchResourceAttr(resourceName, "weekly_maintenance_start_time", regexp.MustCompile(`^\d:\d\d:\d\d$`)),
resource.TestCheckResourceAttr(resourceName, "deployment_type", "MULTI_AZ_1"),
),
},
{
Expand Down Expand Up @@ -129,7 +225,7 @@ func TestAccAWSFsxWindowsFileSystem_disappears(t *testing.T) {
Config: testAccAwsFsxWindowsFileSystemConfigSubnetIds1(),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxWindowsFileSystemExists(resourceName, &filesystem),
testAccCheckFsxWindowsFileSystemDisappears(&filesystem),
testAccCheckResourceDisappears(testAccProvider, resourceAwsFsxWindowsFileSystem(), resourceName),
),
ExpectNonEmptyPlan: true,
},
Expand Down Expand Up @@ -609,24 +705,6 @@ func testAccCheckFsxWindowsFileSystemDestroy(s *terraform.State) error {
return nil
}

func testAccCheckFsxWindowsFileSystemDisappears(filesystem *fsx.FileSystem) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).fsxconn

input := &fsx.DeleteFileSystemInput{
FileSystemId: filesystem.FileSystemId,
}

_, err := conn.DeleteFileSystem(input)

if err != nil {
return err
}

return waitForFsxFileSystemDeletion(conn, aws.StringValue(filesystem.FileSystemId), 30*time.Minute)
}
}

func testAccCheckFsxWindowsFileSystemNotRecreated(i, j *fsx.FileSystem) resource.TestCheckFunc {
return func(s *terraform.State) error {
if aws.StringValue(i.FileSystemId) != aws.StringValue(j.FileSystemId) {
Expand Down Expand Up @@ -905,6 +983,33 @@ resource "aws_fsx_windows_file_system" "test" {
`)
}

func testAccAwsFsxWindowsFileSystemConfigSubnetIds1WithSingleType(azType string) string {
return testAccAwsFsxWindowsFileSystemConfigBase() + fmt.Sprintf(`
resource "aws_fsx_windows_file_system" "test" {
active_directory_id = "${aws_directory_service_directory.test.id}"
skip_final_backup = true
storage_capacity = 32
deployment_type = %[1]q
subnet_ids = ["${aws_subnet.test1.id}"]
throughput_capacity = 8
}
`, azType)
}

func testAccAwsFsxWindowsFileSystemConfigSubnetIds2() string {
return testAccAwsFsxWindowsFileSystemConfigBase() + fmt.Sprintf(`
resource "aws_fsx_windows_file_system" "test" {
active_directory_id = "${aws_directory_service_directory.test.id}"
skip_final_backup = true
storage_capacity = 32
deployment_type = "MULTI_AZ_1"
subnet_ids = ["${aws_subnet.test1.id}", "${aws_subnet.test2.id}"]
preferred_subnet_id = "${aws_subnet.test1.id}"
throughput_capacity = 8
}
`)
}

func testAccAwsFsxWindowsFileSystemConfigTags1(tagKey1, tagValue1 string) string {
return testAccAwsFsxWindowsFileSystemConfigBase() + fmt.Sprintf(`
resource "aws_fsx_windows_file_system" "test" {
Expand Down
6 changes: 5 additions & 1 deletion website/docs/r/fsx_windows_file_system.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ resource "aws_fsx_windows_file_system" "example" {
The following arguments are supported:

* `storage_capacity` - (Required) Storage capacity (GiB) of the file system. Minimum of 32 and maximum of 65536.
* `subnet_ids` - (Required) A list of IDs for the subnets that the file system will be accessible from. File systems support only one subnet. The file server is also launched in that subnet's Availability Zone.
* `subnet_ids` - (Required) A list of IDs for the subnets that the file system will be accessible from. To specify more than a single subnet set `deployment_type` to `MULTI_AZ_1`.
* `throughput_capacity` - (Required) Throughput (megabytes per second) of the file system in power of 2 increments. Minimum of `8` and maximum of `2048`.
* `active_directory_id` - (Optional) The ID for an existing Microsoft Active Directory instance that the file system should join when it's created. Cannot be specified with `self_managed_active_directory`.
* `automatic_backup_retention_days` - (Optional) The number of days to retain automatic backups. Minimum of `0` and maximum of `35`. Defaults to `7`. Set to `0` to disable.
Expand All @@ -65,6 +65,8 @@ The following arguments are supported:
* `skip_final_backup` - (Optional) When enabled, will skip the default final backup taken when the file system is deleted. This configuration must be applied separately before attempting to delete the resource to have the desired behavior. Defaults to `false`.
* `tags` - (Optional) A map of tags to assign to the file system.
* `weekly_maintenance_start_time` - (Optional) The preferred start time (in `d:HH:MM` format) to perform weekly maintenance, in the UTC time zone.
* `deployment_type` - (Optional) Specifies the file system deployment type, valid values are `MULTI_AZ_1` and `SINGLE_AZ_1`. Default value is `SINGLE_AZ_1`.
* `preferred_subnet_id` - (Optional) Specifies the subnet in which you want the preferred file server to be located. Required for when deployment type is `MULTI_AZ_1`.

### self_managed_active_directory

Expand All @@ -87,6 +89,8 @@ In addition to all arguments above, the following attributes are exported:
* `network_interface_ids` - Set of Elastic Network Interface identifiers from which the file system is accessible.
* `owner_id` - AWS account identifier that created the file system.
* `vpc_id` - Identifier of the Virtual Private Cloud for the file system.
* `preferred_file_server_ip` - The IP address of the primary, or preferred, file server.
* `remote_administration_endpoint` - For `MULTI_AZ_1` deployment types, use this endpoint when performing administrative tasks on the file system using Amazon FSx Remote PowerShell. For `SINGLE_AZ_1` deployment types, this is the DNS name of the file system.

## Timeouts

Expand Down