Skip to content

Commit bb349c4

Browse files
Create custom domain
1 parent 738a29c commit bb349c4

File tree

9 files changed

+80
-3
lines changed

9 files changed

+80
-3
lines changed

infra/resources/_modules/mcp_server/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ No requirements.
1010
| Name | Version |
1111
|------|---------|
1212
| <a name="provider_aws"></a> [aws](#provider\_aws) | 0.1.3 |
13+
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 4.47.0 |
1314

1415
## Modules
1516

@@ -19,7 +20,10 @@ No modules.
1920

2021
| Name | Type |
2122
|------|------|
23+
| [aws_acm_certificate.api_custom_domain](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate) | resource |
2224
| [aws_apigatewayv2_api.mcp_server](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/apigatewayv2_api) | resource |
25+
| [aws_apigatewayv2_api_mapping.api_custom](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/apigatewayv2_api_mapping) | resource |
26+
| [aws_apigatewayv2_domain_name.api_custom](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/apigatewayv2_domain_name) | resource |
2327
| [aws_apigatewayv2_integration.lambda_proxy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/apigatewayv2_integration) | resource |
2428
| [aws_apigatewayv2_route.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/apigatewayv2_route) | resource |
2529
| [aws_apigatewayv2_route.mcp](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/apigatewayv2_route) | resource |
@@ -31,13 +35,16 @@ No modules.
3135
| [aws_lambda_function.server](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function) | resource |
3236
| [aws_lambda_permission.apigw_http](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |
3337
| [aws_s3_bucket.mcp_knowledge_base](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
38+
| [azurerm_dns_cname_record.acm_validation](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/dns_cname_record) | resource |
39+
| [azurerm_dns_cname_record.api_gateway_custom](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/dns_cname_record) | resource |
3440

3541
## Inputs
3642

3743
| Name | Description | Type | Default | Required |
3844
|------|-------------|------|---------|:--------:|
3945
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | The AWS account ID where the MCP server resources will be created. | `string` | n/a | yes |
4046
| <a name="input_bedrock_knowledge_base_id"></a> [bedrock\_knowledge\_base\_id](#input\_bedrock\_knowledge\_base\_id) | The Bedrock knowledge base ID to be used by the MCP server. | `string` | n/a | yes |
47+
| <a name="input_dns"></a> [dns](#input\_dns) | DNS configuration for the MCP server, including zone name, resource group name, and custom domain name. | <pre>object({<br/> zone_name = string<br/> resource_group_name = string<br/> custom_domain_name = string<br/> })</pre> | n/a | yes |
4148
| <a name="input_naming_config"></a> [naming\_config](#input\_naming\_config) | n/a | <pre>object({<br/> prefix = string<br/> environment = string<br/> region = string<br/> instance_number = number<br/> })</pre> | n/a | yes |
4249
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to assign to the resources. | `map(string)` | n/a | yes |
4350

infra/resources/_modules/mcp_server/api_gateway.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
## Custom domain for API Gateway HTTP v2
2+
resource "aws_acm_certificate" "api_custom_domain" {
3+
domain_name = var.dns.custom_domain_name
4+
validation_method = "DNS"
5+
tags = var.tags
6+
}
7+
8+
resource "aws_apigatewayv2_domain_name" "api_custom" {
9+
domain_name = var.dns.custom_domain_name
10+
domain_name_configuration {
11+
certificate_arn = aws_acm_certificate.api_custom_domain.arn
12+
endpoint_type = "REGIONAL"
13+
security_policy = "TLS_1_2"
14+
}
15+
tags = var.tags
16+
}
17+
18+
resource "aws_apigatewayv2_api_mapping" "api_custom" {
19+
api_id = aws_apigatewayv2_api.mcp_server.id
20+
domain_name = aws_apigatewayv2_domain_name.api_custom.domain_name
21+
stage = aws_apigatewayv2_stage.default.id
22+
}
123
## HTTP API Gateway v2 exposing the Lambda as a proxy
224
resource "aws_apigatewayv2_api" "mcp_server" {
325
name = provider::awsdx::resource_name(merge(var.naming_config, {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# ACM validation records (CNAME)
2+
resource "azurerm_dns_cname_record" "acm_validation" {
3+
for_each = { for dvo in tolist(aws_acm_certificate.api_custom_domain.domain_validation_options) : dvo.resource_record_name => dvo }
4+
5+
name = each.value.resource_record_name
6+
zone_name = var.dns.zone_name
7+
resource_group_name = var.dns.resource_group_name
8+
ttl = 300
9+
record = each.value.resource_record_value
10+
}
11+
12+
# API Gateway custom domain CNAME
13+
resource "azurerm_dns_cname_record" "api_gateway_custom" {
14+
name = var.dns.custom_domain_name
15+
zone_name = var.dns.zone_name
16+
resource_group_name = var.dns.resource_group_name
17+
ttl = 300
18+
record = aws_apigatewayv2_domain_name.api_custom.domain_name_configuration[0].target_domain_name
19+
}

infra/resources/_modules/mcp_server/lambda.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ resource "aws_iam_policy" "lambda_bedrock_access" {
8686
Action = [
8787
"bedrock:ListKnowledgeBases",
8888
"bedrock:GetKnowledgeBase",
89-
"bedrock:QueryKnowledgeBase"
89+
"bedrock:QueryKnowledgeBase",
90+
"bedrock:Retrieve"
9091
]
9192
Resource = "arn:aws:bedrock:${var.naming_config.region}:${var.account_id}:knowledge-base/${var.bedrock_knowledge_base_id}"
9293
}

infra/resources/_modules/mcp_server/variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ variable "bedrock_knowledge_base_id" {
1717
description = "The Bedrock knowledge base ID to be used by the MCP server."
1818
}
1919

20+
variable "dns" {
21+
type = object({
22+
zone_name = string
23+
resource_group_name = string
24+
custom_domain_name = string
25+
})
26+
description = "DNS configuration for the MCP server, including zone name, resource group name, and custom domain name."
27+
}
28+
2029
variable "tags" {
2130
type = map(string)
2231
description = "A map of tags to assign to the resources."

infra/resources/dev/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
| Name | Source | Version |
2424
|------|--------|---------|
2525
| <a name="module_aws_core_values"></a> [aws\_core\_values](#module\_aws\_core\_values) | pagopa-dx/aws-core-values-exporter/aws | ~> 0.0 |
26+
| <a name="module_azure_core_values"></a> [azure\_core\_values](#module\_azure\_core\_values) | pagopa-dx/azure-core-values-exporter/azurerm | ~> 0.0 |
2627
| <a name="module_mcp_server"></a> [mcp\_server](#module\_mcp\_server) | ../_modules/mcp_server | n/a |
2728
| <a name="module_testing"></a> [testing](#module\_testing) | ../_modules/testing | n/a |
2829

infra/resources/dev/aws.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ module "mcp_server" {
1111
aws = aws.eu-central-1
1212
}
1313

14-
naming_config = local.aws_naming_config
14+
naming_config = merge(local.aws_naming_config, { region = "eu-central-1" })
1515
account_id = data.aws_caller_identity.current.account_id
1616
bedrock_knowledge_base_id = "TWMAUIB8QZ"
17-
tags = local.tags
17+
18+
dns = {
19+
custom_domain_name = "mcp.dev.dx.pagopa.it"
20+
zone_name = "dev.dx.pagopa.it"
21+
resource_group_name = module.azure_core_values.network_resource_group_name
22+
}
23+
tags = local.tags
1824
}

infra/resources/dev/azure.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module "azure_core_values" {
2+
source = "pagopa-dx/azure-core-values-exporter/azurerm"
3+
version = "~> 0.0"
4+
5+
core_state = local.core_state
6+
}

infra/resources/dev/tfmodules.lock.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@
44
"version": "0.1.1",
55
"name": "aws_core_values_exporter",
66
"source": "https://registry.terraform.io/modules/pagopa-dx/aws-core-values-exporter/aws/0.1.1"
7+
},
8+
"azure_core_values": {
9+
"hash": "9d17c2786991abf8af52245d73bb724877914c4eb8f72389a831b5385878974e",
10+
"version": "0.2.4",
11+
"name": "azure_core_values_exporter",
12+
"source": "https://registry.terraform.io/modules/pagopa-dx/azure-core-values-exporter/azurerm/0.2.4"
713
}
814
}

0 commit comments

Comments
 (0)