-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32624 from R-Campbell/f-aws_fsx_ontap_storage_vir…
…tual_machines [New Data Source] `fsx_ontap_storage_virtual_machines`
- Loading branch information
Showing
6 changed files
with
176 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-data-source | ||
aws_fsx_ontap_storage_virtual_machines | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
internal/service/fsx/ontap_storage_virtual_machines_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package fsx | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/fsx" | ||
"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" | ||
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" | ||
) | ||
|
||
// @SDKDataSource("aws_fsx_ontap_storage_virtual_machines", name="ONTAP Storage Virtual Machines") | ||
func DataSourceONTAPStorageVirtualMachines() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadWithoutTimeout: dataSourceONTAPStorageVirtualMachinesRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"filter": DataSourceStorageVirtualMachineFiltersSchema(), | ||
"ids": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceONTAPStorageVirtualMachinesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
conn := meta.(*conns.AWSClient).FSxConn(ctx) | ||
|
||
input := &fsx.DescribeStorageVirtualMachinesInput{} | ||
|
||
input.Filters = BuildStorageVirtualMachineFiltersDataSource( | ||
d.Get("filter").(*schema.Set), | ||
) | ||
|
||
if len(input.Filters) == 0 { | ||
input.Filters = nil | ||
} | ||
|
||
svms, err := findStorageVirtualMachines(ctx, conn, input, tfslices.PredicateTrue[*fsx.StorageVirtualMachine]()) | ||
|
||
if err != nil { | ||
return sdkdiag.AppendErrorf(diags, "reading FSx ONTAP Storage Virtual Machines: %s", err) | ||
} | ||
|
||
var svmIDs []string | ||
|
||
for _, svm := range svms { | ||
svmIDs = append(svmIDs, aws.StringValue(svm.StorageVirtualMachineId)) | ||
} | ||
|
||
d.SetId(meta.(*conns.AWSClient).Region) | ||
d.Set("ids", svmIDs) | ||
|
||
return diags | ||
} |
59 changes: 59 additions & 0 deletions
59
internal/service/fsx/ontap_storage_virtual_machines_data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package fsx_test | ||
|
||
import ( | ||
"fmt" | ||
"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 TestAccFSxONTAPStorageVirtualMachinesDataSource_Filter(t *testing.T) { | ||
ctx := acctest.Context(t) | ||
|
||
if testing.Short() { | ||
t.Skip("skipping long-running test in short mode") | ||
} | ||
|
||
dataSourceName := "data.aws_fsx_ontap_storage_virtual_machines.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, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccONTAPStorageVirtualMachinesDataSourceConfig_filter(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceName, "ids.#", "2"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccONTAPStorageVirtualMachinesDataSourceConfig_filter(rName string) string { | ||
return acctest.ConfigCompose(testAccONTAPStorageVirtualMachineConfig_base(rName), fmt.Sprintf(` | ||
resource "aws_fsx_ontap_storage_virtual_machine" "test" { | ||
count = 2 | ||
file_system_id = aws_fsx_ontap_file_system.test.id | ||
name = "%[1]s-${count.index}" | ||
} | ||
data "aws_fsx_ontap_storage_virtual_machines" "test" { | ||
filter { | ||
name = "file-system-id" | ||
values = [aws_fsx_ontap_file_system.test.id] | ||
} | ||
depends_on = [aws_fsx_ontap_storage_virtual_machine.test] | ||
} | ||
`, rName)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
website/docs/d/fsx_ontap_storage_virtual_machines.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
subcategory: "FSx" | ||
layout: "aws" | ||
page_title: "AWS: aws_fsx_ontap_storage_virtual_machines" | ||
description: |- | ||
This resource can be useful for getting back a set of FSx ONTAP Storage Virtual Machine (SVM) IDs. | ||
--- | ||
|
||
# Data Source: aws_fsx_ontap_storage_virtual_machines | ||
|
||
This resource can be useful for getting back a set of FSx ONTAP Storage Virtual Machine (SVM) IDs. | ||
|
||
## Example Usage | ||
|
||
The following shows outputting all SVM IDs for a given FSx ONTAP File System. | ||
|
||
``` | ||
data "aws_fsx_ontap_storage_virtual_machines" "example" { | ||
filter { | ||
name = "file-system-id" | ||
values = ["fs-12345678"] | ||
} | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `filter` - (Optional) Configuration block. Detailed below. | ||
|
||
### filter | ||
|
||
This block allows for complex filters. | ||
|
||
The following arguments are required: | ||
|
||
* `name` - (Required) Name of the field to filter by, as defined by [the underlying AWS API](https://docs.aws.amazon.com/fsx/latest/APIReference/API_StorageVirtualMachineFilter.html). | ||
* `values` - (Required) Set of values that are accepted for the given field. An SVM will be selected if any one of the given values matches. | ||
|
||
## Attributes Reference | ||
|
||
* `ids` - List of all SVM IDs found. |