Terraform AWS ELB 模块使用教程

Terraform AWS ELB 模块使用教程

terraform-aws-elb Terraform module to create AWS ELB resources 🇺🇦 项目地址: https://gitcode.com/gh_mirrors/te/terraform-aws-elb

1. 项目的目录结构及介绍

terraform-aws-elb/
├── examples/
│   ├── complete/
│   └── simple/
├── modules/
│   ├── elb/
│   └── elb_attachment/
├── .editorconfig
├── .gitignore
├── .pre-commit-config.yaml
├── .releaserc.json
├── CHANGELOG.md
├── LICENSE
├── README.md
├── main.tf
├── outputs.tf
├── variables.tf
└── versions.tf

目录结构介绍

  • examples/: 包含模块的示例配置,分为 completesimple 两个子目录,分别展示了完整和简单的使用案例。
  • modules/: 包含模块的核心代码,分为 elbelb_attachment 两个子模块。
  • .editorconfig: 编辑器配置文件,用于统一代码风格。
  • .gitignore: Git 忽略文件配置。
  • .pre-commit-config.yaml: 预提交钩子配置文件,用于代码检查和格式化。
  • .releaserc.json: 发布配置文件,用于自动化发布流程。
  • CHANGELOG.md: 项目变更日志。
  • LICENSE: 项目许可证文件。
  • README.md: 项目说明文档。
  • main.tf: 主配置文件,定义了模块的主要资源和逻辑。
  • outputs.tf: 输出配置文件,定义了模块的输出变量。
  • variables.tf: 变量配置文件,定义了模块的输入变量。
  • versions.tf: 版本配置文件,定义了 Terraform 和 Provider 的版本要求。

2. 项目的启动文件介绍

main.tf

main.tf 是 Terraform 模块的主配置文件,定义了 AWS ELB 资源的主要配置。以下是文件的主要内容:

module "elb_http" {
  source = "terraform-aws-modules/elb/aws"

  name = "elb-example"
  subnets = ["subnet-12345678", "subnet-87654321"]
  security_groups = ["sg-12345678"]
  internal = false

  listener = [
    {
      instance_port     = 80
      instance_protocol = "HTTP"
      lb_port           = 80
      lb_protocol       = "HTTP"
    },
    {
      instance_port     = 8080
      instance_protocol = "http"
      lb_port           = 8080
      lb_protocol       = "http"
      ssl_certificate_id = "arn:aws:acm:eu-west-1:235367859451:certificate/6c270328-2cd5-4b2d-8dfd-ae8d0004ad31"
    }
  ]

  health_check = {
    target              = "HTTP:80/"
    interval            = 30
    healthy_threshold   = 2
    unhealthy_threshold = 2
    timeout             = 5
  }

  access_logs = {
    bucket = "my-access-logs-bucket"
  }

  number_of_instances = 2
  instances           = ["i-06ff41a77dfb5349d", "i-4906ff41a77dfb53d"]

  tags = {
    Owner       = "user"
    Environment = "dev"
  }
}

启动文件介绍

  • source: 指定模块的源地址。
  • name: ELB 的名称。
  • subnets: 指定 ELB 所在的子网。
  • security_groups: 指定 ELB 的安全组。
  • internal: 是否为内部 ELB。
  • listener: 定义 ELB 的监听器配置,包括端口、协议和 SSL 证书。
  • health_check: 定义 ELB 的健康检查配置。
  • access_logs: 定义 ELB 的访问日志配置。
  • number_of_instances: 指定挂载到 ELB 的实例数量。
  • instances: 指定挂载到 ELB 的实例 ID。
  • tags: 定义 ELB 的标签。

3. 项目的配置文件介绍

variables.tf

variables.tf 文件定义了模块的输入变量,以下是文件的主要内容:

variable "name" {
  description = "The name of the ELB"
  type        = string
  default     = null
}

variable "subnets" {
  description = "A list of subnet IDs to attach to the ELB"
  type        = list(string)
  default     = []
}

variable "security_groups" {
  description = "A list of security group IDs to assign to the ELB"
  type        = list(string)
  default     = []
}

variable "internal" {
  description = "If true, ELB will be an internal ELB"
  type        = bool
  default     = false
}

variable "listener" {
  description = "A list of listener blocks"
  type        = list(map(string))
  default     = []
}

variable "health_check" {
  description = "A health check block"
  type        = map(string)
  default     = {}
}

variable "access_logs" {
  description = "An access logs block"
  type        = map(string)
  default     = {}
}

variable "number_of_instances" {
  description = "Number of instances to attach to ELB"
  type        = number
  default     = 0
}

variable "instances" {
  description = "List of instances ID to place in the ELB pool"
  type        = list(string)
  default     = []
}

variable "tags" {
  description = "A mapping of tags to assign to the resource"
  type        = map(string)
  default     = {}
}

配置文件介绍

  • name: ELB 的名称。
  • subnets: 指定 ELB 所在的子网。
  • security_groups: 指定 ELB 的安全组。
  • internal: 是否为内部 ELB。
  • listener: 定义 ELB 的监听器配置。
  • health_check: 定义 ELB 的健康检查配置。
  • access_logs: 定义 ELB 的访问日志配置。
  • number_of_instances: 指定挂载到 ELB 的实例数量。
  • instances: 指定挂载到 ELB 的实例 ID。
  • tags: 定义 ELB 的标签。

通过以上配置文件,用户可以根据自己的需求灵活配置 AWS ELB 资源。

terraform-aws-elb Terraform module to create AWS ELB resources 🇺🇦 项目地址: https://gitcode.com/gh_mirrors/te/terraform-aws-elb

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

纪亚钧

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值