Skip to content

Commit

Permalink
fsx ontap fs - add endpoint attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 committed Sep 18, 2021
1 parent 84a0c4c commit 86b031f
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
78 changes: 78 additions & 0 deletions aws/resource_aws_fsx_ontap_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,48 @@ func resourceAwsFsxOntapFileSystem() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"endpoints": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"intercluster": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dns_name": {
Type: schema.TypeString,
Computed: true,
},
"ip_addresses": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
"management": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dns_name": {
Type: schema.TypeString,
Computed: true,
},
"ip_addresses": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
},
},
},
"endpoint_ip_address_range": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -361,6 +403,10 @@ func resourceAwsFsxOntapFileSystemRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("error setting subnet_ids: %w", err)
}

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

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

//lintignore:AWSR002
Expand Down Expand Up @@ -399,3 +445,35 @@ func resourceAwsFsxOntapFileSystemDelete(d *schema.ResourceData, meta interface{

return nil
}

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

m := make(map[string]interface{})
if rs.Intercluster != nil {
m["intercluster"] = flattenFsxOntapFileSystemEndpoint(rs.Intercluster)
}
if rs.Management != nil {
m["management"] = flattenFsxOntapFileSystemEndpoint(rs.Management)
}

return []interface{}{m}
}

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

m := make(map[string]interface{})
if rs.DNSName != nil {
m["dns_name"] = aws.StringValue(rs.DNSName)
}
if rs.IpAddresses != nil {
m["ip_addresses"] = flattenStringSet(rs.IpAddresses)
}

return []interface{}{m}
}
8 changes: 7 additions & 1 deletion aws/resource_aws_fsx_ontap_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func TestAccAWSFsxOntapFileSystem_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "network_interface_ids.#", "2"),
testAccCheckResourceAttrAccountID(resourceName, "owner_id"),
resource.TestCheckResourceAttr(resourceName, "storage_capacity", "1024"),
resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "2"),
resource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_ids.*", "aws_subnet.test1", "id"),
resource.TestCheckTypeSetElemAttrPair(resourceName, "subnet_ids.*", "aws_subnet.test2", "id"),
resource.TestCheckResourceAttr(resourceName, "security_group_ids.#", "0"),
Expand All @@ -104,6 +103,13 @@ func TestAccAWSFsxOntapFileSystem_basic(t *testing.T) {
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"),
resource.TestCheckResourceAttr(resourceName, "endpoints.#", "1"),
resource.TestCheckResourceAttr(resourceName, "endpoints.0.intecluster.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "endpoints.0.intecluster.0.dns_name"),
resource.TestCheckResourceAttrSet(resourceName, "endpoints.0.intecluster.0.ip_addresses"),
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"),
),
},
{
Expand Down

0 comments on commit 86b031f

Please sign in to comment.