-
Notifications
You must be signed in to change notification settings - Fork 134
Provider: Support module-scoped user-agents via provider_meta
#474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
$ make build && cp $GOPATH/bin/terraform-provider-awscc ~/.terraform.d/plugins/providermeta/hashicorp/awscc/0.0.1/darwin_amd64/
go install
# github.com/hashicorp/terraform-provider-awscc
./main.go:11:32: cannot use provider.New (type func() tfsdk.ProviderWithProviderMeta) as type func() tfsdk.Provider in argument to tfsdk.Serve
make: *** [build] Error 2 |
a8b16f4 to
78ef3c5
Compare
|
Unable to figure out how to extract the hcl provider_meta set in test I'm pretty sure the function Once the data is there, i think we have the functionality in place to unpack and add to the new ctx key for user-agent additions |
Resolved merge conflicts and refactored the method on the provider struct to satisfy the WithProviderMeta interface. Smoke tests are now passing, though validation of the behavior with `provider_meta` configured on a module is not yet complete. This commit simply brings the branch up to date with `main` so progress can continue. ```console % awscc-smoke TF_ACC=1 go test ./internal/aws/logs -v -count 1 -parallel 20 -run=TestAccAWSLogsLogGroup_\|TestAccAWSLogsLogGroupDataSource_ -timeout 180m === CONT TestAccAWSLogsLogGroup_disappears 2025-09-24T10:43:17.335-0400 [ERROR] sdk.proto: Response contains error diagnostic: tf_rpc=ReadDataSource diagnostic_detail="After attempting to read the data source, the API returned a resource not found error for the id provided. Original Error: couldn't find resource" diagnostic_severity=ERROR diagnostic_summary="AWS Data Source Not Found" tf_req_id=fdc69384-3b91-1658-1dab-ee4553603457 tf_provider_addr=registry.terraform.io/hashicorp/awscc tf_data_source_type=awscc_logs_log_group tf_proto_version=6.10 --- PASS: TestAccAWSLogsLogGroupDataSource_NonExistent (1.83s) --- PASS: TestAccAWSLogsLogGroup_basic (27.73s) --- PASS: TestAccAWSLogsLogGroupDataSource_basic (29.87s) --- PASS: TestAccAWSLogsLogGroup_disappears (34.05s) --- PASS: TestAccAWSLogsLogGroup_update (42.21s) PASS ok github.com/hashicorp/terraform-provider-awscc/internal/aws/logs 43.514s ```
The changes from this branch were merged into main in August 2022. hashicorp/aws-sdk-go-base#318
provider_meta
```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 (36.16s) PASS ok github.com/hashicorp/terraform-provider-awscc/internal/aws/ec2 37.026s ```
Includes one additional test with `provider_meta` configured in the root directory, and another configured within a module. Because terraform-plugin-framework does not currently copy module contents when using the `ConfigDirectory` field for a test case, this test is always skipped. Once support for modules is available, we can enable this test.
```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
=== RUN TestAccAWSLogsLogGroup_providerMetaWithModule
log_group_resource_test.go:90: The ConfigDirectory field does not currently support copying modules to the working directory
--- SKIP: TestAccAWSLogsLogGroup_providerMetaWithModule (0.00s)
--- PASS: TestAccAWSLogsLogGroup_providerMeta (25.31s)
PASS
ok github.com/hashicorp/terraform-provider-awscc/internal/aws/logs 26.313s
```
|
Test results from the latest batch of commits. % 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 (36.16s)
PASS
ok github.com/hashicorp/terraform-provider-awscc/internal/aws/ec2 37.026s% 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
=== RUN TestAccAWSLogsLogGroup_providerMetaWithModule
log_group_resource_test.go:90: The ConfigDirectory field does not currently support copying modules to the working directory
--- SKIP: TestAccAWSLogsLogGroup_providerMetaWithModule (0.00s)
--- PASS: TestAccAWSLogsLogGroup_providerMeta (25.31s)
PASS
ok github.com/hashicorp/terraform-provider-awscc/internal/aws/logs 26.313sI've validated the behavior using modules locally. I was unable to replicate this in an acceptance test due to limitations on what is copied to the working directory when using |
…agent
This naming convention aligns the `provider_meta` schema with the arguments nested inside the existing `user_agent` argument in the provider schema.
```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
=== RUN TestAccAWSLogsLogGroup_providerMetaWithModule
log_group_resource_test.go:90: The ConfigDirectory field does not currently support copying modules to the working directory
--- SKIP: TestAccAWSLogsLogGroup_providerMetaWithModule (0.00s)
--- PASS: TestAccAWSLogsLogGroup_providerMeta (27.26s)
PASS
ok github.com/hashicorp/terraform-provider-awscc/internal/aws/logs 28.270s
```
```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 (38.53s)
PASS
ok github.com/hashicorp/terraform-provider-awscc/internal/aws/ec2 39.509s
```
Community Note
Description
This change enables the AWSCC provider to support the
provider_metablock. Specifically, modules can use this block to append additional details to the user agent sent in all CRUD operations.For example, the configuration for a module with a
providerblock already declared in the root might look like the following:All API calls invoked during CRUD operations will have a user agent string with the custom details from
provider_metaappended at the end. This can be observed in debug level Terraform logs or in the CloudTrail event history in the AWS console.http.user_agent="APN/1.0 HashiCorp/1.0 Terraform/1.14.0-beta1 (+https://www.terraform.io) terraform-provider-awscc/dev (+https://registry.terraform.io/providers/hashicorp/awscc) aws-sdk-go-v2/1.39.0 ua/2.1 os/macos lang/go#1.24.6 md/GOOS#darwin md/GOARCH#arm64 api/cloudcontrol#1.28.4 m/n jb-demo/0.0.1 (a demo module)"Relations
Closes #473
Relates #466