diff --git a/terraform-modules/aws/route53/record-vpc-endpoint-sftp-transfer/README.md b/terraform-modules/aws/route53/record-vpc-endpoint-sftp-transfer/README.md new file mode 100644 index 000000000..796a32614 --- /dev/null +++ b/terraform-modules/aws/route53/record-vpc-endpoint-sftp-transfer/README.md @@ -0,0 +1,46 @@ +## Requirements + +No requirements. + +## Providers + +| Name | Version | +|------|---------| +| [aws](#provider\_aws) | n/a | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [record](#module\_record) | ../record/ | n/a | + +## Resources + +| Name | Type | +|------|------| +| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | +| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source | +| [aws_transfer_server.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/transfer_server) | data source | +| [aws_vpc_endpoint.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc_endpoint) | data source | +| [aws_vpc_endpoint_service.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc_endpoint_service) | data source | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [evaluate\_target\_health](#input\_evaluate\_target\_health) | whether or not Route 53 should perform health checks on the target of an alias record before responding to DNS queries. | `bool` | `false` | no | +| [record\_name](#input\_record\_name) | The name for the Route 53 record. | `string` | n/a | yes | +| [route53\_zone\_id](#input\_route53\_zone\_id) | The ID of the Route 53 zone where the record will be created. | `string` | n/a | yes | +| [transfer\_server\_id](#input\_transfer\_server\_id) | The ID of the AWS Transfer Server | `string` | `""` | no | +| [type](#input\_type) | Also known as an Address record, is used to map a domain name to an IP address. | `string` | `"A"` | no | +| [vpc\_id](#input\_vpc\_id) | The VPC ID Where VPC enpoint is configured | `string` | `""` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [fqdn](#output\_fqdn) | FQDN built using the zone domain and name. | +| [name](#output\_name) | The name for the Route 53 record. | +| [vpc\_endpoint\_dns\_entry](#output\_vpc\_endpoint\_dns\_entry) | Retrieve the DNS name associated with an AWS VPC Endpoint. | +| [vpc\_endpoint\_dns\_name](#output\_vpc\_endpoint\_dns\_name) | Retrieves the primary DNS name associated with the VPC Endpoint | +| [vpc\_endpoint\_id](#output\_vpc\_endpoint\_id) | ID of an AWS VPC Endpoint | diff --git a/terraform-modules/aws/route53/record-vpc-endpoint-sftp-transfer/main.tf b/terraform-modules/aws/route53/record-vpc-endpoint-sftp-transfer/main.tf new file mode 100644 index 000000000..10a7b2910 --- /dev/null +++ b/terraform-modules/aws/route53/record-vpc-endpoint-sftp-transfer/main.tf @@ -0,0 +1,42 @@ + +data "aws_caller_identity" "current" {} +data "aws_region" "current" {} + + +resource "null_resource" "output-vpc-endpoint-id" { + provisioner "local-exec" { + command = "aws transfer describe-server --server-id ${var.transfer_server_id} --query 'Server.EndpointDetails.VpcEndpointId' > ${data.template_file.log_name.rendered}" + } +} + +data "template_file" "log_name" { + template = "${path.module}/vpc-endpoint-id.txt" +} + +data "local_file" "get-vpc-endpoint-id-value" { + filename = "${data.template_file.log_name.rendered}" + depends_on = [null_resource.output-vpc-endpoint-id] +} + +# Get the VPC Endpoint ID for the Transfer Service +data "aws_vpc_endpoint" "this" { + # Remove quotes and new lines + id = trim(replace(replace(data.local_file.get-vpc-endpoint-id-value.content, "\"", ""),"/\"|\r\n|\r|\n/",""), "") + vpc_id = var.vpc_id + + depends_on = [ + data.local_file.get-vpc-endpoint-id-value + ] +} + +module "record" { + source = "../record/" + route53_zone_id = var.route53_zone_id + record_name = var.record_name + vpc_endpoint_dns_name = data.aws_vpc_endpoint.this.dns_entry[0].dns_name + vpc_endpoint_zone_id = data.aws_vpc_endpoint.this.dns_entry[0].hosted_zone_id + + depends_on = [ + data.aws_vpc_endpoint.this + ] +} \ No newline at end of file diff --git a/terraform-modules/aws/route53/record-vpc-endpoint-sftp-transfer/outputs.tf b/terraform-modules/aws/route53/record-vpc-endpoint-sftp-transfer/outputs.tf new file mode 100644 index 000000000..3e930a9dd --- /dev/null +++ b/terraform-modules/aws/route53/record-vpc-endpoint-sftp-transfer/outputs.tf @@ -0,0 +1,24 @@ +output "name" { + value = module.record.name + description = "The name for the Route 53 record." +} + +output "fqdn" { + value = module.record.fqdn + description = "FQDN built using the zone domain and name." +} + +output "vpc_endpoint_id" { + value = data.aws_vpc_endpoint.this.id + description = "ID of an AWS VPC Endpoint" +} + +output "vpc_endpoint_dns_name" { + value = data.aws_vpc_endpoint.this.dns_entry[0].dns_name + description = "Retrieve the DNS name associated with an AWS VPC Endpoint." +} + +output "vpc_endpoint_hosted_zone_id" { + value = data.aws_vpc_endpoint.this.dns_entry[0].hosted_zone_id + description = "Retrieves the Zona ID name associated with the VPC Endpoint" +} \ No newline at end of file diff --git a/terraform-modules/aws/route53/record-vpc-endpoint-sftp-transfer/variables.tf b/terraform-modules/aws/route53/record-vpc-endpoint-sftp-transfer/variables.tf new file mode 100644 index 000000000..554a8e5e9 --- /dev/null +++ b/terraform-modules/aws/route53/record-vpc-endpoint-sftp-transfer/variables.tf @@ -0,0 +1,34 @@ +variable "route53_zone_id" { + description = "The ID of the Route 53 zone where the record will be created." + type = string +} + +variable "record_name" { + description = "The name for the Route 53 record." + type = string +} + +variable "type" { + type = string + default = "A" + description = "Also known as an Address record, is used to map a domain name to an IP address." +} + +variable "evaluate_target_health" { + type = bool + default = false + description = "whether or not Route 53 should perform health checks on the target of an alias record before responding to DNS queries." +} + +variable "transfer_server_id" { + type = string + default = "" + description = "The ID of the AWS Transfer Server" +} + +variable vpc_id { + type = string + default = "" + description = "The VPC ID Where VPC enpoint is configured" +} + diff --git a/terraform-modules/aws/route53/record/README.md b/terraform-modules/aws/route53/record/README.md new file mode 100644 index 000000000..781290251 --- /dev/null +++ b/terraform-modules/aws/route53/record/README.md @@ -0,0 +1,37 @@ +## Requirements + +No requirements. + +## Providers + +| Name | Version | +|------|---------| +| [aws](#provider\_aws) | n/a | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [aws_route53_record.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [evaluate\_target\_health](#input\_evaluate\_target\_health) | whether or not Route 53 should perform health checks on the target of an alias record before responding to DNS queries. | `bool` | `false` | no | +| [record\_name](#input\_record\_name) | The name for the Route 53 record. | `string` | n/a | yes | +| [route53\_zone\_id](#input\_route53\_zone\_id) | The ID of the Route 53 zone where the record will be created. | `string` | n/a | yes | +| [type](#input\_type) | Also known as an Address record, is used to map a domain name to an IP address. | `string` | `"A"` | no | +| [vpc\_endpoint\_dns\_name](#input\_vpc\_endpoint\_dns\_name) | The DNS name of the VPC Endpoint. | `string` | n/a | yes | +| [vpc\_endpoint\_zone\_id](#input\_vpc\_endpoint\_zone\_id) | The ID of the Hosted Zone for the VPC Endpoint. | `string` | n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| [fqdn](#output\_fqdn) | FQDN built using the zone domain and name. | +| [name](#output\_name) | The name for the Route 53 record. | diff --git a/terraform-modules/aws/route53/record/main.tf b/terraform-modules/aws/route53/record/main.tf new file mode 100644 index 000000000..e5c13cd18 --- /dev/null +++ b/terraform-modules/aws/route53/record/main.tf @@ -0,0 +1,10 @@ +resource "aws_route53_record" "this" { + zone_id = var.route53_zone_id + name = var.record_name + type = var.type + alias { + name = var.vpc_endpoint_dns_name + zone_id = var.vpc_endpoint_zone_id + evaluate_target_health = false + } +} \ No newline at end of file diff --git a/terraform-modules/aws/route53/record/outputs.tf b/terraform-modules/aws/route53/record/outputs.tf new file mode 100644 index 000000000..511ba9275 --- /dev/null +++ b/terraform-modules/aws/route53/record/outputs.tf @@ -0,0 +1,9 @@ +output "name" { + value = aws_route53_record.this.name + description = "The name for the Route 53 record." +} + +output "fqdn" { + value = aws_route53_record.this.fqdn + description = "FQDN built using the zone domain and name." +} diff --git a/terraform-modules/aws/route53/record/variables.tf b/terraform-modules/aws/route53/record/variables.tf new file mode 100644 index 000000000..f896bcab9 --- /dev/null +++ b/terraform-modules/aws/route53/record/variables.tf @@ -0,0 +1,32 @@ +variable "route53_zone_id" { + description = "The ID of the Route 53 zone where the record will be created." + type = string +} + +variable "record_name" { + description = "The name for the Route 53 record." + type = string +} + +variable "type" { + type = string + default = "A" + description = "Also known as an Address record, is used to map a domain name to an IP address." +} + + +variable "vpc_endpoint_dns_name" { + description = "The DNS name of the VPC Endpoint." + type = string +} + +variable "vpc_endpoint_zone_id" { + description = "The ID of the Hosted Zone for the VPC Endpoint." + type = string +} + +variable "evaluate_target_health" { + type = bool + default = false + description = "whether or not Route 53 should perform health checks on the target of an alias record before responding to DNS queries." +}