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

[New Data Source]: aws_fsx_ontap_file_system #32503

Merged
merged 9 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/32503.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_fsx_ontap_file_system
```
228 changes: 228 additions & 0 deletions internal/service/fsx/ontap_file_system_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
package fsx

import (
"context"

"github.com/aws/aws-sdk-go/aws"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
)

// @SDKDataSource("aws_fsx_ontap_file_system", name="Ontap File System")
func DataSourceOntapFileSystem() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceOntapFileSystemRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"automatic_backup_retention_days": {
Type: schema.TypeInt,
Computed: true,
},
"daily_automatic_backup_start_time": {
Type: schema.TypeString,
Computed: true,
},
"deployment_type": {
Type: schema.TypeString,
Computed: true,
},
"disk_iops_configuration": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"iops": {
Type: schema.TypeInt,
Computed: true,
},
"mode": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"dns_name": {
Type: schema.TypeString,
Computed: true,
},
"endpoint_ip_address_range": {
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},
},
},
},
},
},
},
},
"id": {
Type: schema.TypeString,
Required: true,
},
"kms_key_id": {
Type: schema.TypeString,
Computed: true,
},
"network_interface_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"owner_id": {
Type: schema.TypeString,
Computed: true,
},
"preferred_subnet_id": {
Type: schema.TypeString,
Computed: true,
},
"route_table_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"storage_capacity": {
Type: schema.TypeInt,
Computed: true,
},
"storage_type": {
Type: schema.TypeString,
Computed: true,
},
"subnet_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"tags": tftags.TagsSchemaComputed(),
"throughput_capacity": {
Type: schema.TypeInt,
Computed: true,
},
"vpc_id": {
Type: schema.TypeString,
Computed: true,
},
"weekly_maintenance_start_time": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

const (
DSNameOntapFileSystem = "Ontap File System Data Source"
)

func dataSourceOntapFileSystemRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

conn := meta.(*conns.AWSClient).FSxConn(ctx)
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

id := d.Get("id").(string)
filesystem, err := FindFileSystemByID(ctx, conn, id)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading FSx Ontap File System (%s): %s", d.Id(), err)
}

if filesystem.LustreConfiguration != nil {
return sdkdiag.AppendErrorf(diags, "expected FSx Ontap File System, found FSx Lustre File System: %s", d.Id())
}

if filesystem.WindowsConfiguration != nil {
return sdkdiag.AppendErrorf(diags, "expected FSx Ontap File System, found FSx Windows File System: %s", d.Id())
}

if filesystem.OpenZFSConfiguration != nil {
return sdkdiag.AppendErrorf(diags, "expected FSx Ontap File System, found FSx OpenZFS File System: %s", d.Id())
}

if filesystem.OntapConfiguration == nil {
return sdkdiag.AppendErrorf(diags, "reading FSx Ontap File System (%s): empty OntapConfiguration", d.Id())
}

d.SetId(aws.StringValue(filesystem.FileSystemId))
d.Set("arn", filesystem.ResourceARN)
d.Set("automatic_backup_retention_days", filesystem.OntapConfiguration.AutomaticBackupRetentionDays)
d.Set("daily_automatic_backup_start_time", filesystem.OntapConfiguration.DailyAutomaticBackupStartTime)
d.Set("deployment_type", filesystem.OntapConfiguration.DeploymentType)
if err := d.Set("disk_iops_configuration", flattenOntapFileDiskIopsConfiguration(filesystem.OntapConfiguration.DiskIopsConfiguration)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting disk_iops_configuration: %s", err)
}
d.Set("dns_name", filesystem.DNSName)
d.Set("endpoint_ip_address_range", filesystem.OntapConfiguration.EndpointIpAddressRange)
if err := d.Set("endpoints", flattenOntapFileSystemEndpoints(filesystem.OntapConfiguration.Endpoints)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting endpoints: %s", err)
}
d.Set("id", filesystem.FileSystemId)
d.Set("kms_key_id", filesystem.KmsKeyId)
d.Set("network_interface_ids", aws.StringValueSlice(filesystem.NetworkInterfaceIds))
d.Set("owner_id", filesystem.OwnerId)
d.Set("preferred_subnet_id", filesystem.OntapConfiguration.PreferredSubnetId)
d.Set("route_table_ids", aws.StringValueSlice(filesystem.OntapConfiguration.RouteTableIds))
d.Set("storage_capacity", filesystem.StorageCapacity)
d.Set("storage_type", filesystem.StorageType)
d.Set("subnet_ids", aws.StringValueSlice(filesystem.SubnetIds))
d.Set("throughput_capacity", filesystem.OntapConfiguration.ThroughputCapacity)
d.Set("vpc_id", filesystem.VpcId)
d.Set("weekly_maintenance_start_time", filesystem.OntapConfiguration.WeeklyMaintenanceStartTime)

tags := KeyValueTags(ctx, filesystem.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return sdkdiag.AppendErrorf(diags, "setting tags: %s", err)
}

return diags
}
63 changes: 63 additions & 0 deletions internal/service/fsx/ontap_file_system_data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package fsx_test

import (
"testing"

"github.com/aws/aws-sdk-go/service/fsx"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)

func TestAccFSxOntapFileSystemDataSource_Id(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

ctx := acctest.Context(t)
resourceName := "aws_fsx_ontap_file_system.test"
datasourceName := "data.aws_fsx_ontap_file_system.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, fsx.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckOntapFileSystemDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccOntapFileSystemDataSourceConfigId(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(datasourceName, "automatic_backup_retention_days", resourceName, "automatic_backup_retention_days"),
resource.TestCheckResourceAttrPair(datasourceName, "daily_automatic_backup_start_time", resourceName, "daily_automatic_backup_start_time"),
resource.TestCheckResourceAttrPair(datasourceName, "deployment_type", resourceName, "deployment_type"),
resource.TestCheckResourceAttrPair(datasourceName, "disk_iops_configuration", resourceName, "disk_iops_configuration"),
resource.TestCheckResourceAttrPair(datasourceName, "dns_name", resourceName, "dns_name"),
resource.TestCheckResourceAttrPair(datasourceName, "endpoint_ip_address_range", resourceName, "endpoint_ip_address_range"),
resource.TestCheckResourceAttrPair(datasourceName, "endpoints", resourceName, "endpoints"),
resource.TestCheckResourceAttrPair(datasourceName, "id", resourceName, "id"),
resource.TestCheckResourceAttrPair(datasourceName, "kms_key_id", resourceName, "kms_key_id"),
resource.TestCheckResourceAttrPair(datasourceName, "network_interface_ids", resourceName, "network_interface_ids"),
resource.TestCheckResourceAttrPair(datasourceName, "owner_id", resourceName, "owner_id"),
resource.TestCheckResourceAttrPair(datasourceName, "preferred_subnet_id", resourceName, "preferred_subnet_id"),
resource.TestCheckResourceAttrPair(datasourceName, "route_table_ids", resourceName, "route_table_ids"),
resource.TestCheckResourceAttrPair(datasourceName, "storage_capacity", resourceName, "storage_capacity"),
resource.TestCheckResourceAttrPair(datasourceName, "storage_type", resourceName, "storage_type"),
resource.TestCheckResourceAttrPair(datasourceName, "subnet_ids.#", resourceName, "subnet_ids.#"),
resource.TestCheckResourceAttrPair(datasourceName, "throughput_capacity", resourceName, "throughput_capacity"),
resource.TestCheckResourceAttrPair(datasourceName, "vpc_id", resourceName, "vpc_id"),
resource.TestCheckResourceAttrPair(datasourceName, "weekly_maintenance_start_time", resourceName, "weekly_maintenance_start_time"),
),
},
},
})
}

func testAccOntapFileSystemDataSourceConfigId(rName string) string {
return acctest.ConfigCompose(testAccONTAPFileSystemConfig_basic(rName), `
data "aws_fsx_ontap_file_system" "test" {
id = aws_fsx_ontap_file_system.test.id
}
`)
}
5 changes: 5 additions & 0 deletions internal/service/fsx/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions website/docs/d/fsx_ontap_file_system.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
subcategory: "FSx"
layout: "aws"
page_title: "AWS: aws_fsx_ontap_file_system"
description: |-
Retrieve information on FSx ONTAP File System.
---

# Data Source: aws_fsx_ontap_file_system

Retrieve information on FSx ONTAP File System.

## Example Usage

### Basic Usage

```terraform
data "aws_fsx_ontap_file_system" "example" {
id = "fs-12345678
}
```

## Argument Reference

The following arguments are required:

* `id` - (Required) Identifier of the file system (e.g. `fs-12345678`).

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `arn` - Amazon Resource Name of the file system.
* `automatic_backup_retention_days` - The number of days to retain automatic backups.
* `daily_automatic_backup_start_time` - The preferred time (in `HH:MM` format) to take daily automatic backups, in the UTC time zone.
* `deployment_type` - The file system deployment type.
* `disk_iops_configuration` - The SSD IOPS configuration for the Amazon FSx for NetApp ONTAP file system, specifying the number of provisioned IOPS and the provision mode. See [Disk IOPS](#disk-iops) Below.
* `dns_name` - DNS name for the file system (e.g. `fs-12345678.corp.example.com`).
* `endpoint_ip_address_range` - (Multi-AZ only) Specifies the IP address range in which the endpoints to access your file system exist.
* `endpoints` - The Management and Intercluster FileSystemEndpoints that are used to access data or to manage the file system using the NetApp ONTAP CLI, REST API, or NetApp SnapMirror. See [FileSystemEndpoints](#file-system-endpoints) below.
* `id` - Identifier of the file system (e.g. `fs-12345678`).
* `kms_key_id` - ARN for the KMS Key to encrypt the file system at rest.
* `network_interface_ids` - The IDs of the elastic network interfaces from which a specific file system is accessible.
* `owner_id` - AWS account identifier that created the file system.
* `preferred_subnet_id` - Specifies the subnet in which you want the preferred file server to be located.
* `route_table_ids` - (Multi-AZ only) The VPC route tables in which your file system's endpoints exist.
* `storage_capacity` - The storage capacity of the file system in gibibytes (GiB).
* `storage_type` - The type of storage the file system is using. If set to `SSD`, the file system uses solid state drive storage. If set to `HDD`, the file system uses hard disk drive storage.
* `subnet_ids` - Specifies the IDs of the subnets that the file system is accessible from. For the MULTI_AZ_1 file system deployment type, there are two subnet IDs, one for the preferred file server and one for the standby file server. The preferred file server subnet identified in the `preferred_subnet_id` property.
* `tags` - The tags associated with the file system.
* `throughput_capacity` - The sustained throughput of an Amazon FSx file system in Megabytes per second (MBps).
* `vpc_id` - The ID of the primary virtual private cloud (VPC) for the file system.
* `weekly_maintenance_start_time` - The preferred start time (in `D:HH:MM` format) to perform weekly maintenance, in the UTC time zone.

### Disk IOPS

* `iops` - The total number of SSD IOPS provisioned for the file system.
* `mode` - Specifies whether the file system is using the `AUTOMATIC` setting of SSD IOPS of 3 IOPS per GB of storage capacity, or if it using a `USER_PROVISIONED` value.

### File System Endpoints

* `intercluster` - A FileSystemEndpoint for managing your file system by setting up NetApp SnapMirror with other ONTAP systems. See [FileSystemEndpoint](#file-system-endpoint) below.
* `management` - A FileSystemEndpoint for managing your file system using the NetApp ONTAP CLI and NetApp ONTAP API. See [FileSystemEndpoint](#file-system-endpoint) below.

### File System Endpoint

* `DNSName` - The file system's DNS name. You can mount your file system using its DNS name.
* `IpAddresses` - IP addresses of the file system endpoint.