Skip to content

Commit

Permalink
fsx ontap fs - disk config
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 committed Sep 18, 2021
1 parent 86b031f commit 99cf734
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
65 changes: 65 additions & 0 deletions aws/resource_aws_fsx_ontap_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ func resourceAwsFsxOntapFileSystem() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.StringInSlice(fsx.OntapDeploymentType_Values(), false),
},
"disk_iops_configuration": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"iops": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntBetween(0, 80000),
},
"mode": {
Type: schema.TypeString,
Optional: true,
Default: fsx.DiskIopsConfigurationModeAutomatic,
ValidateFunc: validation.StringInSlice(fsx.DiskIopsConfigurationMode_Values(), false),
},
},
},
},
"dns_name": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -258,6 +280,10 @@ func resourceAwsFsxOntapFileSystemCreate(d *schema.ResourceData, meta interface{
input.OntapConfiguration.DailyAutomaticBackupStartTime = aws.String(v.(string))
}

if v, ok := d.GetOk("disk_iops_configuration"); ok {
input.OntapConfiguration.DiskIopsConfiguration = expandFsxOntapFileDiskIopsConfiguration(v.([]interface{}))
}

if v, ok := d.GetOk("security_group_ids"); ok {
input.SecurityGroupIds = expandStringSet(v.(*schema.Set))
backupInput.SecurityGroupIds = expandStringSet(v.(*schema.Set))
Expand Down Expand Up @@ -407,6 +433,10 @@ func resourceAwsFsxOntapFileSystemRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("error setting endpoints: %w", err)
}

if err := d.Set("disk_iops_configuration", flattenFsxOntapFileDiskIopsConfiguration(ontapConfig.DiskIopsConfiguration)); err != nil {
return fmt.Errorf("error setting disk_iops_configuration: %w", err)
}

tags := keyvaluetags.FsxKeyValueTags(filesystem.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
Expand Down Expand Up @@ -446,6 +476,41 @@ func resourceAwsFsxOntapFileSystemDelete(d *schema.ResourceData, meta interface{
return nil
}

func expandFsxOntapFileDiskIopsConfiguration(cfg []interface{}) *fsx.DiskIopsConfiguration {
if len(cfg) < 1 {
return nil
}

conf := cfg[0].(map[string]interface{})

out := fsx.DiskIopsConfiguration{}

if v, ok := conf["mode"].(string); ok && len(v) > 0 {
out.Mode = aws.String(v)
}
if v, ok := conf["iops"].(int); ok {
out.Iops = aws.Int64(int64(v))
}

return &out
}

func flattenFsxOntapFileDiskIopsConfiguration(rs *fsx.DiskIopsConfiguration) []interface{} {
if rs == nil {
return []interface{}{}
}

m := make(map[string]interface{})
if rs.Mode != nil {
m["mode"] = aws.StringValue(rs.Mode)
}
if rs.Iops != nil {
m["iops"] = aws.Int64Value(rs.Iops)
}

return []interface{}{m}
}

func flattenFsxOntapFileSystemEndpoints(rs *fsx.FileSystemEndpoints) []interface{} {
if rs == nil {
return []interface{}{}
Expand Down
49 changes: 48 additions & 1 deletion aws/resource_aws_fsx_ontap_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestAccAWSFsxOntapFileSystem_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "kms_key_id"),
resource.TestCheckResourceAttrSet(resourceName, "endpoint_ip_address_range"),
resource.TestCheckResourceAttr(resourceName, "route_table_ids.#", "1"),
resource.TestCheckTypeSetElemAttrPair(resourceName, "route_table_ids.*", "aws_vpc.testt", "default_route_table_id"),
resource.TestCheckTypeSetElemAttrPair(resourceName, "route_table_ids.*", "aws_vpc.test", "default_route_table_id"),
resource.TestCheckResourceAttr(resourceName, "throughput_capacity", "512"),
resource.TestCheckResourceAttrPair(resourceName, "preferred_subnet_id", "aws_subnet.test1", "id"),
resource.TestCheckResourceAttr(resourceName, "endpoints.#", "1"),
Expand All @@ -110,6 +110,9 @@ func TestAccAWSFsxOntapFileSystem_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "endpoints.0.management.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "endpoints.0.management.0.dns_name"),
resource.TestCheckResourceAttrSet(resourceName, "endpoints.0.management.0.ip_addresses"),
resource.TestCheckResourceAttr(resourceName, "disk_iops_configuration.#", "1"),
resource.TestCheckResourceAttr(resourceName, "disk_iops_configuration.0.mode", "AUTOMATIC"),
resource.TestCheckResourceAttr(resourceName, "disk_iops_configuration.0.iops", "3072"),
),
},
{
Expand Down Expand Up @@ -149,6 +152,34 @@ func TestAccAWSFsxOntapFileSystem_endpointIpAddressRange(t *testing.T) {
})
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(fsx.EndpointsID, t) },
ErrorCheck: testAccErrorCheck(t, fsx.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckFsxOntapFileSystemDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsFsxOntapFileSystemConfigDiskIopsConfiguration(),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxOntapFileSystemExists(resourceName, &filesystem),
resource.TestCheckResourceAttr(resourceName, "disk_iops_configuration.#", "1"),
resource.TestCheckResourceAttr(resourceName, "disk_iops_configuration.0.mode", "USER_PROVISIONED"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"security_group_ids"},
},
},
})
}

func TestAccAWSFsxOntapFileSystem_disappears(t *testing.T) {
var filesystem fsx.FileSystem
resourceName := "aws_fsx_ontap_file_system.test"
Expand Down Expand Up @@ -579,6 +610,22 @@ resource "aws_fsx_ontap_file_system" "test" {
`)
}

func testAccAwsFsxOntapFileSystemConfigDiskIopsConfiguration() string {
return composeConfig(testAccAwsFsxOntapFileSystemConfigBase(), `
resource "aws_fsx_ontap_file_system" "test" {
storage_capacity = 1024
subnet_ids = [aws_subnet.test1.id, aws_subnet.test2.id]
deployment_type = "MULTI_AZ_1"
throughput_capacity = 512
preferred_subnet_id = aws_subnet.test1.id
disk_iops_configuration {
mode = "USER_PROVISIONED"
}
}
`)
}

func testAccAwsFsxOntapFileSystemConfigRouteTable() string {
return composeConfig(testAccAwsFsxOntapFileSystemConfigBase(), `
resource "aws_route_table" "test" {
Expand Down

0 comments on commit 99cf734

Please sign in to comment.