Skip to content

Commit

Permalink
fsx ontap - add route tables and endpoint ip args
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 committed Sep 18, 2021
1 parent fd9ecdf commit 84a0c4c
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 61 deletions.
127 changes: 76 additions & 51 deletions aws/resource_aws_fsx_ontap_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,50 @@ func resourceAwsFsxOntapFileSystem() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"automatic_backup_retention_days": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
ValidateFunc: validation.IntBetween(0, 90),
},
"backup_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"daily_automatic_backup_start_time": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.All(
validation.StringLenBetween(5, 5),
validation.StringMatch(regexp.MustCompile(`^([01]\d|2[0-3]):?([0-5]\d)$`), "must be in the format HH:MM"),
),
},
"deployment_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(fsx.OntapDeploymentType_Values(), false),
},
"dns_name": {
Type: schema.TypeString,
Computed: true,
},
"endpoint_ip_address_range": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validateIpv4CIDRNetworkAddress,
},
"kms_key_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validateArn,
},
"network_interface_ids": {
// As explained in https://docs.aws.amazon.com/fsx/latest/OntapGuide/mounting-on-premises.html, the first
// network_interface_id is the primary one, so ordering matters. Use TypeList instead of TypeSet to preserve it.
Expand All @@ -72,11 +107,25 @@ func resourceAwsFsxOntapFileSystem() *schema.Resource {
MaxItems: 50,
Elem: &schema.Schema{Type: schema.TypeString},
},
"route_table_ids": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
MaxItems: 50,
Elem: &schema.Schema{Type: schema.TypeString},
},
"storage_capacity": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1024, 192*1024),
},
"storage_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: fsx.StorageTypeSsd,
ValidateFunc: validation.StringInSlice(fsx.StorageType_Values(), false),
},
"subnet_ids": {
Type: schema.TypeList,
Required: true,
Expand All @@ -87,6 +136,12 @@ func resourceAwsFsxOntapFileSystem() *schema.Resource {
},
"tags": tagsSchema(),
"tags_all": tagsSchemaComputed(),
"throughput_capacity": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntInSlice([]int{512, 1024, 2048}),
},
"vpc_id": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -100,47 +155,6 @@ func resourceAwsFsxOntapFileSystem() *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,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(fsx.OntapDeploymentType_Values(), false),
},
"kms_key_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validateArn,
},
"automatic_backup_retention_days": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
ValidateFunc: validation.IntBetween(0, 90),
},
"daily_automatic_backup_start_time": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.All(
validation.StringLenBetween(5, 5),
validation.StringMatch(regexp.MustCompile(`^([01]\d|2[0-3]):?([0-5]\d)$`), "must be in the format HH:MM"),
),
},
"storage_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: fsx.StorageTypeSsd,
ValidateFunc: validation.StringInSlice(fsx.StorageType_Values(), false),
},
"throughput_capacity": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntInSlice([]int{512, 1024, 2048}),
},
},

CustomizeDiff: customdiff.Sequence(
Expand Down Expand Up @@ -194,6 +208,10 @@ func resourceAwsFsxOntapFileSystemCreate(d *schema.ResourceData, meta interface{
backupInput.KmsKeyId = aws.String(v.(string))
}

if v, ok := d.GetOk("endpoint_ip_address_range"); ok {
input.OntapConfiguration.EndpointIpAddressRange = aws.String(v.(string))
}

if v, ok := d.GetOk("daily_automatic_backup_start_time"); ok {
input.OntapConfiguration.DailyAutomaticBackupStartTime = aws.String(v.(string))
}
Expand All @@ -203,6 +221,10 @@ func resourceAwsFsxOntapFileSystemCreate(d *schema.ResourceData, meta interface{
backupInput.SecurityGroupIds = expandStringSet(v.(*schema.Set))
}

if v, ok := d.GetOk("route_table_ids"); ok {
input.OntapConfiguration.RouteTableIds = expandStringSet(v.(*schema.Set))
}

if len(tags) > 0 {
input.Tags = tags.IgnoreAws().FsxTags()
backupInput.Tags = tags.IgnoreAws().FsxTags()
Expand Down Expand Up @@ -313,6 +335,15 @@ func resourceAwsFsxOntapFileSystemRead(d *schema.ResourceData, meta interface{})
d.Set("dns_name", filesystem.DNSName)
d.Set("deployment_type", ontapConfig.DeploymentType)
d.Set("storage_type", filesystem.StorageType)
d.Set("vpc_id", filesystem.VpcId)
d.Set("weekly_maintenance_start_time", ontapConfig.WeeklyMaintenanceStartTime)
d.Set("automatic_backup_retention_days", ontapConfig.AutomaticBackupRetentionDays)
d.Set("daily_automatic_backup_start_time", ontapConfig.DailyAutomaticBackupStartTime)
d.Set("throughput_capacity", ontapConfig.ThroughputCapacity)
d.Set("preferred_subnet_id", ontapConfig.PreferredSubnetId)
d.Set("endpoint_ip_address_range", ontapConfig.EndpointIpAddressRange)
d.Set("owner_id", filesystem.OwnerId)
d.Set("storage_capacity", filesystem.StorageCapacity)

if filesystem.KmsKeyId != nil {
d.Set("kms_key_id", filesystem.KmsKeyId)
Expand All @@ -322,13 +353,14 @@ func resourceAwsFsxOntapFileSystemRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("error setting network_interface_ids: %w", err)
}

d.Set("owner_id", filesystem.OwnerId)
d.Set("storage_capacity", filesystem.StorageCapacity)

if err := d.Set("subnet_ids", aws.StringValueSlice(filesystem.SubnetIds)); err != nil {
return fmt.Errorf("error setting subnet_ids: %w", err)
}

if err := d.Set("route_table_ids", aws.StringValueSlice(ontapConfig.RouteTableIds)); err != nil {
return fmt.Errorf("error setting subnet_ids: %w", err)
}

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

//lintignore:AWSR002
Expand All @@ -340,13 +372,6 @@ func resourceAwsFsxOntapFileSystemRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("error setting tags_all: %w", err)
}

d.Set("vpc_id", filesystem.VpcId)
d.Set("weekly_maintenance_start_time", ontapConfig.WeeklyMaintenanceStartTime)
d.Set("automatic_backup_retention_days", ontapConfig.AutomaticBackupRetentionDays)
d.Set("daily_automatic_backup_start_time", ontapConfig.DailyAutomaticBackupStartTime)
d.Set("throughput_capacity", ontapConfig.ThroughputCapacity)
d.Set("preferred_subnet_id", ontapConfig.PreferredSubnetId)

return nil
}

Expand Down
109 changes: 99 additions & 10 deletions aws/resource_aws_fsx_ontap_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ func TestAccAWSFsxOntapFileSystem_basic(t *testing.T) {
var filesystem fsx.FileSystem
resourceName := "aws_fsx_ontap_file_system.test"

deploymentType := fsx.OntapDeploymentTypeMultiAz1

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(fsx.EndpointsID, t) },
ErrorCheck: testAccErrorCheck(t, fsx.EndpointsID),
Expand All @@ -97,10 +95,13 @@ func TestAccAWSFsxOntapFileSystem_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
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", deploymentType),
resource.TestCheckResourceAttr(resourceName, "deployment_type", fsx.OntapDeploymentTypeMultiAz1),
resource.TestCheckResourceAttr(resourceName, "automatic_backup_retention_days", "0"),
resource.TestCheckResourceAttr(resourceName, "storage_type", fsx.StorageTypeSsd),
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.TestCheckResourceAttr(resourceName, "throughput_capacity", "512"),
resource.TestCheckResourceAttrPair(resourceName, "preferred_subnet_id", "aws_subnet.test1", "id"),
),
Expand All @@ -115,6 +116,33 @@ func TestAccAWSFsxOntapFileSystem_basic(t *testing.T) {
})
}

