Skip to content

Commit 0dd651f

Browse files
committed
internal/provider: refactor provider_meta.user_agent to list of strings type
This is done to align the schema with the standard provider. ```console % make testacc PKG_NAME=internal/aws/ec2 TESTARGS='-run=TestAccAWSEC2VPC_providerMeta' TF_ACC=1 go test ./internal/aws/ec2 -v -count 1 -parallel 20 -run=TestAccAWSEC2VPC_providerMeta -timeout 180m --- PASS: TestAccAWSEC2VPC_providerMeta (31.37s) PASS ok github.com/hashicorp/terraform-provider-awscc/internal/aws/ec2 32.268s ``` ```console % make testacc PKG_NAME=internal/aws/logs TESTARGS='-run=TestAccAWSLogsLogGroup_providerMeta' TF_ACC=1 go test ./internal/aws/logs -v -count 1 -parallel 20 -run=TestAccAWSLogsLogGroup_providerMeta -timeout 180m --- PASS: TestAccAWSLogsLogGroup_providerMeta (24.17s) PASS ok github.com/hashicorp/terraform-provider-awscc/internal/aws/logs 25.032s ``` Inspecting the CloudTrail event history, we can see the `CreateResource` event contains the expected User-Agent information appended. ``` "userAgent": "APN/1.0 HashiCorp/1.0 Terraform/1.14.0-beta3 (+https://www.terraform.io) terraform-provider-awscc/dev (+https://registry.terraform.io/providers/hashicorp/awscc) aws-sdk-go-v2/1.41.0 ua/2.1 os/macos lang/go#1.24.11 md/GOOS#darwin md/GOARCH#arm64 api/cloudcontrol#1.29.8 m/n test-module/0.0.1 (test comment) second-test-module/0.0.2 (second test comment)", ``` Once the CloudControl API receives the request, the subsequent calls made to other AWS services by cloud control will _not_ include the additional User-Agent details. Instead the `userAgent` field will just display the following: ``` "userAgent": "cloudformation.amazonaws.com", ```
1 parent 3c3469a commit 0dd651f

File tree

7 files changed

+12
-59
lines changed

7 files changed

+12
-59
lines changed

docs/index.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,7 @@ terraform {
246246
247247
provider_meta "awscc" {
248248
user_agent = [
249-
{
250-
product_name = "example-demo"
251-
product_version = "0.0.1"
252-
comment = "a demo module"
253-
},
249+
"example-demo/0.0.1 (a demo module)",
254250
]
255251
}
256252
}

