簡體   English   中英

從 ASG 獲取私人 IP

[英]Get Private IP from ASG

我需要 output private IP 來自 EC2 實例的 Auto Scaling Group,該實例由 Terraform 配置。如何從 ASG 獲得私有 IP?

 # Launch config for ASG resource "aws_launch_configuration" "asg_conf" { name = "ASG-Conf-${var.env}" image_id = data.aws_ami.ubuntu.id # Get image from data instance_type = var.instance_type # use t2.micro ad default security_groups = [var.sg_app.id, var.sg_alb.id] # SG for APP key_name = var.ssh_key # SSH key for connection to EC2 user_data = file("./modules/ec2/shell/apache.sh") # install apache lifecycle { create_before_destroy = true } } # Auto Scaling Group resource "aws_autoscaling_group" "asg" { count = length(var.private_su.net_id) # count numbers of private su.nets name = "ASG-${var.env}-${count.index + 1}" vpc_zone_identifier = [var.private_su.net_id[count.index]] launch_configuration = aws_launch_configuration.asg_conf.name target_group_arns = [var.alb_target.arn] min_size = 1 # Min size of creating EC2 max_size = 1 # Max size of creating EC2 health_check_grace_period = 120 health_check_type = "ELB" force_delete = true lifecycle { create_before_destroy = true } tag { key = "Name" value = "Webserver-ec2-${count.index + 1}" propagate_at_launch = true } } output { # How can i get this??? value = aws_autoscaling_group.asg.private_ip }

我的基礎設施通過 ASG 在 2 個私有 AZ 中創建 1 個 EC2 實例,我需要來自這個 ASG 的 output IP

您需要自定義數據源來獲取 IP。 但這真的沒有多大意義,因為 ASG 中的實例可以隨時被 AWS 更改,從而使您的 IP 過時。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM