gpt4 book ai didi

aws-cloudformation - terraform 从 vpc 端点子网选项卡获取子网集成 ip

转载 作者:行者123 更新时间:2023-12-03 07:27:46 25 4
gpt4 key购买 nike

流程就像

1.vpc-->vpc_endpoint(com.amazonaws.us-east-1.transfer.server) --> [subnet_1,subnet_2]

2.net --> nlb --> 目标组 --> [subnet_ip_1,subnet_ip_2]

我正在创建一个 NLB,目标组指向为“AWS Transfers for sftp”创建的 VPC 终端节点 com.amazonaws.us-east-1.transfer.server 但 terraform 不会返回与VPC端点集成的子网ip

因此,目前我正在从 vpc 端点下的子网选项卡手动复制 ip。但是,我想使用 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]
}

最佳答案

尝试这样的事情:

## Data Section
data "aws_network_interface" "eni_0" {
id = "${aws_vpc_endpoint.transfer.network_interface.ids {0}"
}

data "aws_network_interface" "eni_1" {
id = "${aws_vpc_endpoint.transfer.network_interface.ids {1}"
}


## Resource Section
resource "aws_alb_target_group_attachment" "tg_att_0" {
target_group_arn = "$aws_lb_target_group.group.arn}"
target_id = "${data.aws_network_interface.eni_0.private_ips[0]}"
port = 22
}

resource "aws_alb_target_group_attachment" "tg_att_1" {
target_group_arn = "$aws_lb_target_group.group.arn}"
target_id = "${data.aws_network_interface.eni_1.private_ips[0]}"
port = 22
}

这确实有效,但还没有时间优化代码......它将允许您将 NLB 附加到 VPC 终端节点内部地址。

祝你好运。

关于aws-cloudformation - terraform 从 vpc 端点子网选项卡获取子网集成 ip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57886961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com