Skip to content

Commit 2207d40

Browse files
Mullendrewmullen
authored andcommitted
use context instead
1 parent 1753bd2 commit 2207d40

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

internal/acctest/data.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ terraform {
4646
name = "my-test-module"
4747
version = "0.0.1"
4848
comment = "testing user-agent comment"
49-
}]
49+
},
50+
{
51+
name = "2nd-user-agent"
52+
version = "0.0.1"
53+
comment = "2nd user agent"
54+
}
55+
]
5056
}
5157
}
5258
`, role) + config

internal/generic/resource.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,12 @@ func (r *resource) Create(ctx context.Context, request tfsdk.CreateResourceReque
399399

400400
traceEntry(ctx, "Resource.Create")
401401

402-
conn := r.provider.CloudControlApiClient(ctx)
402+
providerMeta := request.ProviderMeta
403+
// userAgentProducts
404+
405+
newCtx := context.WithValue(ctx, "meta", providerMeta)
406+
407+
conn := r.provider.CloudControlApiClient(newCtx)
403408

404409
tflog.Debug(ctx, "Request.Plan.Raw", map[string]interface{}{
405410
"value": hclog.Fmt("%v", request.Plan.Raw),

internal/provider/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ type providerData struct {
304304
UserAgent []userAgentProduct `tfsdk:"user_agent"`
305305
terraformVersion string
306306
}
307+
type providerMeta struct {
308+
UserAgent []userAgentProduct `tfsdk:"user_agent"`
309+
}
307310

308311
type userAgentProduct struct {
309312
ProductName types.String `tfsdk:"product_name"`
@@ -508,6 +511,8 @@ func (p *AwsCloudControlApiProvider) RoleARN(_ context.Context) string {
508511

509512
// newCloudControlClient configures and returns a fully initialized AWS Cloud Control API client with the configured region.
510513
func newCloudControlClient(ctx context.Context, pd *providerData) (*cloudcontrol.Client, string, error) {
514+
// m, _ := ctx.Value("meta").(*tfsdk.Config) // _ was ok
515+
511516
config := awsbase.Config{
512517
AccessKey: pd.AccessKey.Value,
513518
CallerDocumentationURL: "https://registry.terraform.io/providers/hashicorp/awscc",
@@ -527,6 +532,7 @@ func newCloudControlClient(ctx context.Context, pd *providerData) (*cloudcontrol
527532
},
528533
}
529534
config.UserAgent = userAgentProducts(pd.UserAgent)
535+
// config.UserAgent = userAgentProducts(m.Schema.)
530536
if pd.MaxRetries.Null {
531537
config.MaxRetries = defaultMaxRetries
532538
} else {

0 commit comments

Comments
 (0)