diff --git a/.changelog/42769.txt b/.changelog/42769.txt new file mode 100644 index 000000000000..7e882e0858d9 --- /dev/null +++ b/.changelog/42769.txt @@ -0,0 +1,3 @@ +```release-note:new-data-source +aws_wafv2_application_integration_url +``` diff --git a/internal/service/wafv2/application_integration_url_data_source.go b/internal/service/wafv2/application_integration_url_data_source.go new file mode 100644 index 000000000000..5f28ae769df5 --- /dev/null +++ b/internal/service/wafv2/application_integration_url_data_source.go @@ -0,0 +1,77 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package wafv2 + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/wafv2" + awstypes "github.com/aws/aws-sdk-go-v2/service/wafv2/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/names" +) + +// @FrameworkDataSource("aws_wafv2_application_integration_url", name="Application Integration URL") +func newDataSourceApplicationIntegrationURL(context.Context) (datasource.DataSourceWithConfigure, error) { + return &dataSourceApplicationIntegrationURL{}, nil +} + +const ( + ApplicationIntegrationURL = "Captcha API Application Integration URL Data Source" +) + +type dataSourceApplicationIntegrationURL struct { + framework.DataSourceWithConfigure +} + +func (d *dataSourceApplicationIntegrationURL) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + names.AttrURL: schema.StringAttribute{ + Computed: true, + }, + }, + } +} + +func (d *dataSourceApplicationIntegrationURL) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + conn := d.Meta().WAFV2Client(ctx) + + var data dataSourceApplicationIntegrationURLModel + + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + input := wafv2.ListAPIKeysInput{ + Scope: awstypes.ScopeRegional, + Limit: aws.Int32(1), + } + + out, err := conn.ListAPIKeys(ctx, &input) + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.WAFV2, create.ErrActionReading, ApplicationIntegrationURL, data.URL.String(), err), + err.Error(), + ) + return + } + + data.URL = types.StringValue(aws.ToString(out.ApplicationIntegrationURL)) + + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } +} + +type dataSourceApplicationIntegrationURLModel struct { + URL types.String `tfsdk:"url"` +} diff --git a/internal/service/wafv2/application_integration_url_data_source_test.go b/internal/service/wafv2/application_integration_url_data_source_test.go new file mode 100644 index 000000000000..b1b215fc741b --- /dev/null +++ b/internal/service/wafv2/application_integration_url_data_source_test.go @@ -0,0 +1,32 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package wafv2_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 TestAccWAFV2ApplicationIntegrationURLDataSource_basic(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_wafv2_application_integration_url.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckScopeRegional(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.WAFV2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckAPIKeyDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: `data "aws_wafv2_application_integration_url" "test" {}`, + Check: resource.ComposeAggregateTestCheckFunc( + acctest.CheckResourceAttrHasPrefix(dataSourceName, names.AttrURL, "https://"), + ), + }, + }, + }) +} diff --git a/internal/service/wafv2/service_package_gen.go b/internal/service/wafv2/service_package_gen.go index b67ba9dd93a7..fe24b3fb7a72 100644 --- a/internal/service/wafv2/service_package_gen.go +++ b/internal/service/wafv2/service_package_gen.go @@ -15,7 +15,13 @@ import ( type servicePackage struct{} func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.ServicePackageFrameworkDataSource { - return []*types.ServicePackageFrameworkDataSource{} + return []*types.ServicePackageFrameworkDataSource{ + { + Factory: newDataSourceApplicationIntegrationURL, + TypeName: "aws_wafv2_application_integration_url", + Name: "Application Integration URL", + }, + } } func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.ServicePackageFrameworkResource { diff --git a/website/docs/d/wafv2_application_integration_url.html.markdown b/website/docs/d/wafv2_application_integration_url.html.markdown new file mode 100644 index 000000000000..3f2e855557b4 --- /dev/null +++ b/website/docs/d/wafv2_application_integration_url.html.markdown @@ -0,0 +1,26 @@ +--- +subcategory: "WAF" +layout: "aws" +page_title: "AWS: aws_wafv2_application_integration_url" +description: |- + Retrieves WAF Captcha Application Integration URL. +--- +# Data Source: aws_wafv2_application_integration_url + +Retrieves WAF Captcha Application Integration URL. + +## Example Usage + +```terraform +data "aws_wafv2_application_integration_url" "example" {} +``` + +## Argument Reference + +This data source does not support any arguments. + +## Attribute Reference + +This data source exports the following attributes in addition to the arguments above: + +* `url` - The Application Integration URL.