Skip to content

Commit

Permalink
d/aws_servicecatalogappregistry_application: new data source (#36596)
Browse files Browse the repository at this point in the history
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
jar-b authored Mar 27, 2024
1 parent 18d78e5 commit 12f2fa3
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/36596.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_servicecatalogappregistry_application
```
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"`
}
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)
}

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

35 changes: 35 additions & 0 deletions website/docs/d/servicecatalogappregistry_application.html.markdown
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.

0 comments on commit 12f2fa3

Please sign in to comment.