-
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 #22723 from kamilturek/f-aws_imagebuilder_infrastr…
…ucture_configurations_data_source d/aws_imagebuilder_infrastructure_configurations - new data source
- Loading branch information
Showing
5 changed files
with
179 additions
and
8 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_imagebuilder_infrastructure_configurations | ||
``` |
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
74 changes: 74 additions & 0 deletions
74
internal/service/imagebuilder/infrastructure_configurations_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,74 @@ | ||
package imagebuilder | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/imagebuilder" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-aws/internal/conns" | ||
) | ||
|
||
func DataSourceInfrastructureConfigurations() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceInfrastructureConfigurationsRead, | ||
Schema: map[string]*schema.Schema{ | ||
"arns": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"filter": dataSourceFiltersSchema(), | ||
"names": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceInfrastructureConfigurationsRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*conns.AWSClient).ImageBuilderConn | ||
|
||
input := &imagebuilder.ListInfrastructureConfigurationsInput{} | ||
|
||
if v, ok := d.GetOk("filter"); ok { | ||
input.Filters = buildFiltersDataSource(v.(*schema.Set)) | ||
} | ||
|
||
var results []*imagebuilder.InfrastructureConfigurationSummary | ||
|
||
err := conn.ListInfrastructureConfigurationsPages(input, func(page *imagebuilder.ListInfrastructureConfigurationsOutput, lastPage bool) bool { | ||
if page == nil { | ||
return !lastPage | ||
} | ||
|
||
for _, infrastructureConfigurationSummary := range page.InfrastructureConfigurationSummaryList { | ||
if infrastructureConfigurationSummary == nil { | ||
continue | ||
} | ||
|
||
results = append(results, infrastructureConfigurationSummary) | ||
} | ||
|
||
return !lastPage | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error reading Image Builder Infrastructure Configurations: %w", err) | ||
} | ||
|
||
var arns, names []string | ||
|
||
for _, r := range results { | ||
arns = append(arns, aws.StringValue(r.Arn)) | ||
names = append(names, aws.StringValue(r.Name)) | ||
} | ||
|
||
d.SetId(meta.(*conns.AWSClient).Region) | ||
d.Set("arns", arns) | ||
d.Set("names", names) | ||
|
||
return nil | ||
} |
55 changes: 55 additions & 0 deletions
55
internal/service/imagebuilder/infrastructure_configurations_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,55 @@ | ||
package imagebuilder_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/imagebuilder" | ||
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-aws/internal/acctest" | ||
) | ||
|
||
func TestAccImageBuilderInfrastructureConfigurationsDataSource_filter(t *testing.T) { | ||
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
dataSourceName := "data.aws_imagebuilder_infrastructure_configurations.test" | ||
resourceName := "aws_imagebuilder_infrastructure_configuration.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t) }, | ||
ErrorCheck: acctest.ErrorCheck(t, imagebuilder.EndpointsID), | ||
ProviderFactories: acctest.ProviderFactories, | ||
CheckDestroy: testAccCheckInfrastructureConfigurationDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccConfigInfrastructureConfigurations_filter(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceName, "arns.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "names.#", "1"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "arns.0", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "names.0", resourceName, "name"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccConfigInfrastructureConfigurations_filter(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_iam_instance_profile" "test" { | ||
name = %[1]q | ||
} | ||
resource "aws_imagebuilder_infrastructure_configuration" "test" { | ||
name = %[1]q | ||
instance_profile_name = aws_iam_instance_profile.test.name | ||
} | ||
data "aws_imagebuilder_infrastructure_configurations" "test" { | ||
filter { | ||
name = "name" | ||
values = [aws_imagebuilder_infrastructure_configuration.test.name] | ||
} | ||
} | ||
`, rName) | ||
} |
38 changes: 38 additions & 0 deletions
38
website/docs/d/imagebuilder_infrastructure_configurations.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,38 @@ | ||
--- | ||
subcategory: "Image Builder" | ||
layout: "aws" | ||
page_title: "AWS: aws_imagebuilder_infrastructure_configurations" | ||
description: |- | ||
Get information on Image Builder Infrastructure Configurations. | ||
--- | ||
|
||
# Data Source: aws_imagebuilder_infrastructure_configurations | ||
|
||
Use this data source to get the ARNs and names of Image Builder Infrastructure Configurations matching the specified criteria. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "aws_imagebuilder_infrastructure_configurations" "example" { | ||
filter { | ||
name = "name" | ||
values = ["example"] | ||
} | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `filter` - (Optional) Configuration block(s) for filtering. Detailed below. | ||
|
||
## filter Configuration Block | ||
|
||
The following arguments are supported by the `filter` configuration block: | ||
|
||
* `name` - (Required) The name of the filter field. Valid values can be found in the [Image Builder ListInfrastructureConfigurations API Reference](https://docs.aws.amazon.com/imagebuilder/latest/APIReference/API_ListInfrastructureConfigurations.html). | ||
* `values` - (Required) Set of values that are accepted for the given filter field. Results will be selected if any given value matches. | ||
|
||
## Attributes Reference | ||
|
||
* `arns` - Set of ARNs of the matched Image Builder Infrastructure Configurations. | ||
* `names` - Set of names of the matched Image Builder Infrastructure Configurations. |