aws terraform_在AWS第1部分中使用Terraform自动缩放组:基本步骤
生活随笔
收集整理的這篇文章主要介紹了
aws terraform_在AWS第1部分中使用Terraform自动缩放组:基本步骤
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
aws terraform
因此,您想使用Terraform在AWS上創(chuàng)建一個自動縮放組。 以下是達到此目的的最少步驟。
在編寫實際代碼之前,應指定aws terraform提供程序以及provider.tf文件上的區(qū)域。
provider "aws" { version = "~> 2.0" region = "eu-west-1" } terraform { required_version = "~>0.12.0" }然后我們將
第一步是在variables.tf文件上定義一些變量。
variable "vpc_id" { type = string default = "your-vpc-id" } variable "launch_configuration_name" { type = string default = "launch_configuration_name" } variable "auto_scalling_group_name" { type = string default = "auto_scalling_group_name" } variable "image_id" { type = string default = "image-id-based-on-the-region" } variable "instance_type" { type = "string" default = "t2.micro" }然后,我們將在autoscalling_group.tf文件上具有自動縮放組配置。
data "aws_subnet_ids" "subnets" { vpc_id = var.vpc_id } data "aws_subnet" "subnet_values" { for_each = data.aws_subnet_ids.subnets.ids id = each.value } resource "aws_launch_configuration" "launch-configuration" { name = var.launch_configuration_name image_id = var.image_id instance_type = var.instance_type } resource "aws_autoscaling_group" "autoscalling_group_config" { name = var.auto_scalling_group_name max_size = 3 min_size = 2 health_check_grace_period = 300 health_check_type = "EC2" desired_capacity = 3 force_delete = true vpc_zone_identifier = [ for s in data.aws_subnet.subnet_values: s. id ] launch_configuration = aws_launch_configuration.launch-configuration.name lifecycle { create_before_destroy = true } }讓我們分解一下。 需要vpc id才能識別自動伸縮組使用的子網(wǎng)。 因此,值vpc_zone_identifier將從定義的vpc派生子網(wǎng)。
然后,您必須創(chuàng)建啟動配置。 啟動配置應指定基于您所在地區(qū)和實例類型的映像ID。
要執(zhí)行此操作,前提是您擁有aws憑證,因此必須進行初始化,然后應用
> terraform init > terraform apply翻譯自: https://www.javacodegeeks.com/2020/01/autoscaling-groups-with-terraform-on-aws-part-1-basic-steps.html
aws terraform
總結
以上是生活随笔為你收集整理的aws terraform_在AWS第1部分中使用Terraform自动缩放组:基本步骤的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 设置电脑自动关机的方法电脑如何让设置自动
- 下一篇: 华硕推出 ProArt PA169CDV