[英]Terraform for AWS: Pass specific resource address based on AZ of the beanstalk instance
Setup设置
I have a system with a beanstalk application that can span multiple AZs.我有一个带有可跨越多个可用区的 beanstalk 应用程序的系统。 The application needs to get data from ElastiCache instances, but they need to be the closest to each other.应用程序需要从 ElastiCache 实例获取数据,但它们需要彼此最接近。
For instance, The beanstalk spins up instances B1 and B2 in AZs A and B. There is the primary ElastiCache instance E1 in AZ A, with a read-replica in B , being E2.例如,beanstalk 在可用区 A 和 B 中启动实例 B1 和 B2。在可用区 A 中有主 ElastiCache 实例 E1,在 B 中有一个只读副本,即 E2。
B1 needs to contact E1, and B2 should get data from E2 for efficiency. B1 需要联系 E1,B2 应该从 E2 获取数据以提高效率。
Question题
In Terraform, how do I tell the system to pass the specific address of the ElastiCache instances based on what AZ they are created in?在 Terraform 中,我如何告诉系统根据它们在哪个可用区中创建来传递 ElastiCache 实例的特定地址? If an auto-scaling rule for the beanstalk detects a high CPU usage and creates a new instance in AZ A, I need the address of E1 to be passed as a variable, but if a new instance is spun up in AZ B, then I need E2's address to be passed.如果 beanstalk 的自动缩放规则检测到高 CPU 使用率并在 AZ A 中创建一个新实例,我需要将 E1 的地址作为变量传递,但如果在 AZ B 中启动了一个新实例,那么我需要通过E2的地址。
Is this possible in Terraform (0.12), and if so, how?这在 Terraform (0.12) 中是否可行,如果可以,如何实现?
A coworker suggested this: When creating the Redis instances, register their addresses in the Parameter Store with the name having the zone identifier in it.一位同事建议:在创建 Redis 实例时,在 Parameter Store 中注册它们的地址,名称中包含区域标识符。 Then, when an EC2 instance spins up, part of the initialization code will call 169.254.169.254 to get the metadata for the instance, which includes the AZ identifier.然后,当 EC2 实例启动时,部分初始化代码将调用 169.254.169.254 以获取实例的元数据,其中包括 AZ 标识符。 It can then grab the address for the Redis instance in that zone.然后它可以获取该区域中 Redis 实例的地址。 Short and sweet!又短又甜!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.