func TestAccAWSFsxOntapFileSystem_endpointIpAddressRange(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: testAccAwsFsxOntapFileSystemConfigEndpointIpAddressRange(),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxOntapFileSystemExists(resourceName, &filesystem),
resource.TestCheckResourceAttr(resourceName, "endpoint_ip_address_range", "198.19.255.0/24"),
),
},
{
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 @@ -172,6 +200,34 @@ func TestAccAWSFsxOntapFileSystem_SecurityGroupIds(t *testing.T) {
})
}

func TestAccAWSFsxOntapFileSystem_routeTableIds(t *testing.T) {
var filesystem1 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: testAccAwsFsxOntapFileSystemConfigRouteTable(),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxOntapFileSystemExists(resourceName, &filesystem1),
resource.TestCheckResourceAttr(resourceName, "route_table_ids.#", "1"),
resource.TestCheckTypeSetElemAttrPair(resourceName, "route_table_ids.*", "aws_route_table.test", "id"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"security_group_ids"},
},
},
})
}

func TestAccAWSFsxOntapFileSystem_StorageCapacity(t *testing.T) {
var filesystem1, filesystem2 fsx.FileSystem
resourceName := "aws_fsx_ontap_file_system.test"
Expand Down Expand Up @@ -504,6 +560,35 @@ resource "aws_fsx_ontap_file_system" "test" {
`)
}

func testAccAwsFsxOntapFileSystemConfigEndpointIpAddressRange() 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
endpoint_ip_address_range = "198.19.255.0/24"
}
`)
}

func testAccAwsFsxOntapFileSystemConfigRouteTable() string {
return composeConfig(testAccAwsFsxOntapFileSystemConfigBase(), `
resource "aws_route_table" "test" {
vpc_id = aws_vpc.test.id
}
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_route_table.test.id]
}
`)
}

func testAccAwsFsxOntapFileSystemConfigSecurityGroupIds1() string {
return composeConfig(testAccAwsFsxOntapFileSystemConfigBase(), `
resource "aws_security_group" "test1" {
Expand Down Expand Up @@ -577,20 +662,24 @@ resource "aws_security_group" "test2" {
}
resource "aws_fsx_ontap_file_system" "test" {
security_group_ids = [aws_security_group.test1.id, aws_security_group.test2.id]
storage_capacity = 1024
subnet_ids = [aws_subnet.test1.id]
deployment_type = "MULTI_AZ_1"
security_group_ids = [aws_security_group.test1.id, aws_security_group.test2.id]
storage_capacity = 1024
subnet_ids = [aws_subnet.test1.id]
deployment_type = "MULTI_AZ_1"
throughput_capacity = 512
preferred_subnet_id = aws_subnet.test1.id
}
`)
}

func testAccAwsFsxOntapFileSystemConfigStorageCapacity(storageCapacity int) string {
return composeConfig(testAccAwsFsxOntapFileSystemConfigBase(), fmt.Sprintf(`
resource "aws_fsx_ontap_file_system" "test" {
storage_capacity = %[1]d
subnet_ids = [aws_subnet.test1.id]
deployment_type = "MULTI_AZ_1"
storage_capacity = %[1]d
subnet_ids = [aws_subnet.test1.id]
deployment_type = "MULTI_AZ_1"
throughput_capacity = 512
preferred_subnet_id = aws_subnet.test1.id
}
`, storageCapacity))
}
Expand Down

0 comments on commit 84a0c4c

Please sign in to comment.