Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d/aws_servicecatalogappregistry_application: new data source #36596

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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.
Loading