为了从ASG获取IP,我尝试了以下代码,该IP是使用Terraform创建的?这是好习惯还是坏习惯?但是我得到了预期的正确输出。
data "aws_instances" "test" {
instance_tags {
Environment = "${var.environment}",
instance = "${var.db_instance_name}"
}
instance_state_names = ["running"]
depends_on = ["aws_sqs_queue.ansible", "aws_autoscaling_group.sample"]
}
output.tf
output "privateips" {
value = "${data.aws_instances.test.private_ips}"
}
答案 0 :(得分:2)
创建ASG时,在末尾添加本地供应商以执行使用cli与AWS交互的本地脚本,以便您可以查询ASG IP:
grep "25/Jan/2019" access.log | aplogcsv > ~/20190125.access.log.csv
脚本:
resource "aws_autoscaling_group" "artifactory" {
name_prefix = "${var.env}-Application-ASG-"
vpc_zone_identifier = ["${var.app_subnets}"]
max_size = "${var.asg_max}"
min_size = "${var.asg_min}"
desired_capacity = "${var.asg_desired}"
force_delete = true
launch_configuration = "${aws_launch_configuration.application.name}"
target_group_arns = ["${aws_alb_target_group.application.arn}"]
provisioner "local-exec" {
command = "./getips.sh"
}
}