-
Notifications
You must be signed in to change notification settings - Fork 9.8k
provider: add provider_meta support
#45464
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
Open
jar-b
wants to merge
14
commits into
main
Choose a base branch
from
f-provider-meta-simple
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+487
−30
Open
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
106d3d4
provider: add `provider_meta` support
jar-b 5076ec8
deps: bump `hashicorp/aws-sdk-go-base/v2`, drop local replacement
jar-b 1173735
internal/acctest: add `provider_meta` config, smoke tests
jar-b c5f304d
website/docs: markdown-lint fixes
jar-b efe02c6
Merge branch 'main' into f-provider-meta-simple
jar-b deb8ac9
chore: changelog
jar-b 27a7855
internal/function: add `user_agent` provider-defined function
jar-b 05fc8fc
Merge branch 'main' into f-provider-meta-simple
jar-b 519bb26
internal/function(test): split `user_agent` cases
jar-b df254e1
website/docs/functions: populate `user_agent` docs
jar-b 8baa4e6
chore: `make copyright-fix`
jar-b 1b2c903
chore: link to `provider_meta` docs in changelog entry
jar-b efeedf9
docs: consolidate User-Agent related sections
jar-b 6506dbc
docs: tidy up `user_agent` examples, formatting
jar-b File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| ```release-note:enhancement | ||
| provider: The `provider_meta` block is now supported. The `user_agent` argument enables module authors to include additional product information in the `User-Agent` header sent during all AWS API requests made during Create, Read, Update, and Delete operations. | ||
| ``` | ||
| ```release-note:enhancement | ||
| provider: Add `user_agent` argument | ||
| ``` | ||
| ```release-note:new-function | ||
| user_agent | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Copyright IBM Corp. 2014, 2025 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package function | ||
|
|
||
| import ( | ||
| "context" | ||
| "strings" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-framework/function" | ||
| ) | ||
|
|
||
| var _ function.Function = userAgentFunction{} | ||
|
|
||
| func NewUserAgentFunction() function.Function { | ||
| return &userAgentFunction{} | ||
| } | ||
|
|
||
| type userAgentFunction struct{} | ||
|
|
||
| func (f userAgentFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { | ||
| resp.Name = "user_agent" | ||
| } | ||
|
|
||
| func (f userAgentFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { | ||
| resp.Definition = function.Definition{ | ||
| Summary: "user_agent Function", | ||
| MarkdownDescription: "Formats a User-Agent product for use with the user_agent argument in the provider or provider_meta block.", | ||
| Parameters: []function.Parameter{ | ||
| function.StringParameter{ | ||
| Name: "product_name", | ||
| MarkdownDescription: "Product name.", | ||
| }, | ||
| function.StringParameter{ | ||
| Name: "product_version", | ||
| MarkdownDescription: "Product version.", | ||
| }, | ||
| function.StringParameter{ | ||
| Name: "comment", | ||
| MarkdownDescription: "Comment describing any additional product details.", | ||
| }, | ||
| }, | ||
| Return: function.StringReturn{}, | ||
| } | ||
| } | ||
|
|
||
| func (f userAgentFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { | ||
| var name, version, comment string | ||
|
|
||
| resp.Error = function.ConcatFuncErrors(req.Arguments.Get(ctx, &name, &version, &comment)) | ||
| if resp.Error != nil { | ||
| return | ||
| } | ||
|
|
||
| if name == "" { | ||
| resp.Error = function.ConcatFuncErrors(resp.Error, function.NewFuncError("product_name must be set")) | ||
| return | ||
| } | ||
|
|
||
| var sb strings.Builder | ||
|
|
||
| sb.WriteString(name) | ||
| if version != "" { | ||
| sb.WriteString("/" + version) | ||
| } | ||
| if comment != "" { | ||
| sb.WriteString(" (" + comment + ")") | ||
| } | ||
|
|
||
| resp.Error = function.ConcatFuncErrors(resp.Result.Set(ctx, sb.String())) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // Copyright IBM Corp. 2014, 2025 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package function_test | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/YakDriver/regexache" | ||
| "github.com/hashicorp/go-version" | ||
| "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
| "github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
| "github.com/hashicorp/terraform-provider-aws/internal/acctest" | ||
| ) | ||
|
|
||
| func TestUserAgentFunction_valid(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| resource.UnitTest(t, resource.TestCase{ | ||
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
| TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
| tfversion.SkipBelow(version.Must(version.NewVersion("1.8.0"))), | ||
| }, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: testUserAgentFunctionConfig("test-module", "0.0.1", "test comment"), | ||
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckOutput("test", "test-module/0.0.1 (test comment)"), | ||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func TestUserAgentFunction_valid_name(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| resource.UnitTest(t, resource.TestCase{ | ||
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
| TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
| tfversion.SkipBelow(version.Must(version.NewVersion("1.8.0"))), | ||
| }, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: testUserAgentFunctionConfig("test-module", "", ""), | ||
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckOutput("test", "test-module"), | ||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func TestUserAgentFunction_valid_nameVersion(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| resource.UnitTest(t, resource.TestCase{ | ||
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
| TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
| tfversion.SkipBelow(version.Must(version.NewVersion("1.8.0"))), | ||
| }, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: testUserAgentFunctionConfig("test-module", "0.0.1", ""), | ||
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckOutput("test", "test-module/0.0.1"), | ||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func TestUserAgentFunction_valid_nameComment(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| resource.UnitTest(t, resource.TestCase{ | ||
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
| TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
| tfversion.SkipBelow(version.Must(version.NewVersion("1.8.0"))), | ||
| }, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: testUserAgentFunctionConfig("test-module", "", "test comment"), | ||
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckOutput("test", "test-module (test comment)"), | ||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func TestUserAgentFunction_invalid(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| resource.UnitTest(t, resource.TestCase{ | ||
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
| TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
| tfversion.SkipBelow(version.Must(version.NewVersion("1.8.0"))), | ||
| }, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: testUserAgentFunctionConfig("", "", ""), | ||
| // The full message is broken across lines, complicating validation. | ||
| // Check just the start. | ||
| ExpectError: regexache.MustCompile("product_name must be"), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func testUserAgentFunctionConfig(name, version, comment string) string { | ||
| return fmt.Sprintf(` | ||
| output "test" { | ||
| value = provider::aws::user_agent(%[1]q, %[2]q, %[3]q) | ||
| } | ||
| `, name, version, comment) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.