简体   繁体   English

Terraform for AWS:根据 beanstalk 实例的 AZ 传递特定资源地址

[英]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.

相关问题 Terraform - AWS - 创建多个实例 - 不同的 AZ(其中实例数大于 AZ 列表长度) - Terraform - AWS - create multiple instances - different AZ (where instance count is greater than AZ list length) Terraform 资源:aws_iam_instance_profile - Terraform Resource: aws_iam_instance_profile 如何将 aws_instance 资源创建的 EC2 实例 ID 传递到文件中,并使用 Terraform 将其放置在 EC2 实例中? - How to pass the EC2 instance ID created by an aws_instance resource into a file and place it inside an EC2 instance using Terraform? AWS Beanstalk Tomcat 和 Terraform - AWS Beanstalk Tomcat and Terraform 如何将aws_elastic_beanstalk_environment设置传递给Terraform模块 - How to pass aws_elastic_beanstalk_environment settings to a Terraform module 根据 terraform 中的条件或标志创建 AWS 资源 - create AWS resource based on condition or flag in terraform terraform aws serverless v2 多可用区 - terraform aws serverless v2 multi AZ Terraform:从aws_instance资源获取volume_id - Terraform: Getting volume_id from aws_instance resource "Terraform - 具有相同 aws_instance 资源的多个子网" - Terraform - Multiple subnets with same aws_instance resource 在 Terraform 中为 aws_instance 资源声明嵌套变量 - Declaring nested variables in Terraform for aws_instance resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM