From 83a83d6cd5fed538c3e99e3b0a2db28c55002e6e Mon Sep 17 00:00:00 2001 From: Rodrigue Koffi Date: Tue, 23 Jan 2024 13:22:00 -0600 Subject: [PATCH 1/4] Export scraper's role arn --- internal/service/amp/scraper.go | 6 ++++++ internal/service/amp/scraper_test.go | 1 + 2 files changed, 7 insertions(+) diff --git a/internal/service/amp/scraper.go b/internal/service/amp/scraper.go index 5224c93b6e2..435f6d7b046 100644 --- a/internal/service/amp/scraper.go +++ b/internal/service/amp/scraper.go @@ -70,6 +70,9 @@ func (r *scraperResource) Schema(ctx context.Context, req resource.SchemaRequest }, names.AttrARN: framework.ARNAttributeComputedOnly(), names.AttrID: framework.IDAttribute(), + "role_arn": schema.StringAttribute{ + Computed: true, + }, "scrape_configuration": schema.StringAttribute{ Required: true, PlanModifiers: []planmodifier.String{ @@ -274,6 +277,7 @@ func (r *scraperResource) Create(ctx context.Context, req resource.CreateRequest // Set values for unknowns after creation is complete. sourceData.EKS = fwtypes.NewListNestedObjectValueOfPtr(ctx, eksSourceData) data.Source = fwtypes.NewListNestedObjectValueOfPtr(ctx, sourceData) + data.RoleArn = flex.StringToFramework(ctx, scraper.RoleArn) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } @@ -305,6 +309,7 @@ func (r *scraperResource) Read(ctx context.Context, req resource.ReadRequest, re // We can't use AutoFlEx with the top-level resource model because the API structure uses Go interfaces. data.ARN = flex.StringToFramework(ctx, scraper.Arn) data.Alias = flex.StringToFramework(ctx, scraper.Alias) + data.RoleArn = flex.StringToFramework(ctx, scraper.RoleArn) if v, ok := scraper.Destination.(*awstypes.DestinationMemberAmpConfiguration); ok { var ampDestinationData scraperAMPDestinationModel resp.Diagnostics.Append(flex.Flatten(ctx, &v.Value, &DestinationData)...) @@ -392,6 +397,7 @@ type scraperResourceModel struct { ARN types.String `tfsdk:"arn"` Destination fwtypes.ListNestedObjectValueOf[scraperDestinationModel] `tfsdk:"destination"` ID types.String `tfsdk:"id"` + RoleArn types.String `tfsdk:"role_arn"` ScrapeConfiguration types.String `tfsdk:"scrape_configuration"` Source fwtypes.ListNestedObjectValueOf[scraperSourceModel] `tfsdk:"source"` Tags types.Map `tfsdk:"tags"` diff --git a/internal/service/amp/scraper_test.go b/internal/service/amp/scraper_test.go index 1db2fdd3309..868f8cbb6e5 100644 --- a/internal/service/amp/scraper_test.go +++ b/internal/service/amp/scraper_test.go @@ -44,6 +44,7 @@ func TestAccAMPScraper_basic(t *testing.T) { testAccCheckScraperExists(ctx, resourceName, &scraper), resource.TestCheckNoResourceAttr(resourceName, "alias"), resource.TestCheckResourceAttrSet(resourceName, "arn"), + resource.TestCheckResourceAttrSet(resourceName, "role_arn"), resource.TestCheckResourceAttr(resourceName, "destination.#", "1"), resource.TestCheckResourceAttr(resourceName, "destination.0.amp.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "scrape_configuration"), From 4cca5e030545be67b25dcdc0f824333389f42b91 Mon Sep 17 00:00:00 2001 From: Rodrigue Koffi Date: Tue, 23 Jan 2024 14:18:44 -0600 Subject: [PATCH 2/4] Add changelog --- .changelog/35453.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/35453.txt diff --git a/.changelog/35453.txt b/.changelog/35453.txt new file mode 100644 index 00000000000..eebe158cf9b --- /dev/null +++ b/.changelog/35453.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +aws_prometheus_scraper: Add `role_arn` computed argument +``` From e15b683f14d8fad48cf16614566c455dfce89b0d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 24 Jan 2024 08:13:17 -0500 Subject: [PATCH 3/4] Cosmetics. --- .changelog/35453.txt | 2 +- internal/service/amp/scraper.go | 6 +++--- internal/service/amp/scraper_test.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.changelog/35453.txt b/.changelog/35453.txt index eebe158cf9b..1c01f61ae04 100644 --- a/.changelog/35453.txt +++ b/.changelog/35453.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -aws_prometheus_scraper: Add `role_arn` computed argument +aws_prometheus_scraper: Add `role_arn` attribute ``` diff --git a/internal/service/amp/scraper.go b/internal/service/amp/scraper.go index 435f6d7b046..df5e6e57177 100644 --- a/internal/service/amp/scraper.go +++ b/internal/service/amp/scraper.go @@ -276,8 +276,8 @@ func (r *scraperResource) Create(ctx context.Context, req resource.CreateRequest // Set values for unknowns after creation is complete. sourceData.EKS = fwtypes.NewListNestedObjectValueOfPtr(ctx, eksSourceData) + data.RoleARN = flex.StringToFramework(ctx, scraper.RoleArn) data.Source = fwtypes.NewListNestedObjectValueOfPtr(ctx, sourceData) - data.RoleArn = flex.StringToFramework(ctx, scraper.RoleArn) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } @@ -309,7 +309,6 @@ func (r *scraperResource) Read(ctx context.Context, req resource.ReadRequest, re // We can't use AutoFlEx with the top-level resource model because the API structure uses Go interfaces. data.ARN = flex.StringToFramework(ctx, scraper.Arn) data.Alias = flex.StringToFramework(ctx, scraper.Alias) - data.RoleArn = flex.StringToFramework(ctx, scraper.RoleArn) if v, ok := scraper.Destination.(*awstypes.DestinationMemberAmpConfiguration); ok { var ampDestinationData scraperAMPDestinationModel resp.Diagnostics.Append(flex.Flatten(ctx, &v.Value, &DestinationData)...) @@ -321,6 +320,7 @@ func (r *scraperResource) Read(ctx context.Context, req resource.ReadRequest, re AMP: fwtypes.NewListNestedObjectValueOfPtr(ctx, &DestinationData), }) } + data.RoleARN = flex.StringToFramework(ctx, scraper.RoleArn) if v, ok := scraper.ScrapeConfiguration.(*awstypes.ScrapeConfigurationMemberConfigurationBlob); ok { data.ScrapeConfiguration = flex.StringValueToFramework(ctx, string(v.Value)) } @@ -397,7 +397,7 @@ type scraperResourceModel struct { ARN types.String `tfsdk:"arn"` Destination fwtypes.ListNestedObjectValueOf[scraperDestinationModel] `tfsdk:"destination"` ID types.String `tfsdk:"id"` - RoleArn types.String `tfsdk:"role_arn"` + RoleARN types.String `tfsdk:"role_arn"` ScrapeConfiguration types.String `tfsdk:"scrape_configuration"` Source fwtypes.ListNestedObjectValueOf[scraperSourceModel] `tfsdk:"source"` Tags types.Map `tfsdk:"tags"` diff --git a/internal/service/amp/scraper_test.go b/internal/service/amp/scraper_test.go index 868f8cbb6e5..538c61e8029 100644 --- a/internal/service/amp/scraper_test.go +++ b/internal/service/amp/scraper_test.go @@ -44,9 +44,9 @@ func TestAccAMPScraper_basic(t *testing.T) { testAccCheckScraperExists(ctx, resourceName, &scraper), resource.TestCheckNoResourceAttr(resourceName, "alias"), resource.TestCheckResourceAttrSet(resourceName, "arn"), - resource.TestCheckResourceAttrSet(resourceName, "role_arn"), resource.TestCheckResourceAttr(resourceName, "destination.#", "1"), resource.TestCheckResourceAttr(resourceName, "destination.0.amp.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "role_arn"), resource.TestCheckResourceAttrSet(resourceName, "scrape_configuration"), resource.TestCheckResourceAttr(resourceName, "source.#", "1"), resource.TestCheckResourceAttr(resourceName, "source.0.eks.#", "1"), From f298ee3c448fafeff69d3713b1bb0081d280f4fc Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 24 Jan 2024 08:56:32 -0500 Subject: [PATCH 4/4] r/aws_prometheus_scraper: Document 'role_arn'. --- website/docs/r/prometheus_scraper.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/prometheus_scraper.html.markdown b/website/docs/r/prometheus_scraper.html.markdown index 4bc32f6b15d..e154495f2c4 100644 --- a/website/docs/r/prometheus_scraper.html.markdown +++ b/website/docs/r/prometheus_scraper.html.markdown @@ -171,6 +171,7 @@ The following arguments are optional: This resource exports the following attributes in addition to the arguments above: * `arn` - The Amazon Resource Name (ARN) of the new scraper. +* `role_arn` - The Amazon Resource Name (ARN) of the IAM role that provides permissions for the scraper to discover, collect, and produce metrics * `status` - Status of the scraper. One of ACTIVE, CREATING, DELETING, CREATION_FAILED, DELETION_FAILED ## Timeouts