From 0d21b49a8eca529d0b07c36763a62b55d05a38a7 Mon Sep 17 00:00:00 2001 From: nrnrk Date: Thu, 8 Feb 2024 09:46:31 +0900 Subject: [PATCH 1/4] add bedrock-agent service client without implementation --- .github/labeler-issue-triage.yml | 2 ++ .github/labeler-pr-triage.yml | 3 +++ infrastructure/repository/labels-service.tf | 1 + names/data/names_data.csv | 1 + 4 files changed, 7 insertions(+) diff --git a/.github/labeler-issue-triage.yml b/.github/labeler-issue-triage.yml index b8581767a1f..91bd73cedf2 100644 --- a/.github/labeler-issue-triage.yml +++ b/.github/labeler-issue-triage.yml @@ -91,6 +91,8 @@ service/batch: - '((\*|-)\s*`?|(data|resource)\s+"?)aws_batch_' service/bedrock: - '((\*|-)\s*`?|(data|resource)\s+"?)aws_bedrock_' +service/bedrockagent: + - '((\*|-)\s*`?|(data|resource)\s+"?)aws_bedrockagent_' service/billingconductor: - '((\*|-)\s*`?|(data|resource)\s+"?)aws_billingconductor_' service/braket: diff --git a/.github/labeler-pr-triage.yml b/.github/labeler-pr-triage.yml index 5833a2193f7..a1e613f8398 100644 --- a/.github/labeler-pr-triage.yml +++ b/.github/labeler-pr-triage.yml @@ -161,6 +161,9 @@ service/batch: service/bedrock: - 'internal/service/bedrock/**/*' - 'website/**/bedrock_*' +service/bedrockagent: + - 'internal/service/bedrockagent/**/*' + - 'website/**/bedrock_agent_*' service/billingconductor: - 'internal/service/billingconductor/**/*' - 'website/**/billingconductor_*' diff --git a/infrastructure/repository/labels-service.tf b/infrastructure/repository/labels-service.tf index 237aab10086..7d266e06ce5 100644 --- a/infrastructure/repository/labels-service.tf +++ b/infrastructure/repository/labels-service.tf @@ -33,6 +33,7 @@ variable "service_labels" { "backupgateway", "batch", "bedrock", + "bedrockagent", "billingconductor", "braket", "budgets", diff --git a/names/data/names_data.csv b/names/data/names_data.csv index d5145f5fc52..aa3cb730c24 100644 --- a/names/data/names_data.csv +++ b/names/data/names_data.csv @@ -36,6 +36,7 @@ backup,backup,backup,backup,,backup,,,Backup,Backup,,1,,,aws_backup_,,backup_,Ba backup-gateway,backupgateway,backupgateway,backupgateway,,backupgateway,,,BackupGateway,BackupGateway,,1,,,aws_backupgateway_,,backupgateway_,Backup Gateway,AWS,,x,,,,,Backup Gateway,,, batch,batch,batch,batch,,batch,,,Batch,Batch,,1,,,aws_batch_,,batch_,Batch,AWS,,,,,,,Batch,ListJobs,, bedrock,bedrock,bedrock,bedrock,,bedrock,,,Bedrock,Bedrock,,,2,,aws_bedrock_,,bedrock_,Amazon Bedrock,Amazon,,,,,,,Bedrock,ListFoundationModels,, +bedrock-agent,bedrockagent,bedrockagent,bedrockagent,,bedrockagent,,,BedrockAgent,BedrockAgent,,,2,,aws_bedrockagent_,,bedrock_agent_,Agents for Amazon Bedrock,Amazon,,x,,,,,Bedrock Agent,,, billingconductor,billingconductor,billingconductor,,,billingconductor,,,BillingConductor,BillingConductor,,1,,,aws_billingconductor_,,billingconductor_,Billing Conductor,AWS,,x,,,,,billingconductor,,, braket,braket,braket,braket,,braket,,,Braket,Braket,,1,,,aws_braket_,,braket_,Braket,Amazon,,x,,,,,Braket,,, ce,ce,costexplorer,costexplorer,,ce,,costexplorer,CE,CostExplorer,,1,,,aws_ce_,,ce_,CE (Cost Explorer),AWS,,,,,,,Cost Explorer,ListCostCategoryDefinitions,, From cb48eea5c30add343e8b9bac1fed9a66102003ec Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 8 Feb 2024 08:18:28 -0500 Subject: [PATCH 2/4] Service client for bedrockagent and run 'make gen'. --- .ci/.semgrep-service-name0.yml | 91 ++-- .ci/.semgrep-service-name1.yml | 62 +-- .ci/.semgrep-service-name2.yml | 44 +- .ci/.semgrep-service-name3.yml | 14 + .../components/generated/services_all.kt | 1 + internal/conns/awsclient_gen.go | 5 + .../service_endpoints_gen_test.go | 496 ++++++++++++++++++ names/consts_gen.go | 1 + names/data/names_data.csv | 2 +- website/allowed-subcategories.txt | 1 + .../custom-service-endpoints.html.markdown | 1 + 11 files changed, 641 insertions(+), 77 deletions(-) create mode 100644 internal/service/bedrockagent/service_endpoints_gen_test.go diff --git a/.ci/.semgrep-service-name0.yml b/.ci/.semgrep-service-name0.yml index 847bae44dbb..c7fd16721c1 100644 --- a/.ci/.semgrep-service-name0.yml +++ b/.ci/.semgrep-service-name0.yml @@ -1695,6 +1695,65 @@ rules: patterns: - pattern-regex: "(?i)Bedrock" severity: WARNING + - id: bedrockagent-in-func-name + languages: + - go + message: Do not use "BedrockAgent" in func name inside bedrockagent package + paths: + include: + - internal/service/bedrockagent + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)BedrockAgent" + - pattern-not-regex: ^TestAcc.* + - focus-metavariable: $NAME + severity: WARNING + - id: bedrockagent-in-test-name + languages: + - go + message: Include "BedrockAgent" in test name + paths: + include: + - internal/service/bedrockagent/*_test.go + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-not-regex: "^TestAccBedrockAgent" + - pattern-regex: ^TestAcc.* + severity: WARNING + - id: bedrockagent-in-const-name + languages: + - go + message: Do not use "BedrockAgent" in const name inside bedrockagent package + paths: + include: + - internal/service/bedrockagent + patterns: + - pattern: const $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)BedrockAgent" + severity: WARNING + - id: bedrockagent-in-var-name + languages: + - go + message: Do not use "BedrockAgent" in var name inside bedrockagent package + paths: + include: + - internal/service/bedrockagent + patterns: + - pattern: var $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)BedrockAgent" + severity: WARNING - id: budgets-in-func-name languages: - go @@ -3794,35 +3853,3 @@ rules: patterns: - pattern-regex: "(?i)ConfigService" severity: WARNING - - id: connect-in-func-name - languages: - - go - message: Do not use "Connect" in func name inside connect package - paths: - include: - - internal/service/connect - patterns: - - pattern: func $NAME( ... ) { ... } - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)Connect" - - pattern-not-regex: .*uickConnect.* - - pattern-not-regex: ^TestAcc.* - - focus-metavariable: $NAME - severity: WARNING - - id: connect-in-test-name - languages: - - go - message: Include "Connect" in test name - paths: - include: - - internal/service/connect/*_test.go - patterns: - - pattern: func $NAME( ... ) { ... } - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-not-regex: "^TestAccConnect" - - pattern-regex: ^TestAcc.* - severity: WARNING diff --git a/.ci/.semgrep-service-name1.yml b/.ci/.semgrep-service-name1.yml index 293dd3b04f7..019ca1e1002 100644 --- a/.ci/.semgrep-service-name1.yml +++ b/.ci/.semgrep-service-name1.yml @@ -1,5 +1,37 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: + - id: connect-in-func-name + languages: + - go + message: Do not use "Connect" in func name inside connect package + paths: + include: + - internal/service/connect + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)Connect" + - pattern-not-regex: .*uickConnect.* + - pattern-not-regex: ^TestAcc.* + - focus-metavariable: $NAME + severity: WARNING + - id: connect-in-test-name + languages: + - go + message: Include "Connect" in test name + paths: + include: + - internal/service/connect/*_test.go + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-not-regex: "^TestAccConnect" + - pattern-regex: ^TestAcc.* + severity: WARNING - id: connect-in-const-name languages: - go @@ -3806,33 +3838,3 @@ rules: patterns: - pattern-regex: "(?i)IoTAnalytics" severity: WARNING - - id: iotanalytics-in-var-name - languages: - - go - message: Do not use "IoTAnalytics" in var name inside iotanalytics package - paths: - include: - - internal/service/iotanalytics - patterns: - - pattern: var $NAME = ... - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)IoTAnalytics" - severity: WARNING - - id: iotevents-in-func-name - languages: - - go - message: Do not use "IoTEvents" in func name inside iotevents package - paths: - include: - - internal/service/iotevents - patterns: - - pattern: func $NAME( ... ) { ... } - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)IoTEvents" - - pattern-not-regex: ^TestAcc.* - - focus-metavariable: $NAME - severity: WARNING diff --git a/.ci/.semgrep-service-name2.yml b/.ci/.semgrep-service-name2.yml index 3f4d4012807..61f8b9ba68d 100644 --- a/.ci/.semgrep-service-name2.yml +++ b/.ci/.semgrep-service-name2.yml @@ -1,5 +1,35 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: + - id: iotanalytics-in-var-name + languages: + - go + message: Do not use "IoTAnalytics" in var name inside iotanalytics package + paths: + include: + - internal/service/iotanalytics + patterns: + - pattern: var $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)IoTAnalytics" + severity: WARNING + - id: iotevents-in-func-name + languages: + - go + message: Do not use "IoTEvents" in func name inside iotevents package + paths: + include: + - internal/service/iotevents + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)IoTEvents" + - pattern-not-regex: ^TestAcc.* + - focus-metavariable: $NAME + severity: WARNING - id: iotevents-in-test-name languages: - go @@ -3809,17 +3839,3 @@ rules: - pattern-not-regex: "^TestAccRedshift" - pattern-regex: ^TestAcc.* severity: WARNING - - id: redshift-in-const-name - languages: - - go - message: Do not use "Redshift" in const name inside redshift package - paths: - include: - - internal/service/redshift - patterns: - - pattern: const $NAME = ... - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)Redshift" - severity: WARNING diff --git a/.ci/.semgrep-service-name3.yml b/.ci/.semgrep-service-name3.yml index 8b5953cdac9..1a3760ee451 100644 --- a/.ci/.semgrep-service-name3.yml +++ b/.ci/.semgrep-service-name3.yml @@ -1,5 +1,19 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: + - id: redshift-in-const-name + languages: + - go + message: Do not use "Redshift" in const name inside redshift package + paths: + include: + - internal/service/redshift + patterns: + - pattern: const $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)Redshift" + severity: WARNING - id: redshift-in-var-name languages: - go diff --git a/.teamcity/components/generated/services_all.kt b/.teamcity/components/generated/services_all.kt index 161781a9b01..ad2adacf43b 100644 --- a/.teamcity/components/generated/services_all.kt +++ b/.teamcity/components/generated/services_all.kt @@ -26,6 +26,7 @@ val services = mapOf( "backup" to ServiceSpec("Backup"), "batch" to ServiceSpec("Batch", vpcLock = true), "bedrock" to ServiceSpec("Amazon Bedrock"), + "bedrockagent" to ServiceSpec("Agents for Amazon Bedrock"), "budgets" to ServiceSpec("Web Services Budgets"), "ce" to ServiceSpec("CE (Cost Explorer)"), "chime" to ServiceSpec("Chime"), diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 93d3ae50131..7fdd9a9fd15 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -15,6 +15,7 @@ import ( athena_sdkv2 "github.com/aws/aws-sdk-go-v2/service/athena" auditmanager_sdkv2 "github.com/aws/aws-sdk-go-v2/service/auditmanager" bedrock_sdkv2 "github.com/aws/aws-sdk-go-v2/service/bedrock" + bedrockagent_sdkv2 "github.com/aws/aws-sdk-go-v2/service/bedrockagent" budgets_sdkv2 "github.com/aws/aws-sdk-go-v2/service/budgets" chimesdkmediapipelines_sdkv2 "github.com/aws/aws-sdk-go-v2/service/chimesdkmediapipelines" chimesdkvoice_sdkv2 "github.com/aws/aws-sdk-go-v2/service/chimesdkvoice" @@ -348,6 +349,10 @@ func (c *AWSClient) BedrockClient(ctx context.Context) *bedrock_sdkv2.Client { return errs.Must(client[*bedrock_sdkv2.Client](ctx, c, names.Bedrock, make(map[string]any))) } +func (c *AWSClient) BedrockAgentClient(ctx context.Context) *bedrockagent_sdkv2.Client { + return errs.Must(client[*bedrockagent_sdkv2.Client](ctx, c, names.BedrockAgent, make(map[string]any))) +} + func (c *AWSClient) BudgetsClient(ctx context.Context) *budgets_sdkv2.Client { return errs.Must(client[*budgets_sdkv2.Client](ctx, c, names.Budgets, make(map[string]any))) } diff --git a/internal/service/bedrockagent/service_endpoints_gen_test.go b/internal/service/bedrockagent/service_endpoints_gen_test.go new file mode 100644 index 00000000000..b8841c481af --- /dev/null +++ b/internal/service/bedrockagent/service_endpoints_gen_test.go @@ -0,0 +1,496 @@ +// Code generated by internal/generate/serviceendpointtests/main.go; DO NOT EDIT. + +package bedrockagent_test + +import ( + "context" + "errors" + "fmt" + "os" + "path/filepath" + "reflect" + "strings" + "testing" + + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + bedrockagent_sdkv2 "github.com/aws/aws-sdk-go-v2/service/bedrockagent" + "github.com/aws/smithy-go/middleware" + smithyhttp "github.com/aws/smithy-go/transport/http" + "github.com/google/go-cmp/cmp" + "github.com/hashicorp/aws-sdk-go-base/v2/servicemocks" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + terraformsdk "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" + "github.com/hashicorp/terraform-provider-aws/internal/provider" + "golang.org/x/exp/maps" +) + +type endpointTestCase struct { + with []setupFunc + expected caseExpectations +} + +type caseSetup struct { + config map[string]any + configFile configFile + environmentVariables map[string]string +} + +type configFile struct { + baseUrl string + serviceUrl string +} + +type caseExpectations struct { + diags diag.Diagnostics + endpoint string +} + +type setupFunc func(setup *caseSetup) + +type callFunc func(ctx context.Context, t *testing.T, meta *conns.AWSClient) string + +const ( + packageNameConfigEndpoint = "https://packagename-config.endpoint.test/" + awsServiceEnvvarEndpoint = "https://service-envvar.endpoint.test/" + baseEnvvarEndpoint = "https://base-envvar.endpoint.test/" + serviceConfigFileEndpoint = "https://service-configfile.endpoint.test/" + baseConfigFileEndpoint = "https://base-configfile.endpoint.test/" +) + +const ( + packageName = "bedrockagent" + awsEnvVar = "AWS_ENDPOINT_URL_BEDROCK_AGENT" + baseEnvVar = "AWS_ENDPOINT_URL" + configParam = "bedrock_agent" +) + +func TestEndpointConfiguration(t *testing.T) { //nolint:paralleltest // uses t.Setenv + const region = "us-west-2" //lintignore:AWSAT003 + + testcases := map[string]endpointTestCase{ + "no config": { + with: []setupFunc{withNoConfig}, + expected: expectDefaultEndpoint(region), + }, + + // Package name endpoint on Config + + "package name endpoint config": { + with: []setupFunc{ + withPackageNameEndpointInConfig, + }, + expected: expectPackageNameConfigEndpoint(), + }, + + "package name endpoint config overrides aws service envvar": { + with: []setupFunc{ + withPackageNameEndpointInConfig, + withAwsEnvVar, + }, + expected: expectPackageNameConfigEndpoint(), + }, + + "package name endpoint config overrides base envvar": { + with: []setupFunc{ + withPackageNameEndpointInConfig, + withBaseEnvVar, + }, + expected: expectPackageNameConfigEndpoint(), + }, + + "package name endpoint config overrides service config file": { + with: []setupFunc{ + withPackageNameEndpointInConfig, + withServiceEndpointInConfigFile, + }, + expected: expectPackageNameConfigEndpoint(), + }, + + "package name endpoint config overrides base config file": { + with: []setupFunc{ + withPackageNameEndpointInConfig, + withBaseEndpointInConfigFile, + }, + expected: expectPackageNameConfigEndpoint(), + }, + + // Service endpoint in AWS envvar + + "service aws envvar": { + with: []setupFunc{ + withAwsEnvVar, + }, + expected: expectAwsEnvVarEndpoint(), + }, + + "service aws envvar overrides base envvar": { + with: []setupFunc{ + withAwsEnvVar, + withBaseEnvVar, + }, + expected: expectAwsEnvVarEndpoint(), + }, + + "service aws envvar overrides service config file": { + with: []setupFunc{ + withAwsEnvVar, + withServiceEndpointInConfigFile, + }, + expected: expectAwsEnvVarEndpoint(), + }, + + "service aws envvar overrides base config file": { + with: []setupFunc{ + withAwsEnvVar, + withBaseEndpointInConfigFile, + }, + expected: expectAwsEnvVarEndpoint(), + }, + + // Base endpoint in envvar + + "base endpoint envvar": { + with: []setupFunc{ + withBaseEnvVar, + }, + expected: expectBaseEnvVarEndpoint(), + }, + + "base endpoint envvar overrides service config file": { + with: []setupFunc{ + withBaseEnvVar, + withServiceEndpointInConfigFile, + }, + expected: expectBaseEnvVarEndpoint(), + }, + + "base endpoint envvar overrides base config file": { + with: []setupFunc{ + withBaseEnvVar, + withBaseEndpointInConfigFile, + }, + expected: expectBaseEnvVarEndpoint(), + }, + + // Service endpoint in config file + + "service config file": { + with: []setupFunc{ + withServiceEndpointInConfigFile, + }, + expected: expectServiceConfigFileEndpoint(), + }, + + "service config file overrides base config file": { + with: []setupFunc{ + withServiceEndpointInConfigFile, + withBaseEndpointInConfigFile, + }, + expected: expectServiceConfigFileEndpoint(), + }, + + // Base endpoint in config file + + "base endpoint config file": { + with: []setupFunc{ + withBaseEndpointInConfigFile, + }, + expected: expectBaseConfigFileEndpoint(), + }, + } + + for name, testcase := range testcases { //nolint:paralleltest // uses t.Setenv + testcase := testcase + + t.Run(name, func(t *testing.T) { + testEndpointCase(t, region, testcase, callService) + }) + } +} + +func defaultEndpoint(region string) string { + r := bedrockagent_sdkv2.NewDefaultEndpointResolverV2() + + ep, err := r.ResolveEndpoint(context.Background(), bedrockagent_sdkv2.EndpointParameters{ + Region: aws_sdkv2.String(region), + }) + if err != nil { + return err.Error() + } + + if ep.URI.Path == "" { + ep.URI.Path = "/" + } + + return ep.URI.String() +} + +func callService(ctx context.Context, t *testing.T, meta *conns.AWSClient) string { + t.Helper() + + var endpoint string + + client := meta.BedrockAgentClient(ctx) + + _, err := client.ListAgents(ctx, &bedrockagent_sdkv2.ListAgentsInput{}, + func(opts *bedrockagent_sdkv2.Options) { + opts.APIOptions = append(opts.APIOptions, + addRetrieveEndpointURLMiddleware(t, &endpoint), + addCancelRequestMiddleware(), + ) + }, + ) + if err == nil { + t.Fatal("Expected an error, got none") + } else if !errors.Is(err, errCancelOperation) { + t.Fatalf("Unexpected error: %s", err) + } + + return endpoint +} + +func withNoConfig(_ *caseSetup) { + // no-op +} + +func withPackageNameEndpointInConfig(setup *caseSetup) { + if _, ok := setup.config["endpoints"]; !ok { + setup.config["endpoints"] = []any{ + map[string]any{}, + } + } + endpoints := setup.config["endpoints"].([]any)[0].(map[string]any) + endpoints[packageName] = packageNameConfigEndpoint +} + +func withAwsEnvVar(setup *caseSetup) { + setup.environmentVariables[awsEnvVar] = awsServiceEnvvarEndpoint +} + +func withBaseEnvVar(setup *caseSetup) { + setup.environmentVariables[baseEnvVar] = baseEnvvarEndpoint +} + +func withServiceEndpointInConfigFile(setup *caseSetup) { + setup.configFile.serviceUrl = serviceConfigFileEndpoint +} + +func withBaseEndpointInConfigFile(setup *caseSetup) { + setup.configFile.baseUrl = baseConfigFileEndpoint +} + +func expectDefaultEndpoint(region string) caseExpectations { + return caseExpectations{ + endpoint: defaultEndpoint(region), + } +} + +func expectPackageNameConfigEndpoint() caseExpectations { + return caseExpectations{ + endpoint: packageNameConfigEndpoint, + } +} + +func expectAwsEnvVarEndpoint() caseExpectations { + return caseExpectations{ + endpoint: awsServiceEnvvarEndpoint, + } +} + +func expectBaseEnvVarEndpoint() caseExpectations { + return caseExpectations{ + endpoint: baseEnvvarEndpoint, + } +} + +func expectServiceConfigFileEndpoint() caseExpectations { + return caseExpectations{ + endpoint: serviceConfigFileEndpoint, + } +} + +func expectBaseConfigFileEndpoint() caseExpectations { + return caseExpectations{ + endpoint: baseConfigFileEndpoint, + } +} + +func testEndpointCase(t *testing.T, region string, testcase endpointTestCase, callF callFunc) { + t.Helper() + + ctx := context.Background() + + setup := caseSetup{ + config: map[string]any{}, + environmentVariables: map[string]string{}, + } + + for _, f := range testcase.with { + f(&setup) + } + + config := map[string]any{ + "access_key": servicemocks.MockStaticAccessKey, + "secret_key": servicemocks.MockStaticSecretKey, + "region": region, + "skip_credentials_validation": true, + "skip_requesting_account_id": true, + } + + maps.Copy(config, setup.config) + + if setup.configFile.baseUrl != "" || setup.configFile.serviceUrl != "" { + config["profile"] = "default" + tempDir := t.TempDir() + writeSharedConfigFile(t, &config, tempDir, generateSharedConfigFile(setup.configFile)) + } + + for k, v := range setup.environmentVariables { + t.Setenv(k, v) + } + + p, err := provider.New(ctx) + if err != nil { + t.Fatal(err) + } + + expectedDiags := testcase.expected.diags + expectedDiags = append( + expectedDiags, + errs.NewWarningDiagnostic( + "AWS account ID not found for provider", + "See https://registry.terraform.io/providers/hashicorp/aws/latest/docs#skip_requesting_account_id for implications.", + ), + ) + + diags := p.Configure(ctx, terraformsdk.NewResourceConfigRaw(config)) + + if diff := cmp.Diff(diags, expectedDiags, cmp.Comparer(sdkdiag.Comparer)); diff != "" { + t.Errorf("unexpected diagnostics difference: %s", diff) + } + + if diags.HasError() { + return + } + + meta := p.Meta().(*conns.AWSClient) + + endpoint := callF(ctx, t, meta) + + if endpoint != testcase.expected.endpoint { + t.Errorf("expected endpoint %q, got %q", testcase.expected.endpoint, endpoint) + } +} + +func addRetrieveEndpointURLMiddleware(t *testing.T, endpoint *string) func(*middleware.Stack) error { + return func(stack *middleware.Stack) error { + return stack.Finalize.Add( + retrieveEndpointURLMiddleware(t, endpoint), + middleware.After, + ) + } +} + +func retrieveEndpointURLMiddleware(t *testing.T, endpoint *string) middleware.FinalizeMiddleware { + return middleware.FinalizeMiddlewareFunc( + "Test: Retrieve Endpoint", + func(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (middleware.FinalizeOutput, middleware.Metadata, error) { + t.Helper() + + request, ok := in.Request.(*smithyhttp.Request) + if !ok { + t.Fatalf("Expected *github.com/aws/smithy-go/transport/http.Request, got %s", fullTypeName(in.Request)) + } + + url := request.URL + url.RawQuery = "" + url.Path = "/" + + *endpoint = url.String() + + return next.HandleFinalize(ctx, in) + }) +} + +var errCancelOperation = fmt.Errorf("Test: Cancelling request") + +func addCancelRequestMiddleware() func(*middleware.Stack) error { + return func(stack *middleware.Stack) error { + return stack.Finalize.Add( + cancelRequestMiddleware(), + middleware.After, + ) + } +} + +// cancelRequestMiddleware creates a Smithy middleware that intercepts the request before sending and cancels it +func cancelRequestMiddleware() middleware.FinalizeMiddleware { + return middleware.FinalizeMiddlewareFunc( + "Test: Cancel Requests", + func(_ context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (middleware.FinalizeOutput, middleware.Metadata, error) { + return middleware.FinalizeOutput{}, middleware.Metadata{}, errCancelOperation + }) +} + +func fullTypeName(i interface{}) string { + return fullValueTypeName(reflect.ValueOf(i)) +} + +func fullValueTypeName(v reflect.Value) string { + if v.Kind() == reflect.Ptr { + return "*" + fullValueTypeName(reflect.Indirect(v)) + } + + requestType := v.Type() + return fmt.Sprintf("%s.%s", requestType.PkgPath(), requestType.Name()) +} + +func generateSharedConfigFile(config configFile) string { + var buf strings.Builder + + buf.WriteString(` +[default] +aws_access_key_id = DefaultSharedCredentialsAccessKey +aws_secret_access_key = DefaultSharedCredentialsSecretKey +`) + if config.baseUrl != "" { + buf.WriteString(fmt.Sprintf("endpoint_url = %s\n", config.baseUrl)) + } + + if config.serviceUrl != "" { + buf.WriteString(fmt.Sprintf(` +services = endpoint-test + +[services endpoint-test] +%[1]s = + endpoint_url = %[2]s +`, configParam, serviceConfigFileEndpoint)) + } + + return buf.String() +} + +func writeSharedConfigFile(t *testing.T, config *map[string]any, tempDir, content string) string { + t.Helper() + + file, err := os.Create(filepath.Join(tempDir, "aws-sdk-go-base-shared-configuration-file")) + if err != nil { + t.Fatalf("creating shared configuration file: %s", err) + } + + _, err = file.WriteString(content) + if err != nil { + t.Fatalf(" writing shared configuration file: %s", err) + } + + if v, ok := (*config)["shared_config_files"]; !ok { + (*config)["shared_config_files"] = []any{file.Name()} + } else { + (*config)["shared_config_files"] = append(v.([]any), file.Name()) + } + + return file.Name() +} diff --git a/names/consts_gen.go b/names/consts_gen.go index b69abddf038..7e4a9cb3455 100644 --- a/names/consts_gen.go +++ b/names/consts_gen.go @@ -27,6 +27,7 @@ const ( Backup = "backup" Batch = "batch" Bedrock = "bedrock" + BedrockAgent = "bedrockagent" Budgets = "budgets" CE = "ce" CUR = "cur" diff --git a/names/data/names_data.csv b/names/data/names_data.csv index 89e0908ebae..81dffcb5f8b 100644 --- a/names/data/names_data.csv +++ b/names/data/names_data.csv @@ -36,7 +36,7 @@ backup,backup,backup,backup,,backup,,,Backup,Backup,,1,,,aws_backup_,,backup_,Ba backup-gateway,backupgateway,backupgateway,backupgateway,,backupgateway,,,BackupGateway,BackupGateway,,1,,,aws_backupgateway_,,backupgateway_,Backup Gateway,AWS,,x,,,,,Backup Gateway,,, batch,batch,batch,batch,,batch,,,Batch,Batch,,1,,,aws_batch_,,batch_,Batch,AWS,,,,,,,Batch,ListJobs,, bedrock,bedrock,bedrock,bedrock,,bedrock,,,Bedrock,Bedrock,,,2,,aws_bedrock_,,bedrock_,Amazon Bedrock,Amazon,,,,,,,Bedrock,ListFoundationModels,, -bedrock-agent,bedrockagent,bedrockagent,bedrockagent,,bedrockagent,,,BedrockAgent,BedrockAgent,,,2,,aws_bedrockagent_,,bedrock_agent_,Agents for Amazon Bedrock,Amazon,,x,,,,,Bedrock Agent,,, +bedrock-agent,bedrockagent,bedrockagent,bedrockagent,,bedrockagent,,,BedrockAgent,BedrockAgent,,,2,,aws_bedrockagent_,,bedrock_agent_,Agents for Amazon Bedrock,Amazon,,,,,,,Bedrock Agent,ListAgents,, billingconductor,billingconductor,billingconductor,,,billingconductor,,,BillingConductor,BillingConductor,,1,,,aws_billingconductor_,,billingconductor_,Billing Conductor,AWS,,x,,,,,billingconductor,,, braket,braket,braket,braket,,braket,,,Braket,Braket,,1,,,aws_braket_,,braket_,Braket,Amazon,,x,,,,,Braket,,, ce,ce,costexplorer,costexplorer,,ce,,costexplorer,CE,CostExplorer,,1,,,aws_ce_,,ce_,CE (Cost Explorer),AWS,,,,,,,Cost Explorer,ListCostCategoryDefinitions,, diff --git a/website/allowed-subcategories.txt b/website/allowed-subcategories.txt index 22d1635cd62..75c837a9dea 100644 --- a/website/allowed-subcategories.txt +++ b/website/allowed-subcategories.txt @@ -5,6 +5,7 @@ AMP (Managed Prometheus) API Gateway API Gateway V2 Account Management +Agents for Amazon Bedrock Amazon Bedrock Amazon Q Business Amplify diff --git a/website/docs/guides/custom-service-endpoints.html.markdown b/website/docs/guides/custom-service-endpoints.html.markdown index 0537780dbdf..2fdac7eebfe 100644 --- a/website/docs/guides/custom-service-endpoints.html.markdown +++ b/website/docs/guides/custom-service-endpoints.html.markdown @@ -95,6 +95,7 @@ provider "aws" {
  • backup
  • batch
  • bedrock
  • +
  • bedrockagent
  • budgets
  • ce (or costexplorer)
  • chime
  • From 52fcac62c057e1e9272bf6db6e18f25ca1c4ac20 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 8 Feb 2024 08:19:29 -0500 Subject: [PATCH 3/4] Run 'go get github.com/aws/aws-sdk-go-v2/service/bedrockagent@v1.2.1 && go mod tidy'. --- go.mod | 1 + go.sum | 2 ++ 2 files changed, 3 insertions(+) diff --git a/go.mod b/go.mod index 792fc46e01f..b1b9c680746 100644 --- a/go.mod +++ b/go.mod @@ -21,6 +21,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/athena v1.38.0 github.com/aws/aws-sdk-go-v2/service/auditmanager v1.30.6 github.com/aws/aws-sdk-go-v2/service/bedrock v1.5.7 + github.com/aws/aws-sdk-go-v2/service/bedrockagent v1.2.1 github.com/aws/aws-sdk-go-v2/service/budgets v1.20.6 github.com/aws/aws-sdk-go-v2/service/chimesdkmediapipelines v1.13.6 github.com/aws/aws-sdk-go-v2/service/chimesdkvoice v1.12.6 diff --git a/go.sum b/go.sum index 27659437c8a..ebac835437b 100644 --- a/go.sum +++ b/go.sum @@ -62,6 +62,8 @@ github.com/aws/aws-sdk-go-v2/service/auditmanager v1.30.6 h1:ijj5S2+7r+bI0s3pehF github.com/aws/aws-sdk-go-v2/service/auditmanager v1.30.6/go.mod h1:KDt78hK+1CugyNGPMTqBQ2QXN8wuUKXQo4xkDIhHFuk= github.com/aws/aws-sdk-go-v2/service/bedrock v1.5.7 h1:+RTl9HK/67LvGKjZXRu0xyg5Nwu8IbkYTHw08EgXoKs= github.com/aws/aws-sdk-go-v2/service/bedrock v1.5.7/go.mod h1:2y2Q98FDPLPUJENXDZXdwSnZUw/BjD6hLFLqkQVOY3w= +github.com/aws/aws-sdk-go-v2/service/bedrockagent v1.2.1 h1:c2/ok3uI0pAdEuGiF+sTLtLUcXJd7UT2fiHK6bxiN+A= +github.com/aws/aws-sdk-go-v2/service/bedrockagent v1.2.1/go.mod h1:agHzm9hfZcZCtaTk1UgOm75sovPhGaPTqe7sx9rGrvM= github.com/aws/aws-sdk-go-v2/service/budgets v1.20.6 h1:LDheX75WZet+IgGOAH02t7NyfWDPLTOgno00+vooUsQ= github.com/aws/aws-sdk-go-v2/service/budgets v1.20.6/go.mod h1:vT8UCkdjXUE3pRxo+ppTQ2YY+Not3W2Da6o+1zfTJZo= github.com/aws/aws-sdk-go-v2/service/chimesdkmediapipelines v1.13.6 h1:ru4KcMBXd+TxtQSpMdZMgEmD4UKFQJVDAr9UBmGQAmk= From 60539cf3e052a7bf4899a405d8cdc18038c6dd45 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 8 Feb 2024 10:43:28 -0500 Subject: [PATCH 4/4] Add 'bedrockagent/generate.go'. --- internal/provider/service_packages_gen.go | 2 + internal/service/bedrockagent/generate.go | 7 +++ .../bedrockagent/service_package_gen.go | 50 +++++++++++++++++++ internal/sweep/service_packages_gen_test.go | 2 + 4 files changed, 61 insertions(+) create mode 100644 internal/service/bedrockagent/generate.go create mode 100644 internal/service/bedrockagent/service_package_gen.go diff --git a/internal/provider/service_packages_gen.go b/internal/provider/service_packages_gen.go index 688f3aaf039..4776e76378d 100644 --- a/internal/provider/service_packages_gen.go +++ b/internal/provider/service_packages_gen.go @@ -31,6 +31,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/service/backup" "github.com/hashicorp/terraform-provider-aws/internal/service/batch" "github.com/hashicorp/terraform-provider-aws/internal/service/bedrock" + "github.com/hashicorp/terraform-provider-aws/internal/service/bedrockagent" "github.com/hashicorp/terraform-provider-aws/internal/service/budgets" "github.com/hashicorp/terraform-provider-aws/internal/service/ce" "github.com/hashicorp/terraform-provider-aws/internal/service/chime" @@ -260,6 +261,7 @@ func servicePackages(ctx context.Context) []conns.ServicePackage { backup.ServicePackage(ctx), batch.ServicePackage(ctx), bedrock.ServicePackage(ctx), + bedrockagent.ServicePackage(ctx), budgets.ServicePackage(ctx), ce.ServicePackage(ctx), chime.ServicePackage(ctx), diff --git a/internal/service/bedrockagent/generate.go b/internal/service/bedrockagent/generate.go new file mode 100644 index 00000000000..aafca55d673 --- /dev/null +++ b/internal/service/bedrockagent/generate.go @@ -0,0 +1,7 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +//go:generate go run ../../generate/servicepackage/main.go +// ONLY generate directives and package declaration! Do not add anything else to this file. + +package bedrockagent diff --git a/internal/service/bedrockagent/service_package_gen.go b/internal/service/bedrockagent/service_package_gen.go new file mode 100644 index 00000000000..bcf95312fba --- /dev/null +++ b/internal/service/bedrockagent/service_package_gen.go @@ -0,0 +1,50 @@ +// Code generated by internal/generate/servicepackages/main.go; DO NOT EDIT. + +package bedrockagent + +import ( + "context" + + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + bedrockagent_sdkv2 "github.com/aws/aws-sdk-go-v2/service/bedrockagent" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/types" + "github.com/hashicorp/terraform-provider-aws/names" +) + +type servicePackage struct{} + +func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.ServicePackageFrameworkDataSource { + return []*types.ServicePackageFrameworkDataSource{} +} + +func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.ServicePackageFrameworkResource { + return []*types.ServicePackageFrameworkResource{} +} + +func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePackageSDKDataSource { + return []*types.ServicePackageSDKDataSource{} +} + +func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePackageSDKResource { + return []*types.ServicePackageSDKResource{} +} + +func (p *servicePackage) ServicePackageName() string { + return names.BedrockAgent +} + +// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. +func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*bedrockagent_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) + + return bedrockagent_sdkv2.NewFromConfig(cfg, func(o *bedrockagent_sdkv2.Options) { + if endpoint := config["endpoint"].(string); endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + }), nil +} + +func ServicePackage(ctx context.Context) conns.ServicePackage { + return &servicePackage{} +} diff --git a/internal/sweep/service_packages_gen_test.go b/internal/sweep/service_packages_gen_test.go index 6ac504d6ac6..b7c9d99453a 100644 --- a/internal/sweep/service_packages_gen_test.go +++ b/internal/sweep/service_packages_gen_test.go @@ -31,6 +31,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/service/backup" "github.com/hashicorp/terraform-provider-aws/internal/service/batch" "github.com/hashicorp/terraform-provider-aws/internal/service/bedrock" + "github.com/hashicorp/terraform-provider-aws/internal/service/bedrockagent" "github.com/hashicorp/terraform-provider-aws/internal/service/budgets" "github.com/hashicorp/terraform-provider-aws/internal/service/ce" "github.com/hashicorp/terraform-provider-aws/internal/service/chime" @@ -260,6 +261,7 @@ func servicePackages(ctx context.Context) []conns.ServicePackage { backup.ServicePackage(ctx), batch.ServicePackage(ctx), bedrock.ServicePackage(ctx), + bedrockagent.ServicePackage(ctx), budgets.ServicePackage(ctx), ce.ServicePackage(ctx), chime.ServicePackage(ctx),