Skip to content

Commit cae81ed

Browse files
authored
Merge pull request #44991 from tabito-hara/f-aws_bedrockagentcore_gateway_target-add_mcp_server
[Enhancement] aws_bedrockagentcore_gateway_target: Add `target_configuration.mcp.mcp_server` block
2 parents f266212 + dfa244c commit cae81ed

File tree

4 files changed

+132
-2
lines changed

4 files changed

+132
-2
lines changed

.changelog/44991.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/aws_bedrockagentcore_gateway_target: Add `target_configuration.mcp.mcp_server` block
3+
```
4+
5+
```release-note:enhancement
6+
resource/aws_bedrockagentcore_gateway_target: Make `credential_provider_configuration` block optional
7+
```

internal/service/bedrockagentcore/gateway_target.go

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ func (r *gatewayTargetResource) Schema(ctx context.Context, request resource.Sch
224224
"credential_provider_configuration": schema.ListNestedBlock{
225225
CustomType: fwtypes.NewListNestedObjectTypeOf[credentialProviderConfigurationModel](ctx),
226226
Validators: []validator.List{
227-
listvalidator.IsRequired(),
228227
listvalidator.SizeAtMost(1),
229228
},
230229
NestedObject: schema.NestedBlockObject{
@@ -385,6 +384,25 @@ func (r *gatewayTargetResource) Schema(ctx context.Context, request resource.Sch
385384
},
386385
},
387386
},
387+
"mcp_server": schema.ListNestedBlock{
388+
CustomType: fwtypes.NewListNestedObjectTypeOf[mcpServerConfigurationModel](ctx),
389+
Validators: []validator.List{
390+
listvalidator.SizeAtMost(1),
391+
},
392+
NestedObject: schema.NestedBlockObject{
393+
Attributes: map[string]schema.Attribute{
394+
names.AttrEndpoint: schema.StringAttribute{
395+
Required: true,
396+
Validators: []validator.String{
397+
stringvalidator.RegexMatches(
398+
regexache.MustCompile(`https://.*`),
399+
"Must start with https://",
400+
),
401+
},
402+
},
403+
},
404+
},
405+
},
388406
"open_api_schema": schema.ListNestedBlock{
389407
CustomType: fwtypes.NewListNestedObjectTypeOf[apiSchemaConfigurationModel](ctx),
390408
Validators: []validator.List{
@@ -875,6 +893,8 @@ func (m *targetConfigurationModel) GetConfigurationType(ctx context.Context) str
875893
switch mcpData, _ := m.MCP.ToPtr(ctx); {
876894
case !mcpData.Lambda.IsNull():
877895
return "lambda"
896+
case !mcpData.MCPServer.IsNull():
897+
return "mcp_server"
878898
case !mcpData.OpenApiSchema.IsNull():
879899
return "open_api_schema"
880900
case !mcpData.SmithyModel.IsNull():
@@ -933,6 +953,7 @@ func (m targetConfigurationModel) Expand(ctx context.Context) (any, diag.Diagnos
933953

934954
type mcpConfigurationModel struct {
935955
Lambda fwtypes.ListNestedObjectValueOf[mcpLambdaConfigurationModel] `tfsdk:"lambda"`
956+
MCPServer fwtypes.ListNestedObjectValueOf[mcpServerConfigurationModel] `tfsdk:"mcp_server"`
936957
SmithyModel fwtypes.ListNestedObjectValueOf[apiSchemaConfigurationModel] `tfsdk:"smithy_model"`
937958
OpenApiSchema fwtypes.ListNestedObjectValueOf[apiSchemaConfigurationModel] `tfsdk:"open_api_schema"`
938959
}
@@ -953,6 +974,14 @@ func (m *mcpConfigurationModel) Flatten(ctx context.Context, v any) diag.Diagnos
953974
}
954975
m.Lambda = fwtypes.NewListNestedObjectValueOfPtrMust(ctx, &model)
955976

977+
case awstypes.McpTargetConfigurationMemberMcpServer:
978+
var model mcpServerConfigurationModel
979+
smerr.AddEnrich(ctx, &diags, fwflex.Flatten(ctx, t.Value, &model))
980+
if diags.HasError() {
981+
return diags
982+
}
983+
m.MCPServer = fwtypes.NewListNestedObjectValueOfPtrMust(ctx, &model)
984+
956985
case awstypes.McpTargetConfigurationMemberOpenApiSchema:
957986
var model apiSchemaConfigurationModel
958987
smerr.AddEnrich(ctx, &diags, fwflex.Flatten(ctx, t.Value, &model))
@@ -995,6 +1024,20 @@ func (m mcpConfigurationModel) Expand(ctx context.Context) (any, diag.Diagnostic
9951024
}
9961025
return &r, diags
9971026

1027+
case !m.MCPServer.IsNull():
1028+
mcpServerConfigurationData, d := m.MCPServer.ToPtr(ctx)
1029+
smerr.AddEnrich(ctx, &diags, d)
1030+
if diags.HasError() {
1031+
return nil, diags
1032+
}
1033+
1034+
var r awstypes.McpTargetConfigurationMemberMcpServer
1035+
smerr.AddEnrich(ctx, &diags, fwflex.Expand(ctx, mcpServerConfigurationData, &r.Value))
1036+
if diags.HasError() {
1037+
return nil, diags
1038+
}
1039+
return &r, diags
1040+
9981041
case !m.OpenApiSchema.IsNull():
9991042
openApiMCPConfigurationData, d := m.OpenApiSchema.ToPtr(ctx)
10001043
smerr.AddEnrich(ctx, &diags, d)
@@ -1547,6 +1590,10 @@ type s3ConfigurationModel struct {
15471590
Uri types.String `tfsdk:"uri"`
15481591
}
15491592

1593+
type mcpServerConfigurationModel struct {
1594+
Endpoint types.String `tfsdk:"endpoint"`
1595+
}
1596+
15501597
type apiSchemaConfigurationModel struct {
15511598
InlinePayload fwtypes.ListNestedObjectValueOf[inlinePayloadModel] `tfsdk:"inline_payload"`
15521599
S3 fwtypes.ListNestedObjectValueOf[s3ConfigurationModel] `tfsdk:"s3"`

internal/service/bedrockagentcore/gateway_target_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,58 @@ func TestAccBedrockAgentCoreGatewayTarget_targetConfiguration(t *testing.T) {
241241
})
242242
}
243243

244+
func TestAccBedrockAgentCoreGatewayTarget_targetConfigurationMCPServer(t *testing.T) {
245+
ctx := acctest.Context(t)
246+
var gatewayTarget bedrockagentcorecontrol.GetGatewayTargetOutput
247+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
248+
resourceName := "aws_bedrockagentcore_gateway_target.test"
249+
250+
resource.ParallelTest(t, resource.TestCase{
251+
PreCheck: func() {
252+
acctest.PreCheck(ctx, t)
253+
acctest.PreCheckPartitionHasService(t, names.BedrockEndpointID)
254+
testAccPreCheckGatewayTargets(ctx, t)
255+
},
256+
ErrorCheck: acctest.ErrorCheck(t, names.BedrockAgentCoreServiceID),
257+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
258+
CheckDestroy: testAccCheckGatewayTargetDestroy(ctx),
259+
Steps: []resource.TestStep{
260+
{
261+
Config: testAccGatewayTargetConfig_targetConfigurationMCPServer(rName, "https://knowledge-mcp.global.api.aws"),
262+
Check: resource.ComposeAggregateTestCheckFunc(
263+
testAccCheckGatewayTargetExists(ctx, resourceName, &gatewayTarget),
264+
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
265+
resource.TestCheckResourceAttr(resourceName, "target_configuration.#", "1"),
266+
resource.TestCheckResourceAttr(resourceName, "target_configuration.0.mcp.#", "1"),
267+
resource.TestCheckResourceAttr(resourceName, "target_configuration.0.mcp.0.mcp_server.#", "1"),
268+
resource.TestCheckResourceAttr(resourceName, "target_configuration.0.mcp.0.mcp_server.0.endpoint", "https://knowledge-mcp.global.api.aws"),
269+
),
270+
ConfigPlanChecks: resource.ConfigPlanChecks{
271+
PreApply: []plancheck.PlanCheck{
272+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
273+
},
274+
},
275+
},
276+
{
277+
Config: testAccGatewayTargetConfig_targetConfigurationMCPServer(rName, "https://docs.mcp.cloudflare.com/mcp"),
278+
Check: resource.ComposeAggregateTestCheckFunc(
279+
testAccCheckGatewayTargetExists(ctx, resourceName, &gatewayTarget),
280+
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
281+
resource.TestCheckResourceAttr(resourceName, "target_configuration.#", "1"),
282+
resource.TestCheckResourceAttr(resourceName, "target_configuration.0.mcp.#", "1"),
283+
resource.TestCheckResourceAttr(resourceName, "target_configuration.0.mcp.0.mcp_server.#", "1"),
284+
resource.TestCheckResourceAttr(resourceName, "target_configuration.0.mcp.0.mcp_server.0.endpoint", "https://docs.mcp.cloudflare.com/mcp"),
285+
),
286+
ConfigPlanChecks: resource.ConfigPlanChecks{
287+
PreApply: []plancheck.PlanCheck{
288+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
289+
},
290+
},
291+
},
292+
},
293+
})
294+
}
295+
244296
func TestAccBedrockAgentCoreGatewayTarget_credentialProvider(t *testing.T) {
245297
ctx := acctest.Context(t)
246298
var gatewayTarget, gatewayTargetPrev bedrockagentcorecontrol.GetGatewayTargetOutput
@@ -734,6 +786,23 @@ resource "aws_bedrockagentcore_gateway_target" "test" {
734786
`, rName, schemaContent))
735787
}
736788

789+
func testAccGatewayTargetConfig_targetConfigurationMCPServer(rName, endpoint string) string {
790+
return acctest.ConfigCompose(testAccGatewayTargetConfig_infra(rName), fmt.Sprintf(`
791+
resource "aws_bedrockagentcore_gateway_target" "test" {
792+
name = %[1]q
793+
gateway_identifier = aws_bedrockagentcore_gateway.test.gateway_id
794+
795+
target_configuration {
796+
mcp {
797+
mcp_server {
798+
endpoint = %[2]q
799+
}
800+
}
801+
}
802+
}
803+
`, rName, endpoint))
804+
}
805+
737806
func testAccSchema_primitive() string {
738807
return `
739808
type = "string"

website/docs/r/bedrockagentcore_gateway_target.html.markdown

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,11 @@ The following arguments are required:
294294

295295
* `name` - (Required) Name of the gateway target.
296296
* `gateway_identifier` - (Required) Identifier of the gateway that this target belongs to.
297-
* `credential_provider_configuration` - (Required) Configuration for authenticating requests to the target. See [`credential_provider_configuration`](#credential_provider_configuration) below.
298297
* `target_configuration` - (Required) Configuration for the target endpoint. See [`target_configuration`](#target_configuration) below.
299298

300299
The following arguments are optional:
301300

301+
* `credential_provider_configuration` - (Optional) Configuration for authenticating requests to the target. Required when using `lambda`, `open_api_schema` and `smithy_model` in `mcp` block. If using `mcp_server` in `mcp` block with no authorization, it should not be specified. See [`credential_provider_configuration`](#credential_provider_configuration) below.
302302
* `description` - (Optional) Description of the gateway target.
303303
* `region` - (Optional) AWS region where the resource will be created. If not provided, the region from the provider configuration will be used.
304304

@@ -338,6 +338,7 @@ The `target_configuration` block supports the following:
338338
The `mcp` block supports exactly one of the following:
339339

340340
* `lambda` - (Optional) Lambda function target configuration. See [`lambda`](#lambda) below.
341+
* `mcp_server` - (Optional) MCP server target configuration. See [`mcp_server`](#mcp_server) below.
341342
* `open_api_schema` - (Optional) OpenAPI schema-based target configuration. See [`api_schema_configuration`](#api_schema_configuration) below.
342343
* `smithy_model` - (Optional) Smithy model-based target configuration. See [`api_schema_configuration`](#api_schema_configuration) below.
343344

@@ -371,6 +372,12 @@ The `s3` block supports the following:
371372
* `uri` - (Optional) S3 URI where the tool schema is stored.
372373
* `bucket_owner_account_id` - (Optional) Account ID of the S3 bucket owner.
373374

375+
### `mcp_server`
376+
377+
The `mcp_server` block supports the following:
378+
379+
* `endpoint` - (Required) Endpoint for the MCP server target configuration.
380+
374381
### `api_schema_configuration`
375382

376383
The `api_schema_configuration` block supports exactly one of the following:

0 commit comments

Comments
 (0)