From 3466c87bd13bce201d5b6d67bd5250a2804c42c1 Mon Sep 17 00:00:00 2001 From: Rodrigue Koffi Date: Thu, 11 Jan 2024 21:52:22 -0500 Subject: [PATCH 01/12] Add data source for default scraper configuration --- .../amp/scraper_configuration_data_source.go | 92 +++++++++++++++++++ .../scraper_configuration_data_source_test.go | 42 +++++++++ internal/service/amp/service_package_gen.go | 7 +- ...etheus_scraper_configuration.html.markdown | 27 ++++++ .../docs/r/prometheus_scraper.html.markdown | 31 +++++++ 5 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 internal/service/amp/scraper_configuration_data_source.go create mode 100644 internal/service/amp/scraper_configuration_data_source_test.go create mode 100644 website/docs/d/prometheus_scraper_configuration.html.markdown diff --git a/internal/service/amp/scraper_configuration_data_source.go b/internal/service/amp/scraper_configuration_data_source.go new file mode 100644 index 00000000000..f0fa0c4dc60 --- /dev/null +++ b/internal/service/amp/scraper_configuration_data_source.go @@ -0,0 +1,92 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package amp + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/service/amp" + "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/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" +) + +// Function annotations are used for datasource registration to the Provider. DO NOT EDIT. +// @FrameworkDataSource(name="ScraperConfiguration") +func newDataSourceScraperConfiguration(context.Context) (datasource.DataSourceWithConfigure, error) { + return &dataSourceScraperConfiguration{}, nil +} + +const ( + DSNameScraperConfiguration = "ScraperConfiguration Data Source" +) + +type dataSourceScraperConfiguration struct { + framework.DataSourceWithConfigure +} + +func (d *dataSourceScraperConfiguration) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name + resp.TypeName = "aws_prometheus_scraper_configuration" +} + +func (d *dataSourceScraperConfiguration) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "default": schema.StringAttribute{ + Computed: true, + }, + "id": framework.IDAttribute(), + }, + } +} + +func (d *dataSourceScraperConfiguration) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + conn := d.Meta().AMPClient(ctx) + + var data dataSourceScraperConfigurationData + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + out, err := findScraperConfiguration(ctx, conn) + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.AMP, create.ErrActionReading, DSNameScraperConfiguration, "", err), + err.Error(), + ) + return + } + + data.ID = flex.StringToFramework(ctx, conn.Options().BaseEndpoint) + data.Default = flex.StringValueToFramework(ctx, string(out)) + + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func findScraperConfiguration(ctx context.Context, conn *amp.Client) ([]byte, error) { + + input := &.GetDefaultScraperConfigurationInput{} + + out, err := conn.GetDefaultScraperConfiguration(ctx, input) + if err != nil { + return nil, err + } + + if out == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + return out.Configuration, err +} + +type dataSourceScraperConfigurationData struct { + Default types.String `tfsdk:"default"` + ID types.String `tfsdk:"id"` +} diff --git a/internal/service/amp/scraper_configuration_data_source_test.go b/internal/service/amp/scraper_configuration_data_source_test.go new file mode 100644 index 00000000000..2f235d68b91 --- /dev/null +++ b/internal/service/amp/scraper_configuration_data_source_test.go @@ -0,0 +1,42 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package amp_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 TestAccAMPScraperConfigurationDataSource_basic(t *testing.T) { + ctx := acctest.Context(t) + + dataSourceName := "data.aws_prometheus_scraper_configuration.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.AMPEndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.AMPEndpointID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccScraperConfigurationDataSourceConfig_basic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(dataSourceName, "default"), + ), + }, + }, + }) +} + +func testAccScraperConfigurationDataSourceConfig_basic() string { + return ` +data "aws_prometheus_scraper_configuration" "test" {} +` +} diff --git a/internal/service/amp/service_package_gen.go b/internal/service/amp/service_package_gen.go index 83b9a4b875d..1c9926bff46 100644 --- a/internal/service/amp/service_package_gen.go +++ b/internal/service/amp/service_package_gen.go @@ -15,7 +15,12 @@ import ( type servicePackage struct{} func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.ServicePackageFrameworkDataSource { - return []*types.ServicePackageFrameworkDataSource{} + return []*types.ServicePackageFrameworkDataSource{ + { + Factory: newDataSourceScraperConfiguration, + Name: "ScraperConfiguration", + }, + } } func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.ServicePackageFrameworkResource { diff --git a/website/docs/d/prometheus_scraper_configuration.html.markdown b/website/docs/d/prometheus_scraper_configuration.html.markdown new file mode 100644 index 00000000000..faca179489d --- /dev/null +++ b/website/docs/d/prometheus_scraper_configuration.html.markdown @@ -0,0 +1,27 @@ +--- +subcategory: "AMP (Managed Prometheus)" +layout: "aws" +page_title: "AWS: aws_prometheus_scraper_configuration" +description: |- + Terraform data source for managing an AWS AMP (Managed Prometheus) Scrape Configuration. +--- + + +# Data Source: aws_prometheus_scraper_configuration + +Use this data source to get the latest default Prometheus scraper +configuration for AWS managed collectors. + +## Example Usage + +### Basic Usage + +```terraform +data "aws_prometheus_scrape_configuration" "example" {} +``` + +## Attribute Reference + +This data source exports the following attributes in addition to the arguments above: + +* `default` - default YAML Prometheus scraper configuration \ No newline at end of file diff --git a/website/docs/r/prometheus_scraper.html.markdown b/website/docs/r/prometheus_scraper.html.markdown index 4bc32f6b15d..00e3c46d215 100644 --- a/website/docs/r/prometheus_scraper.html.markdown +++ b/website/docs/r/prometheus_scraper.html.markdown @@ -94,6 +94,37 @@ EOT } ``` + +### Use default EKS scraper configuration + +You can use the data source `aws_prometheus_scraper_configuration` to use a +service managed scrape configuration. + +-> **Note:** If the configuration is updated, this will trigger a replacement +of your scraper. + +```terraform +data "aws_prometheus_scraper_configuration" "example" {} + +resource "aws_prometheus_scraper" "example" { + + destination { + amp { + workspace_arn = aws_prometheus_workspace.example.arn + } + } + + scrape_configuration = data.aws_prometheus_scraper_configuration.example.default + + source { + eks { + cluster_arn = data.aws_eks_cluster.example.arn + subnet_ids = data.aws_eks_cluster.example.vpc_config[0].subnet_ids + } + } +} +``` + ### Ignoring changes to Prometheus Workspace destination A managed scraper will add a `AMPAgentlessScraper` tag to its Prometheus workspace From 7df5fc8e29931aedb239edc0a60f72c75861b5dc Mon Sep 17 00:00:00 2001 From: Rodrigue Koffi Date: Fri, 12 Jan 2024 14:46:03 -0500 Subject: [PATCH 02/12] Fix markdown --- website/docs/d/prometheus_scraper_configuration.html.markdown | 2 +- website/docs/r/prometheus_scraper.html.markdown | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/website/docs/d/prometheus_scraper_configuration.html.markdown b/website/docs/d/prometheus_scraper_configuration.html.markdown index faca179489d..2ddff8a9764 100644 --- a/website/docs/d/prometheus_scraper_configuration.html.markdown +++ b/website/docs/d/prometheus_scraper_configuration.html.markdown @@ -24,4 +24,4 @@ data "aws_prometheus_scrape_configuration" "example" {} This data source exports the following attributes in addition to the arguments above: -* `default` - default YAML Prometheus scraper configuration \ No newline at end of file +* `default` - default YAML Prometheus scraper configuration diff --git a/website/docs/r/prometheus_scraper.html.markdown b/website/docs/r/prometheus_scraper.html.markdown index 00e3c46d215..85045aa73d0 100644 --- a/website/docs/r/prometheus_scraper.html.markdown +++ b/website/docs/r/prometheus_scraper.html.markdown @@ -94,7 +94,6 @@ EOT } ``` - ### Use default EKS scraper configuration You can use the data source `aws_prometheus_scraper_configuration` to use a From a0eb74d1285f4916a4b1f503d4705aefb1034da5 Mon Sep 17 00:00:00 2001 From: Rodrigue Koffi Date: Fri, 12 Jan 2024 15:09:14 -0500 Subject: [PATCH 03/12] Lint imports --- internal/service/amp/scraper_configuration_data_source_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/service/amp/scraper_configuration_data_source_test.go b/internal/service/amp/scraper_configuration_data_source_test.go index 2f235d68b91..6d649f44dbe 100644 --- a/internal/service/amp/scraper_configuration_data_source_test.go +++ b/internal/service/amp/scraper_configuration_data_source_test.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" - "github.com/hashicorp/terraform-provider-aws/names" ) From e983f6da8fe340d8630883ed55324c3696ae3c68 Mon Sep 17 00:00:00 2001 From: Rodrigue Koffi Date: Wed, 17 Jan 2024 17:07:41 -0500 Subject: [PATCH 04/12] Add changelog --- .changelog/35280.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/35280.txt diff --git a/.changelog/35280.txt b/.changelog/35280.txt new file mode 100644 index 00000000000..ba983b2df16 --- /dev/null +++ b/.changelog/35280.txt @@ -0,0 +1,3 @@ +```release-note:new-data-source +aws_prometheus_scraper_configuration +``` From 75d7a8c482e3f70c32b259b0b6b30fee574b8047 Mon Sep 17 00:00:00 2001 From: Rodrigue Koffi Date: Wed, 17 Jan 2024 17:40:13 -0500 Subject: [PATCH 05/12] Fix linting --- internal/service/amp/scraper_configuration_data_source.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/service/amp/scraper_configuration_data_source.go b/internal/service/amp/scraper_configuration_data_source.go index f0fa0c4dc60..6e82a3b9ddb 100644 --- a/internal/service/amp/scraper_configuration_data_source.go +++ b/internal/service/amp/scraper_configuration_data_source.go @@ -71,7 +71,6 @@ func (d *dataSourceScraperConfiguration) Read(ctx context.Context, req datasourc } func findScraperConfiguration(ctx context.Context, conn *amp.Client) ([]byte, error) { - input := &.GetDefaultScraperConfigurationInput{} out, err := conn.GetDefaultScraperConfiguration(ctx, input) From 7a4449abc8925c0b58cd0aca0558102f96331119 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 9 Oct 2024 11:46:27 -0400 Subject: [PATCH 06/12] Log provider startup as early as possible. --- internal/provider/provider.go | 3 +++ main.go | 14 ++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 3c84cda7e14..8a5fa03dd42 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "log" "os" "strings" "time" @@ -33,6 +34,8 @@ import ( // New returns a new, initialized Terraform Plugin SDK v2-style provider instance. // The provider instance is fully configured once the `ConfigureContextFunc` has been called. func New(ctx context.Context) (*schema.Provider, error) { + log.Printf("Initializing Terraform AWS Provider...") + provider := &schema.Provider{ // This schema must match exactly the Terraform Protocol v6 (Terraform Plugin Framework) provider's schema. // Notably the attributes can have no Default values. diff --git a/main.go b/main.go index b73cae18c64..92ee54dd321 100644 --- a/main.go +++ b/main.go @@ -7,15 +7,25 @@ import ( "context" "flag" "log" + "runtime/debug" "github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server" "github.com/hashicorp/terraform-provider-aws/internal/provider" + "github.com/hashicorp/terraform-provider-aws/version" ) func main() { debugFlag := flag.Bool("debug", false, "Start provider in debug mode.") flag.Parse() + logFlags := log.Flags() + logFlags = logFlags &^ (log.Ldate | log.Ltime) + log.SetFlags(logFlags) + + if buildInfo, ok := debug.ReadBuildInfo(); ok { + log.Printf("Starting %s@%s (%s)...", buildInfo.Main.Path, version.ProviderVersion, buildInfo.GoVersion) + } + serverFactory, _, err := provider.ProtoV5ProviderServerFactory(context.Background()) if err != nil { @@ -28,10 +38,6 @@ func main() { serveOpts = append(serveOpts, tf5server.WithManagedDebug()) } - logFlags := log.Flags() - logFlags = logFlags &^ (log.Ldate | log.Ltime) - log.SetFlags(logFlags) - err = tf5server.Serve( "registry.terraform.io/hashicorp/aws", serverFactory, From d056873d63acd2a88d48fe993b483305eaa43ff9 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 9 Oct 2024 14:10:20 -0400 Subject: [PATCH 07/12] d/aws_prometheus_scraper_configuration: Tidy up. --- .../amp/scraper_configuration_data_source.go | 53 ++++++++----------- .../scraper_configuration_data_source_test.go | 1 - internal/service/amp/service_package_gen.go | 4 +- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/internal/service/amp/scraper_configuration_data_source.go b/internal/service/amp/scraper_configuration_data_source.go index 6e82a3b9ddb..d5f8b6550a5 100644 --- a/internal/service/amp/scraper_configuration_data_source.go +++ b/internal/service/amp/scraper_configuration_data_source.go @@ -10,64 +10,57 @@ import ( "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" + fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) -// Function annotations are used for datasource registration to the Provider. DO NOT EDIT. -// @FrameworkDataSource(name="ScraperConfiguration") -func newDataSourceScraperConfiguration(context.Context) (datasource.DataSourceWithConfigure, error) { - return &dataSourceScraperConfiguration{}, nil +// @FrameworkDataSource(name="Default Scraper Configuration") +func newScraperConfigurationDataSource(context.Context) (datasource.DataSourceWithConfigure, error) { + return &scraperConfigurationDataSource{}, nil } -const ( - DSNameScraperConfiguration = "ScraperConfiguration Data Source" -) - -type dataSourceScraperConfiguration struct { +type scraperConfigurationDataSource struct { framework.DataSourceWithConfigure } -func (d *dataSourceScraperConfiguration) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name - resp.TypeName = "aws_prometheus_scraper_configuration" +func (*scraperConfigurationDataSource) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name + response.TypeName = "aws_prometheus_scraper_configuration" } -func (d *dataSourceScraperConfiguration) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schema.Schema{ +func (d *scraperConfigurationDataSource) Schema(ctx context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) { + response.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "default": schema.StringAttribute{ Computed: true, }, - "id": framework.IDAttribute(), + names.AttrID: framework.IDAttribute(), }, } } -func (d *dataSourceScraperConfiguration) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - conn := d.Meta().AMPClient(ctx) - - var data dataSourceScraperConfigurationData - resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) - if resp.Diagnostics.HasError() { +func (d *scraperConfigurationDataSource) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) { + var data scraperConfigurationDataSourceModel + response.Diagnostics.Append(request.Config.Get(ctx, &data)...) + if response.Diagnostics.HasError() { return } + conn := d.Meta().AMPClient(ctx) + out, err := findScraperConfiguration(ctx, conn) + if err != nil { - resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.AMP, create.ErrActionReading, DSNameScraperConfiguration, "", err), - err.Error(), - ) + response.Diagnostics.AddError("reading Prometheus Default Scraper Configuration", err.Error()) + return } - data.ID = flex.StringToFramework(ctx, conn.Options().BaseEndpoint) - data.Default = flex.StringValueToFramework(ctx, string(out)) + data.ID = fwflex.StringToFramework(ctx, conn.Options().BaseEndpoint) + data.Default = fwflex.StringValueToFramework(ctx, string(out)) - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + response.Diagnostics.Append(response.State.Set(ctx, &data)...) } func findScraperConfiguration(ctx context.Context, conn *amp.Client) ([]byte, error) { @@ -85,7 +78,7 @@ func findScraperConfiguration(ctx context.Context, conn *amp.Client) ([]byte, er return out.Configuration, err } -type dataSourceScraperConfigurationData struct { +type scraperConfigurationDataSourceModel struct { Default types.String `tfsdk:"default"` ID types.String `tfsdk:"id"` } diff --git a/internal/service/amp/scraper_configuration_data_source_test.go b/internal/service/amp/scraper_configuration_data_source_test.go index 6d649f44dbe..6959778a6d4 100644 --- a/internal/service/amp/scraper_configuration_data_source_test.go +++ b/internal/service/amp/scraper_configuration_data_source_test.go @@ -13,7 +13,6 @@ import ( func TestAccAMPScraperConfigurationDataSource_basic(t *testing.T) { ctx := acctest.Context(t) - dataSourceName := "data.aws_prometheus_scraper_configuration.test" resource.ParallelTest(t, resource.TestCase{ diff --git a/internal/service/amp/service_package_gen.go b/internal/service/amp/service_package_gen.go index cc58545f1ff..569cdb24633 100644 --- a/internal/service/amp/service_package_gen.go +++ b/internal/service/amp/service_package_gen.go @@ -17,8 +17,8 @@ type servicePackage struct{} func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.ServicePackageFrameworkDataSource { return []*types.ServicePackageFrameworkDataSource{ { - Factory: newDataSourceScraperConfiguration, - Name: "ScraperConfiguration", + Factory: newScraperConfigurationDataSource, + Name: "Default Scraper Configuration", }, } } From d4eab3403d81d5bf32a1a6337c2290199cbf95e9 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 9 Oct 2024 14:13:21 -0400 Subject: [PATCH 08/12] Acceptance test output: % make testacc TESTARGS='-run=TestAccAMPScraperConfigurationDataSource_' PKG=amp make: Verifying source code with gofmt... ==> Checking that code complies with gofmt requirements... TF_ACC=1 go1.23.2 test ./internal/service/amp/... -v -count 1 -parallel 20 -run=TestAccAMPScraperConfigurationDataSource_ -timeout 360m 2024/10/09 14:12:44 Initializing Terraform AWS Provider... === RUN TestAccAMPScraperConfigurationDataSource_basic === PAUSE TestAccAMPScraperConfigurationDataSource_basic === CONT TestAccAMPScraperConfigurationDataSource_basic --- PASS: TestAccAMPScraperConfigurationDataSource_basic (8.80s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/amp 13.916s From 2e147b01bb1a105a415fae8b50e0831825e13a27 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 9 Oct 2024 14:14:48 -0400 Subject: [PATCH 09/12] Rename files to reflect new data source name. --- ...ata_source.go => default_scraper_configuration_data_source.go} | 0 ..._test.go => default_scraper_configuration_data_source_test.go} | 0 ...own => prometheus_default_scraper_configuration.html.markdown} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename internal/service/amp/{scraper_configuration_data_source.go => default_scraper_configuration_data_source.go} (100%) rename internal/service/amp/{scraper_configuration_data_source_test.go => default_scraper_configuration_data_source_test.go} (100%) rename website/docs/d/{prometheus_scraper_configuration.html.markdown => prometheus_default_scraper_configuration.html.markdown} (100%) diff --git a/internal/service/amp/scraper_configuration_data_source.go b/internal/service/amp/default_scraper_configuration_data_source.go similarity index 100% rename from internal/service/amp/scraper_configuration_data_source.go rename to internal/service/amp/default_scraper_configuration_data_source.go diff --git a/internal/service/amp/scraper_configuration_data_source_test.go b/internal/service/amp/default_scraper_configuration_data_source_test.go similarity index 100% rename from internal/service/amp/scraper_configuration_data_source_test.go rename to internal/service/amp/default_scraper_configuration_data_source_test.go diff --git a/website/docs/d/prometheus_scraper_configuration.html.markdown b/website/docs/d/prometheus_default_scraper_configuration.html.markdown similarity index 100% rename from website/docs/d/prometheus_scraper_configuration.html.markdown rename to website/docs/d/prometheus_default_scraper_configuration.html.markdown From 0aa27bbccdfb3072557637411893dabce57fa089 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 9 Oct 2024 14:31:33 -0400 Subject: [PATCH 10/12] 'aws_prometheus_scraper_configuration' -> 'aws_prometheus_default_scraper_configuration'. --- .changelog/35280.txt | 2 +- ...fault_scraper_configuration_data_source.go | 40 +++++++++---------- ..._scraper_configuration_data_source_test.go | 12 +++--- internal/service/amp/service_package_gen.go | 2 +- ...efault_scraper_configuration.html.markdown | 15 +++---- .../docs/r/prometheus_scraper.html.markdown | 4 +- 6 files changed, 34 insertions(+), 41 deletions(-) diff --git a/.changelog/35280.txt b/.changelog/35280.txt index ba983b2df16..050670503ac 100644 --- a/.changelog/35280.txt +++ b/.changelog/35280.txt @@ -1,3 +1,3 @@ ```release-note:new-data-source -aws_prometheus_scraper_configuration +aws_prometheus_default_scraper_configuration ``` diff --git a/internal/service/amp/default_scraper_configuration_data_source.go b/internal/service/amp/default_scraper_configuration_data_source.go index d5f8b6550a5..4a1a2792743 100644 --- a/internal/service/amp/default_scraper_configuration_data_source.go +++ b/internal/service/amp/default_scraper_configuration_data_source.go @@ -13,35 +13,33 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/framework" fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" - "github.com/hashicorp/terraform-provider-aws/names" ) -// @FrameworkDataSource(name="Default Scraper Configuration") -func newScraperConfigurationDataSource(context.Context) (datasource.DataSourceWithConfigure, error) { - return &scraperConfigurationDataSource{}, nil +// @FrameworkDataSource(aws_prometheus_default_scraper_configuration, name="Default Scraper Configuration") +func newDefaultScraperConfigurationDataSource(context.Context) (datasource.DataSourceWithConfigure, error) { + return &defaultScraperConfigurationDataSource{}, nil } -type scraperConfigurationDataSource struct { +type defaultScraperConfigurationDataSource struct { framework.DataSourceWithConfigure } -func (*scraperConfigurationDataSource) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name - response.TypeName = "aws_prometheus_scraper_configuration" +func (*defaultScraperConfigurationDataSource) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name + response.TypeName = "aws_prometheus_default_scraper_configuration" } -func (d *scraperConfigurationDataSource) Schema(ctx context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) { +func (d *defaultScraperConfigurationDataSource) Schema(ctx context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) { response.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ - "default": schema.StringAttribute{ + "configuration": schema.StringAttribute{ Computed: true, }, - names.AttrID: framework.IDAttribute(), }, } } -func (d *scraperConfigurationDataSource) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) { - var data scraperConfigurationDataSourceModel +func (d *defaultScraperConfigurationDataSource) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) { + var data defaultScraperConfigurationDataSourceModel response.Diagnostics.Append(request.Config.Get(ctx, &data)...) if response.Diagnostics.HasError() { return @@ -49,7 +47,7 @@ func (d *scraperConfigurationDataSource) Read(ctx context.Context, request datas conn := d.Meta().AMPClient(ctx) - out, err := findScraperConfiguration(ctx, conn) + out, err := findDefaultScraperConfiguration(ctx, conn) if err != nil { response.Diagnostics.AddError("reading Prometheus Default Scraper Configuration", err.Error()) @@ -57,28 +55,26 @@ func (d *scraperConfigurationDataSource) Read(ctx context.Context, request datas return } - data.ID = fwflex.StringToFramework(ctx, conn.Options().BaseEndpoint) - data.Default = fwflex.StringValueToFramework(ctx, string(out)) + data.Configuration = fwflex.StringValueToFramework(ctx, string(out)) response.Diagnostics.Append(response.State.Set(ctx, &data)...) } -func findScraperConfiguration(ctx context.Context, conn *amp.Client) ([]byte, error) { +func findDefaultScraperConfiguration(ctx context.Context, conn *amp.Client) ([]byte, error) { input := &.GetDefaultScraperConfigurationInput{} + output, err := conn.GetDefaultScraperConfiguration(ctx, input) - out, err := conn.GetDefaultScraperConfiguration(ctx, input) if err != nil { return nil, err } - if out == nil { + if output == nil || output.Configuration == nil { return nil, tfresource.NewEmptyResultError(input) } - return out.Configuration, err + return output.Configuration, err } -type scraperConfigurationDataSourceModel struct { - Default types.String `tfsdk:"default"` - ID types.String `tfsdk:"id"` +type defaultScraperConfigurationDataSourceModel struct { + Configuration types.String `tfsdk:"configuration"` } diff --git a/internal/service/amp/default_scraper_configuration_data_source_test.go b/internal/service/amp/default_scraper_configuration_data_source_test.go index 6959778a6d4..85d37c2c404 100644 --- a/internal/service/amp/default_scraper_configuration_data_source_test.go +++ b/internal/service/amp/default_scraper_configuration_data_source_test.go @@ -11,9 +11,9 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -func TestAccAMPScraperConfigurationDataSource_basic(t *testing.T) { +func TestAccAMPDefaultScraperConfigurationDataSource_basic(t *testing.T) { ctx := acctest.Context(t) - dataSourceName := "data.aws_prometheus_scraper_configuration.test" + dataSourceName := "data.aws_prometheus_default_scraper_configuration.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { @@ -24,17 +24,17 @@ func TestAccAMPScraperConfigurationDataSource_basic(t *testing.T) { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccScraperConfigurationDataSourceConfig_basic(), + Config: testAccDefaultScraperConfigurationDataSourceConfig_basic(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "default"), + resource.TestCheckResourceAttrSet(dataSourceName, "configuration"), ), }, }, }) } -func testAccScraperConfigurationDataSourceConfig_basic() string { +func testAccDefaultScraperConfigurationDataSourceConfig_basic() string { return ` -data "aws_prometheus_scraper_configuration" "test" {} +data "aws_prometheus_default_scraper_configuration" "test" {} ` } diff --git a/internal/service/amp/service_package_gen.go b/internal/service/amp/service_package_gen.go index 569cdb24633..8c8000a7063 100644 --- a/internal/service/amp/service_package_gen.go +++ b/internal/service/amp/service_package_gen.go @@ -17,7 +17,7 @@ type servicePackage struct{} func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.ServicePackageFrameworkDataSource { return []*types.ServicePackageFrameworkDataSource{ { - Factory: newScraperConfigurationDataSource, + Factory: newDefaultScraperConfigurationDataSource, Name: "Default Scraper Configuration", }, } diff --git a/website/docs/d/prometheus_default_scraper_configuration.html.markdown b/website/docs/d/prometheus_default_scraper_configuration.html.markdown index 2ddff8a9764..284a9636c59 100644 --- a/website/docs/d/prometheus_default_scraper_configuration.html.markdown +++ b/website/docs/d/prometheus_default_scraper_configuration.html.markdown @@ -1,27 +1,24 @@ --- subcategory: "AMP (Managed Prometheus)" layout: "aws" -page_title: "AWS: aws_prometheus_scraper_configuration" +page_title: "AWS: aws_prometheus_default_scraper_configuration" description: |- - Terraform data source for managing an AWS AMP (Managed Prometheus) Scrape Configuration. + Returns the default scraper configuration used when Amazon EKS creates a scraper for you. --- -# Data Source: aws_prometheus_scraper_configuration +# Data Source: aws_prometheus_default_scraper_configuration -Use this data source to get the latest default Prometheus scraper -configuration for AWS managed collectors. +Returns the default scraper configuration used when Amazon EKS creates a scraper for you. ## Example Usage -### Basic Usage - ```terraform -data "aws_prometheus_scrape_configuration" "example" {} +data "aws_prometheus_default_scraper_configuration" "example" {} ``` ## Attribute Reference This data source exports the following attributes in addition to the arguments above: -* `default` - default YAML Prometheus scraper configuration +* `configuration` - The configuration file. diff --git a/website/docs/r/prometheus_scraper.html.markdown b/website/docs/r/prometheus_scraper.html.markdown index a95e9059564..0ff126df48e 100644 --- a/website/docs/r/prometheus_scraper.html.markdown +++ b/website/docs/r/prometheus_scraper.html.markdown @@ -103,7 +103,7 @@ service managed scrape configuration. of your scraper. ```terraform -data "aws_prometheus_scraper_configuration" "example" {} +data "aws_prometheus_default_scraper_configuration" "example" {} resource "aws_prometheus_scraper" "example" { @@ -113,7 +113,7 @@ resource "aws_prometheus_scraper" "example" { } } - scrape_configuration = data.aws_prometheus_scraper_configuration.example.default + scrape_configuration = data.aws_prometheus_scraper_configuration.example.configuration source { eks { From 4474ded92805be846b0b64da209a954015696bfa Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 9 Oct 2024 14:56:22 -0400 Subject: [PATCH 11/12] Run 'make fix-constants PKG=amp'. --- .../service/amp/default_scraper_configuration_data_source.go | 3 ++- .../amp/default_scraper_configuration_data_source_test.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/service/amp/default_scraper_configuration_data_source.go b/internal/service/amp/default_scraper_configuration_data_source.go index 4a1a2792743..5ceae8b5558 100644 --- a/internal/service/amp/default_scraper_configuration_data_source.go +++ b/internal/service/amp/default_scraper_configuration_data_source.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/framework" fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) // @FrameworkDataSource(aws_prometheus_default_scraper_configuration, name="Default Scraper Configuration") @@ -31,7 +32,7 @@ func (*defaultScraperConfigurationDataSource) Metadata(_ context.Context, reques func (d *defaultScraperConfigurationDataSource) Schema(ctx context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) { response.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ - "configuration": schema.StringAttribute{ + names.AttrConfiguration: schema.StringAttribute{ Computed: true, }, }, diff --git a/internal/service/amp/default_scraper_configuration_data_source_test.go b/internal/service/amp/default_scraper_configuration_data_source_test.go index 85d37c2c404..6d3aab64e71 100644 --- a/internal/service/amp/default_scraper_configuration_data_source_test.go +++ b/internal/service/amp/default_scraper_configuration_data_source_test.go @@ -26,7 +26,7 @@ func TestAccAMPDefaultScraperConfigurationDataSource_basic(t *testing.T) { { Config: testAccDefaultScraperConfigurationDataSourceConfig_basic(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "configuration"), + resource.TestCheckResourceAttrSet(dataSourceName, names.AttrConfiguration), ), }, }, From 3c9479fdd6009a945506d0fd415043844df9b2e3 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 9 Oct 2024 14:59:25 -0400 Subject: [PATCH 12/12] Fix semgrep 'ci.semgrep.migrate.error-check-service-id'. --- .../amp/default_scraper_configuration_data_source_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/amp/default_scraper_configuration_data_source_test.go b/internal/service/amp/default_scraper_configuration_data_source_test.go index 6d3aab64e71..b09dc235ceb 100644 --- a/internal/service/amp/default_scraper_configuration_data_source_test.go +++ b/internal/service/amp/default_scraper_configuration_data_source_test.go @@ -20,7 +20,7 @@ func TestAccAMPDefaultScraperConfigurationDataSource_basic(t *testing.T) { acctest.PreCheck(ctx, t) acctest.PreCheckPartitionHasService(t, names.AMPEndpointID) }, - ErrorCheck: acctest.ErrorCheck(t, names.AMPEndpointID), + ErrorCheck: acctest.ErrorCheck(t, names.AMPServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ {