-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
d/aws_devopsguru_resource_collection: new data source
This data source will allow practitioners to read AWS DevOps Guru resource collection data with Terraform. ```console % make testacc PKG=devopsguru TESTS=TestAccDevOpsGuru_serial/ResourceCollectionDataSource/ ==> Checking that code complies with gofmt requirements... TF_ACC=1 go1.21.8 test ./internal/service/devopsguru/... -v -count 1 -parallel 20 -run='TestAccDevOpsGuru_serial/ResourceCollectionDataSource/' -timeout 360m --- PASS: TestAccDevOpsGuru_serial (10.49s) --- PASS: TestAccDevOpsGuru_serial/ResourceCollectionDataSource (10.49s) --- PASS: TestAccDevOpsGuru_serial/ResourceCollectionDataSource/basic (10.49s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/devopsguru 15.982s ```
- Loading branch information
Showing
7 changed files
with
225 additions
and
1 deletion.
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_devopsguru_resource_collection | ||
``` |
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
119 changes: 119 additions & 0 deletions
119
internal/service/devopsguru/resource_collection_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,119 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package devopsguru | ||
|
||
import ( | ||
"context" | ||
|
||
awstypes "github.com/aws/aws-sdk-go-v2/service/devopsguru/types" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/hashicorp/terraform-provider-aws/internal/create" | ||
"github.com/hashicorp/terraform-provider-aws/internal/framework" | ||
"github.com/hashicorp/terraform-provider-aws/internal/framework/flex" | ||
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
// @FrameworkDataSource(name="Resource Collection") | ||
func newDataSourceResourceCollection(context.Context) (datasource.DataSourceWithConfigure, error) { | ||
return &dataSourceResourceCollection{}, nil | ||
} | ||
|
||
const ( | ||
DSNameResourceCollection = "Resource Collection Data Source" | ||
) | ||
|
||
type dataSourceResourceCollection struct { | ||
framework.DataSourceWithConfigure | ||
} | ||
|
||
func (d *dataSourceResourceCollection) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name | ||
resp.TypeName = "aws_devopsguru_resource_collection" | ||
} | ||
|
||
func (d *dataSourceResourceCollection) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"id": framework.IDAttribute(), | ||
"type": schema.StringAttribute{ | ||
Required: true, | ||
CustomType: fwtypes.StringEnumType[awstypes.ResourceCollectionType](), | ||
}, | ||
}, | ||
Blocks: map[string]schema.Block{ | ||
"cloudformation": schema.ListNestedBlock{ | ||
CustomType: fwtypes.NewListNestedObjectTypeOf[cloudformationData](ctx), | ||
NestedObject: schema.NestedBlockObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"stack_names": schema.ListAttribute{ | ||
Computed: true, | ||
CustomType: fwtypes.ListOfStringType, | ||
ElementType: types.StringType, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"tags": schema.ListNestedBlock{ | ||
CustomType: fwtypes.NewListNestedObjectTypeOf[tagsData](ctx), | ||
NestedObject: schema.NestedBlockObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"app_boundary_key": schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
"tag_values": schema.ListAttribute{ | ||
Computed: true, | ||
CustomType: fwtypes.ListOfStringType, | ||
ElementType: types.StringType, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
func (d *dataSourceResourceCollection) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
conn := d.Meta().DevOpsGuruClient(ctx) | ||
|
||
var data dataSourceResourceCollectionData | ||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
data.ID = types.StringValue(data.Type.ValueString()) | ||
|
||
out, err := findResourceCollectionByID(ctx, conn, data.Type.ValueString()) | ||
if err != nil { | ||
resp.Diagnostics.AddError( | ||
create.ProblemStandardMessage(names.DevOpsGuru, create.ErrActionReading, DSNameResourceCollection, data.Type.String(), err), | ||
err.Error(), | ||
) | ||
return | ||
} | ||
|
||
resp.Diagnostics.Append(flex.Flatten(ctx, out, &data)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
// Fields named "Tags" are currently hardcoded to be ignored by AutoFlex. Flattening the Tags | ||
// struct from the response into state.Tags is a temporary workaround until the AutoFlex | ||
// options implementation can be merged. | ||
// | ||
// Ref: https://github.com/hashicorp/terraform-provider-aws/pull/36437 | ||
resp.Diagnostics.Append(flex.Flatten(ctx, out.Tags, &data.Tags)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} | ||
|
||
type dataSourceResourceCollectionData struct { | ||
CloudFormation fwtypes.ListNestedObjectValueOf[cloudformationData] `tfsdk:"cloudformation"` | ||
ID types.String `tfsdk:"id"` | ||
Tags fwtypes.ListNestedObjectValueOf[tagsData] `tfsdk:"tags"` | ||
Type fwtypes.StringEnum[awstypes.ResourceCollectionType] `tfsdk:"type"` | ||
} |
51 changes: 51 additions & 0 deletions
51
internal/service/devopsguru/resource_collection_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,51 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package devopsguru_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-provider-aws/internal/acctest" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
func testAccResourceCollectionDataSource_basic(t *testing.T) { | ||
ctx := acctest.Context(t) | ||
dataSourceName := "data.aws_devopsguru_resource_collection.test" | ||
resourceName := "aws_devopsguru_resource_collection.test" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acctest.PreCheck(ctx, t) | ||
acctest.PreCheckPartitionHasService(t, names.DevOpsGuruEndpointID) | ||
}, | ||
ErrorCheck: acctest.ErrorCheck(t, names.DevOpsGuruServiceID), | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
CheckDestroy: testAccCheckResourceCollectionDestroy(ctx), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccResourceCollectionDataSourceConfig_basic(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "type", resourceName, "type"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccResourceCollectionDataSourceConfig_basic() string { | ||
return ` | ||
resource "aws_devopsguru_resource_collection" "test" { | ||
type = "AWS_SERVICE" | ||
cloudformation { | ||
stack_names = ["*"] | ||
} | ||
} | ||
data "aws_devopsguru_resource_collection" "test" { | ||
type = aws_devopsguru_resource_collection.test.type | ||
} | ||
` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
website/docs/d/devopsguru_resource_collection.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,44 @@ | ||
--- | ||
subcategory: "DevOps Guru" | ||
layout: "aws" | ||
page_title: "AWS: aws_devopsguru_resource_collection" | ||
description: |- | ||
Terraform data source for managing an AWS DevOps Guru Resource Collection. | ||
--- | ||
|
||
# Data Source: aws_devopsguru_resource_collection | ||
|
||
Terraform data source for managing an AWS DevOps Guru Resource Collection. | ||
|
||
## Example Usage | ||
|
||
### Basic Usage | ||
|
||
```terraform | ||
data "aws_devopsguru_resource_collection" "example" { | ||
type = "AWS_SERVICE" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are required: | ||
|
||
* `type` - (Required) Type of AWS resource collection to create. Valid values are `AWS_CLOUD_FORMATION`, `AWS_SERVICE`, and `AWS_TAGS`. | ||
|
||
## Attribute Reference | ||
|
||
This data source exports the following attributes in addition to the arguments above: | ||
|
||
* `cloudformation` - A collection of AWS CloudFormation stacks. See [`cloudformation`](#cloudformation-attribute-reference) below for additional details. | ||
* `id` - Type of AWS resource collection to create (same value as `type`). | ||
* `tags` - AWS tags used to filter the resources in the resource collection. See [`tags`](#tags-attribute-reference) below for additional details. | ||
|
||
### `cloudformation` Attribute Reference | ||
|
||
* `stack_names` - Array of the names of the AWS CloudFormation stacks. | ||
|
||
### `tags` Attribute Reference | ||
|
||
* `app_boundary_key` - An AWS tag key that is used to identify the AWS resources that DevOps Guru analyzes. | ||
* `tag_values` - Array of tag values. |
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