internal/acctest/data.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,8 @@ func WithProviderMeta() string {
110110
terraform {
111111
provider_meta "awscc" {
112112
user_agent = [
113-
{
114-
product_name = "test-module"
115-
product_version = "0.0.1"
116-
comment = "test comment"
117-
},
118-
{
119-
product_name = "second-test-module"
120-
product_version = "0.0.2"
121-
comment = "second test comment"
122-
}
113+
"test-module/0.0.1 (test comment)",
114+
"second-test-module/0.0.2 (second test comment)",
123115
]
124116
}
125117
}

internal/aws/logs/testdata/LogGroup/providerMeta/main.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
terraform {
22
provider_meta "awscc" {
33
user_agent = [
4-
{
5-
product_name = "example-demo"
6-
product_version = "0.0.1"
7-
comment = "a demo module"
8-
},
4+
"example-demo/0.0.1 (a demo module)",
95
]
106
}
117
}

internal/aws/logs/testdata/LogGroup/providerMetaWithModule/demo-module/main.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ terraform {
22
# custom provider_meta which should appear appended to user agent
33
provider_meta "awscc" {
44
user_agent = [
5-
{
6-
product_name = "example-demo"
7-
product_version = "0.0.1"
8-
comment = "a demo module"
9-
},
5+
"example-demo/0.0.1 (a demo module)",
106
]
117
}
128
}

internal/generic/resource.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ import (
2020
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
2121
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
2222
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
23-
"github.com/hashicorp/terraform-plugin-framework/types"
2423
"github.com/hashicorp/terraform-plugin-go/tftypes"
2524
"github.com/hashicorp/terraform-plugin-log/tflog"
2625
ccdiag "github.com/hashicorp/terraform-provider-awscc/internal/errs/diag"
2726
"github.com/hashicorp/terraform-provider-awscc/internal/identity"
2827
tfcloudcontrol "github.com/hashicorp/terraform-provider-awscc/internal/service/cloudcontrol"
2928
"github.com/hashicorp/terraform-provider-awscc/internal/tfresource"
30-
inttypes "github.com/hashicorp/terraform-provider-awscc/internal/types"
3129
)
3230

3331
// ResourceOptionsFunc is a type alias for a resource type functional option.
@@ -370,10 +368,6 @@ var (
370368
idAttributePath = path.Root("id")
371369
)
372370

373-
type providerMetaData struct {
374-
UserAgent types.List `tfsdk:"user_agent"`
375-
}
376-
377371
func (r *genericResource) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) {
378372
response.TypeName = r.tfTypeName
379373

@@ -940,13 +934,11 @@ func (r *genericResource) bootstrapContext(ctx context.Context) context.Context
940934
func (r *genericResource) bootstrapContextWithProviderMeta(ctx context.Context, providerMeta tfsdk.Config, d *diag.Diagnostics) context.Context {
941935
ctx = r.bootstrapContext(ctx)
942936

943-
var metadata *providerMetaData
944-
d.Append(providerMeta.Get(ctx, &metadata)...)
937+
var metadata []string
938+
d.Append(providerMeta.GetAttribute(ctx, path.Root("user_agent"), &metadata)...)
945939

946940
if metadata != nil {
947-
var uap inttypes.UserAgentProducts
948-
d.Append(metadata.UserAgent.ElementsAs(ctx, &uap, false)...)
949-
ctx = useragent.Context(ctx, uap.UserAgentProducts())
941+
ctx = useragent.Context(ctx, useragent.FromSlice(metadata))
950942
}
951943

952944
return ctx

internal/provider/provider.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -292,25 +292,10 @@ func (p *ccProvider) Schema(ctx context.Context, request provider.SchemaRequest,
292292
func (p *ccProvider) MetaSchema(ctx context.Context, req provider.MetaSchemaRequest, resp *provider.MetaSchemaResponse) {
293293
resp.Schema = metaschema.Schema{
294294
Attributes: map[string]metaschema.Attribute{
295-
"user_agent": metaschema.ListNestedAttribute{
296-
NestedObject: metaschema.NestedAttributeObject{
297-
Attributes: map[string]metaschema.Attribute{
298-
"comment": schema.StringAttribute{
299-
Description: "Comment describing any additional product details.",
300-
Optional: true,
301-
},
302-
"product_name": schema.StringAttribute{
303-
Description: "Product name.",
304-
Required: true,
305-
},
306-
"product_version": schema.StringAttribute{
307-
Description: "Product version. Optional, and should only be set when `product_name` is set.",
308-
Optional: true,
309-
},
310-
},
311-
},
312-
Description: "Product details to append to the User-Agent string sent in all AWS API calls.",
295+
"user_agent": schema.ListAttribute{
296+
ElementType: types.StringType,
313297
Optional: true,
298+
Description: "Product details to append to the User-Agent string sent in all AWS API calls.",
314299
},
315300
},
316301
}

templates/index.md.tmpl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,7 @@ terraform {
246246

247247
provider_meta "awscc" {
248248
user_agent = [
249-
{
250-
product_name = "example-demo"
251-
product_version = "0.0.1"
252-
comment = "a demo module"
253-
},
249+
"example-demo/0.0.1 (a demo module)",
254250
]
255251
}
256252
}

0 commit comments

Comments
 (0)