Skip to content

Commit 78ef3c5

Browse files
committed
structs for useragent
1 parent 7134ce9 commit 78ef3c5

File tree

5 files changed

+86
-2
lines changed

5 files changed

+86
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ website/node_modules
2323
.idea
2424
*.iml
2525
*.test
26+
*__debug_bin
2627

2728
website/vendor
2829

internal/acctest/data.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,49 @@ 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
5359
}
5460
return config
5561
}
5662

63+
func (td *TestData) MetadataConfig() string {
64+
config := fmt.Sprintf(`
65+
resource %[1]q %[2]q {}
66+
`, td.TerraformResourceType, td.ResourceLabel)
67+
68+
config = fmt.Sprintf(`
69+
resource awscc_ec2_vpc drew {
70+
cidr_block = "10.0.0.0/16"
71+
}
72+
73+
terraform {
74+
provider_meta "awscc" {
75+
user_agent = [{
76+
product_name = "my-test-module"
77+
product_version = "0.0.1"
78+
comment = "testing user-agent comment"
79+
},
80+
{
81+
product_name = "2nd-user-agent"
82+
product_version = "0.0.1"
83+
comment = "2nd user agent"
84+
}
85+
]
86+
}
87+
}
88+
` + config)
89+
return config
90+
}
91+
5792
// DataSourceWithEmptyResourceConfig returns a Terraform configuration for the data source and its respective resource.
5893
func (td *TestData) DataSourceWithEmptyResourceConfig() string {
5994
return td.EmptyConfig() + fmt.Sprintf(`

internal/aws/ec2/vpc_resource_gen_test.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/generic/resource.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
hclog "github.com/hashicorp/go-hclog"
1414
"github.com/hashicorp/terraform-plugin-framework/diag"
1515
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
16+
"github.com/hashicorp/terraform-plugin-framework/types"
1617
"github.com/hashicorp/terraform-plugin-go/tftypes"
1718
"github.com/hashicorp/terraform-plugin-log/tflog"
1819
tfcloudcontrol "github.com/hashicorp/terraform-provider-awscc/internal/service/cloudcontrol"
@@ -394,11 +395,33 @@ var (
394395
idAttributePath = tftypes.NewAttributePath().WithAttributeName("id")
395396
)
396397

398+
type meta struct {
399+
UserAgents []userAgentProduct `tfsdk:"user_agent"`
400+
}
401+
402+
type userAgentProduct struct {
403+
ProductName types.String `tfsdk:"product_name"`
404+
ProductVersion types.String `tfsdk:"product_version"`
405+
Comment types.String `tfsdk:"comment"`
406+
}
407+
397408
func (r *resource) Create(ctx context.Context, request tfsdk.CreateResourceRequest, response *tfsdk.CreateResourceResponse) {
398409
ctx = r.cfnTypeContext(ctx)
399410

400411
traceEntry(ctx, "Resource.Create")
401412

413+
var m []meta
414+
providerMeta := request.ProviderMeta
415+
416+
diags := providerMeta.Get(ctx, &m)
417+
418+
// userAgentProducts
419+
420+
//(*(*r).resourceType).cfTypeName == "AWS::EC2::VPC"
421+
//providerMeta.Raw.value != nil
422+
// newCtx := context.WithValue(ctx, "meta", m)
423+
424+
// conn := r.provider.CloudControlApiClient(newCtx)
402425
conn := r.provider.CloudControlApiClient(ctx)
403426

404427
tflog.Debug(ctx, "Request.Plan.Raw", map[string]interface{}{
@@ -480,7 +503,7 @@ func (r *resource) Create(ctx context.Context, request tfsdk.CreateResourceReque
480503
}
481504
}
482505

483-
diags := r.populateUnknownValues(ctx, id, &response.State)
506+
diags = r.populateUnknownValues(ctx, id, &response.State)
484507

485508
if diags.HasError() {
486509
response.Diagnostics.Append(diags...)

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)