-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
d/aws_servicecatalogappregistry_application: new data source (#36596)
This data source will allow practitioners to retreive AWS Service Catalog AppRegistry application data via Terraform. ```console % make testacc PKG=servicecatalogappregistry TESTS=TestAccServiceCatalogAppRegistryApplicationDataSource_ ==> Checking that code complies with gofmt requirements... TF_ACC=1 go1.21.8 test ./internal/service/servicecatalogappregistry/... -v -count 1 -parallel 20 -run='TestAccServiceCatalogAppRegistryApplicationDataSource_' -timeout 360m --- PASS: TestAccServiceCatalogAppRegistryApplicationDataSource_basic (10.84s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/servicecatalogappregistry 16.390s ```
- Loading branch information
Showing
5 changed files
with
176 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_servicecatalogappregistry_application | ||
``` |
78 changes: 78 additions & 0 deletions
78
internal/service/servicecatalogappregistry/application_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,78 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package servicecatalogappregistry | ||
|
||
import ( | ||
"context" | ||
|
||
"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" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
// @FrameworkDataSource(name="Application") | ||
func newDataSourceApplication(context.Context) (datasource.DataSourceWithConfigure, error) { | ||
return &dataSourceApplication{}, nil | ||
} | ||
|
||
const ( | ||
DSNameApplication = "Application Data Source" | ||
) | ||
|
||
type dataSourceApplication struct { | ||
framework.DataSourceWithConfigure | ||
} | ||
|
||
func (d *dataSourceApplication) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name | ||
resp.TypeName = "aws_servicecatalogappregistry_application" | ||
} | ||
|
||
func (d *dataSourceApplication) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"arn": framework.ARNAttributeComputedOnly(), | ||
"description": schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
"id": schema.StringAttribute{ | ||
Required: true, | ||
}, | ||
"name": schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
func (d *dataSourceApplication) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
conn := d.Meta().ServiceCatalogAppRegistryClient(ctx) | ||
|
||
var data dataSourceApplicationData | ||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
out, err := findApplicationByID(ctx, conn, data.ID.ValueString()) | ||
if err != nil { | ||
resp.Diagnostics.AddError( | ||
create.ProblemStandardMessage(names.ServiceCatalogAppRegistry, create.ErrActionSetting, ResNameApplication, data.ID.String(), err), | ||
err.Error(), | ||
) | ||
return | ||
} | ||
|
||
resp.Diagnostics.Append(flex.Flatten(ctx, out, &data)...) | ||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} | ||
|
||
type dataSourceApplicationData struct { | ||
ARN types.String `tfsdk:"arn"` | ||
Description types.String `tfsdk:"description"` | ||
ID types.String `tfsdk:"id"` | ||
Name types.String `tfsdk:"name"` | ||
} |
54 changes: 54 additions & 0 deletions
54
internal/service/servicecatalogappregistry/application_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,54 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package servicecatalogappregistry_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/YakDriver/regexache" | ||
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" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
func TestAccServiceCatalogAppRegistryApplicationDataSource_basic(t *testing.T) { | ||
ctx := acctest.Context(t) | ||
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
dataSourceName := "data.aws_servicecatalogappregistry_application.test" | ||
applicationResourceName := "aws_servicecatalogappregistry_application.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acctest.PreCheck(ctx, t) | ||
acctest.PreCheckPartitionHasService(t, names.ServiceCatalogAppRegistryEndpointID) | ||
}, | ||
ErrorCheck: acctest.ErrorCheck(t, names.ServiceCatalogAppRegistryServiceID), | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
CheckDestroy: testAccCheckApplicationDestroy(ctx), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccApplicationDataSourceConfig_basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "id", applicationResourceName, "id"), | ||
resource.TestCheckResourceAttr(dataSourceName, "name", rName), | ||
acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn", "servicecatalog", regexache.MustCompile(`/applications/+.`)), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccApplicationDataSourceConfig_basic(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_servicecatalogappregistry_application" "test" { | ||
name = %[1]q | ||
} | ||
data "aws_servicecatalogappregistry_application" "test" { | ||
id = aws_servicecatalogappregistry_application.test.id | ||
} | ||
`, rName) | ||
} |
7 changes: 6 additions & 1 deletion
7
internal/service/servicecatalogappregistry/service_package_gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
website/docs/d/servicecatalogappregistry_application.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,35 @@ | ||
--- | ||
subcategory: "Service Catalog AppRegistry" | ||
layout: "aws" | ||
page_title: "AWS: aws_servicecatalogappregistry_application" | ||
description: |- | ||
Terraform data source for managing an AWS Service Catalog AppRegistry Application. | ||
--- | ||
|
||
# Data Source: aws_servicecatalogappregistry_application | ||
|
||
Terraform data source for managing an AWS Service Catalog AppRegistry Application. | ||
|
||
## Example Usage | ||
|
||
### Basic Usage | ||
|
||
```terraform | ||
data "aws_servicecatalogappregistry_application" "example" { | ||
id = "application-1234" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are required: | ||
|
||
* `id` - (Required) Application identifier. | ||
|
||
## Attribute Reference | ||
|
||
This data source exports the following attributes in addition to the arguments above: | ||
|
||
* `arn` - ARN (Amazon Resource Name) of the application. | ||
* `description` - Description of the application. | ||
* `name` - Name of the application. |