【发布时间】:2020-01-13 03:58:29
【问题描述】:
流程是这样的
1.vpc-->vpc_endpoint(com.amazonaws.us-east-1.transfer.server) --> [subnet_1, subnet_2]
2.net --> nlb --> targetgroups --> [subnet_ip_1, subnet_ip_2]
我正在创建一个 NLB,其目标组指向为“AWS 传输用于 sftp”com.amazonaws.us-east-1.transfer.server 创建的 VPC 端点,但 terraform 不返回与 VPC 端点集成的子网的 ips
所以,目前我正在从 vpc 端点下的子网选项卡手动复制 ips。 但是,我想使用 terraform 自动化这个完整的过程
任何帮助将不胜感激
resource "aws_eip" "nlb" {
count = length(var.public_subnet_ids)
vpc = true
}
resource "aws_lb" "network" {
name = "${var.service_name}-${var.env}-nlb"
load_balancer_type = "network"
dynamic subnet_mapping {
for_each = [for i in range(length(module.vpc.public_subnet_ids)) : {
subnet_id = var.public_subnet_ids[i]
allocation_id = aws_eip.nlb[i].id
}]
content {
subnet_id = subnet_mapping.value.subnet_id
allocation_id = subnet_mapping.value.allocation_id
}
}
}
resource "aws_lb_target_group" "target-group" {
name = "${var.service_name}-${var.env}-nlb-target-group"
port = 22
protocol = "TCP"
target_type = "ip"
vpc_id = var.vpc_id
}
// TODO need to add vpc endpoint subnet ip addresses manually to nlb target group as terraform doesn't export the subnet ip addresses
//resource "aws_lb_target_group_attachment" "vpc-endpoint" {
// count = length(var.public_subnet_ids)
// target_group_arn = aws_lb_target_group.target-group.arn
// target_id = this needs ip of subnets intgerated with vpc endpoint
// port = 22
//}
resource "aws_vpc_endpoint" "transfer" {
vpc_id = var.vpc_id
service_name = "com.amazonaws.${var.aws_region}.transfer.server"
vpc_endpoint_type = "Interface"
subnet_ids = var.public_subnet_ids
private_dns_enabled = true
}
resource "aws_transfer_server" "sftp" {
identity_provider_type = "API_GATEWAY"
endpoint_type = "VPC_ENDPOINT"
endpoint_details {
vpc_endpoint_id = aws_vpc_endpoint.transfer.id
}
url = aws_api_gateway_deployment.deploy.invoke_url
invocation_role = aws_iam_role.transfer-identity-provider-role.arn
logging_role = aws_iam_role.transfer-logging-role.arn
depends_on = [aws_vpc_endpoint.transfer]
}
【问题讨论】:
-
您能否编辑您的问题以包含您编写的 Terraform 代码?
-
terraform 代码有效且没有错误。但是,我找不到获取 vpc 端点子网集成 ips 的方法
-
您仍应添加minimal reproducible example,以便我们了解您的进度。
-
没有 ID 无济于事,它必须是集成 IP
标签: amazon-cloudformation terraform amazon-vpc terraform-provider-aws