如何通过 terraform 将 alb 注册为目标组的目标

2024-04-24

我有一个目标组,想通过 terraform 将 alb 注册为目标组的目标。https://aws.amazon.com/blogs/networking-and-content-delivery/application-load-balancer-type-target-group-for-network-load-balancer/ https://aws.amazon.com/blogs/networking-and-content-delivery/application-load-balancer-type-target-group-for-network-load-balancer/我有点找不到与此相关的文档。有人可以帮忙吗?


Terraform 文档尚未完全更新以反映新的 ALB 作为 NLB 功能的目标组。尽管如此,您应该能够通过查看 AWS API 参考和 terraform 文档来执行与下面的代码片段类似的操作:

resource "aws_vpc" "main" {
    cidr_block = "10.0.0.0/16"
}

# Create ALB
resource "aws_lb" "alb" {
    name               = "test-alb-tf"
    internal           = false
    load_balancer_type = "application"
    security_groups    = [aws_security_group.lb_sg.id]
    subnets            = aws_subnet.public.*.id
}

# Create ALB target group
resource "aws_lb_target_group" "alb_tg" {
    name     = "tf-example-lb-tg"
    port     = 80
    protocol = "HTTP"
    vpc_id   = aws_vpc.main.id
}

# Create NLB
resource "aws_lb" "nlb" {
    name               = "test-nlb-tf"
    internal           = false
    load_balancer_type = "network"
    subnets            = aws_subnet.public.*.id
}

# Create NLB target group that forwards traffic to alb
# https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_CreateTargetGroup.html
resource "aws_lb_target_group" "nlb_tg" {
    name         = "tf-example-nlb-tg"
    port         = 80
    protocol     = "TCP"
    vpc_id       = aws_vpc.main.id
    target_type  = "alb"
}

# Create target group attachment
# More details: https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_TargetDescription.html
# https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_RegisterTargets.html
resource "aws_lb_target_group_attachment" "tg_attachment" {
    target_group_arn = aws_lb_target_group.nlb_tg.arn
    # attach the ALB to this target group
    target_id        = aws_lb.alb.arn
    #  If the target type is alb, the targeted Application Load Balancer must have at least one listener whose port matches the target group port.
    port             = 80
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何通过 terraform 将 alb 注册为目标组的目标 的相关文章

随机推荐

  • 如何忽略 Eclipse 中特定类型的未捕获异常?

    我在我的 Java 应用程序中使用第三方库 这个第三方库在每次应用程序启动时都会引发自定义的未捕获异常 该异常是无害的 仅用于第三方库内部记录的目的 由于未捕获此异常 它会导致我的 Eclipse IDE 切换到调试视角 并在每次启动应用程
  • D3:打字机风格的文本过渡

    In this jsfiddle http jsfiddle net VividD QbysN 标签通过减小旧文本的字体 然后增加新文本的字体 从一个文本过渡到另一个文本 但是 我希望新文本以 打字机 方式出现 就像这样jsfiddle h
  • Angular 应用程序仅在 IE11 上抛出语法错误

    我有 Angular 应用程序 该应用程序仅适用于 IE11 我已经设置了polyfills import core js es6 symbol import core js es6 object import core js es6 fu
  • 复制构造函数创建依赖副本

    我按照描述实现了复制构造函数here https stackoverflow com questions 15020850 copy constructors and defensive copying 但问题仍然是当我更新时route c
  • 带图像背景的 Outlook 2013 HTML 签名

    我找到了另一个线程 Outlook 2013 背景图像损坏 https stackoverflow com questions 22613230 outlook 2013 background image broken 但是我无法发表评论
  • Pod 清单写入 Deployment Manifest

    在 Kubernetes 中 将正在运行的 pod 清单转换为具有 x 个副本的部署的简单方法是什么 我尝试获取清单 k get po xyz o yaml gt po1 yaml 然后编辑 yaml 并与部署清单匹配 但这似乎并不容易 我
  • 如何替换 randomForest r 包中的引导步骤

    首先是一些背景信息 这在 stats stackexchange 上可能更有趣 在我的数据分析中 我尝试比较不同机器学习方法在时间序列数据上的性能 回归 而不是分类 例如 我训练了一个 Boosting 训练模型 并将其与随机森林训练模型
  • MVC3 将多个字段验证为单个属性

    我正在尝试验证包含两个字段的电话号码 第一个字段显示区号 另一个字段显示剩余的电话号码数字 要求是 它们都是必需的 它们必须是数字 区号字段最多为 6 位数字 电话号码字段最多为 10 位数字 两个字段都需要显示一条消息 例如 如果缺少区号
  • PHP PDO 按列名对查询结果进行分组

    以下 PDO 查询返回以下结果 db new PDO sth db gt prepare SELECT 结果如下 name curso ABC stack CDE stack FGH stack IJK stack LMN overflow
  • C# 中的 String 和 string 有什么区别?

    这两者之间有什么区别 我应该使用哪一个 string s Hello world String s Hello world string https learn microsoft com en us dotnet csharp langu
  • Java boolean[] 到 byte[] 以及返回

    我正在发送byte Java 中通过套接字连接的数组 我有一个相当长的boolean 数组 其中array length 8 0 我想转换这个boolean 数组变成byte 数组的元素数量是原来的 8 倍 这样我就可以发送byte 通过套
  • 类型特征与静态成员相比的优点?

    我有一堂课 Voxel 其子类可能具有也可能不具有许多不同的属性 材料 密度等 以及 get 和 set 方法 现在 我想编写一些代码 如下所示 template
  • 如何在全日历中显示事件的描述

    如何在全日历中显示事件的描述 我的活动有标题和说明 那么如何显示描述呢 当您添加标题和描述时 它将连接起来 使用下面的代码 您可以连接标题 eventRender function event element view element fi
  • 在 recyclerview 中附加 onClickListener 的最佳位置

    当我查看一些有关回收器视图的教程时 其中一些使用 viewHolder 构造函数来附加 onClick 侦听器 而其中一些使用 onBindViewHolder 方法 哪种方法是附加 onclicklistener 的最佳位置 我真的很困惑
  • php 访问 json 中的属性

    我已将以下已解码的 json 存储在 response result gt response object stdClass 6 5 EmailAddress gt string 18 email protected cdn cgi l e
  • 从 HashRouter 中删除 #

    我在用着react router dom对于我的路由 由于我也在使用 GitHub Pages 所以我需要使用HashRouter in my Router jsx like so import React from react impor
  • 如何制作一条曲线来连接 HTML 和 CSS 中的两个节点?

    我有两个 div 我想使用曲线图连接它们 知道我怎样才能实现这一目标吗 如果运行下面提到的代码 您会看到有一个名为 命令序列启动 的标签 和两个 div 分别是 W SCMadl refresh 和 WIN64 MCCMon 现在我想使用曲
  • NSBundle pathForResource 为 NULL

    我正在使用 xcode 和 objc 创建一个简单的应用程序 我需要从文件加载 NSDictionary 但我无法使用 NSBundle 获取文件的路径 NSString l NSBundle mainBundle pathForResou
  • 在 T-SQL 中将日期时间截断为秒(删除毫秒)

    缩短包含毫秒的日期时间以仅包含秒的最佳方法是什么 例如2012 01 25 17 24 05 784 to 2012 01 25 17 24 05 这将截断毫秒 declare X datetime set X 2012 01 25 17
  • 如何通过 terraform 将 alb 注册为目标组的目标

    我有一个目标组 想通过 terraform 将 alb 注册为目标组的目标 https aws amazon com blogs networking and content delivery application load balanc