-
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.
Merge pull request #35280 from bonclay7/f-prometheus-scraper-config
Add data source for default scraper configuration
- Loading branch information
Showing
8 changed files
with
197 additions
and
5 deletions.
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_prometheus_default_scraper_configuration | ||
``` |
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
81 changes: 81 additions & 0 deletions
81
internal/service/amp/default_scraper_configuration_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,81 @@ | ||
// 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/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") | ||
func newDefaultScraperConfigurationDataSource(context.Context) (datasource.DataSourceWithConfigure, error) { | ||
return &defaultScraperConfigurationDataSource{}, nil | ||
} | ||
|
||
type defaultScraperConfigurationDataSource struct { | ||
framework.DataSourceWithConfigure | ||
} | ||
|
||
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 *defaultScraperConfigurationDataSource) Schema(ctx context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) { | ||
response.Schema = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
names.AttrConfiguration: schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
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 | ||
} | ||
|
||
conn := d.Meta().AMPClient(ctx) | ||
|
||
out, err := findDefaultScraperConfiguration(ctx, conn) | ||
|
||
if err != nil { | ||
response.Diagnostics.AddError("reading Prometheus Default Scraper Configuration", err.Error()) | ||
|
||
return | ||
} | ||
|
||
data.Configuration = fwflex.StringValueToFramework(ctx, string(out)) | ||
|
||
response.Diagnostics.Append(response.State.Set(ctx, &data)...) | ||
} | ||
|
||
func findDefaultScraperConfiguration(ctx context.Context, conn *amp.Client) ([]byte, error) { | ||
input := &.GetDefaultScraperConfigurationInput{} | ||
output, err := conn.GetDefaultScraperConfiguration(ctx, input) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if output == nil || output.Configuration == nil { | ||
return nil, tfresource.NewEmptyResultError(input) | ||
} | ||
|
||
return output.Configuration, err | ||
} | ||
|
||
type defaultScraperConfigurationDataSourceModel struct { | ||
Configuration types.String `tfsdk:"configuration"` | ||
} |
40 changes: 40 additions & 0 deletions
40
internal/service/amp/default_scraper_configuration_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,40 @@ | ||
// 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 TestAccAMPDefaultScraperConfigurationDataSource_basic(t *testing.T) { | ||
ctx := acctest.Context(t) | ||
dataSourceName := "data.aws_prometheus_default_scraper_configuration.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acctest.PreCheck(ctx, t) | ||
acctest.PreCheckPartitionHasService(t, names.AMPEndpointID) | ||
}, | ||
ErrorCheck: acctest.ErrorCheck(t, names.AMPServiceID), | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDefaultScraperConfigurationDataSourceConfig_basic(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, names.AttrConfiguration), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDefaultScraperConfigurationDataSourceConfig_basic() string { | ||
return ` | ||
data "aws_prometheus_default_scraper_configuration" "test" {} | ||
` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
24 changes: 24 additions & 0 deletions
24
website/docs/d/prometheus_default_scraper_configuration.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,24 @@ | ||
--- | ||
subcategory: "AMP (Managed Prometheus)" | ||
layout: "aws" | ||
page_title: "AWS: aws_prometheus_default_scraper_configuration" | ||
description: |- | ||
Returns the default scraper configuration used when Amazon EKS creates a scraper for you. | ||
--- | ||
|
||
|
||
# Data Source: aws_prometheus_default_scraper_configuration | ||
|
||
Returns the default scraper configuration used when Amazon EKS creates a scraper for you. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "aws_prometheus_default_scraper_configuration" "example" {} | ||
``` | ||
|
||
## Attribute Reference | ||
|
||
This data source exports the following attributes in addition to the arguments above: | ||
|
||
* `configuration` - The configuration file. |
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