【问题标题】:How to obtain endpoint of ELB,RDS made using terraform如何获取使用 terraform 制作的 ELB、RDS 的端点
【发布时间】:2019-01-19 07:46:50
【问题描述】:

我正在尝试通过获取ELB的端点,使用terraform制作的RDS来创建要在应用程序中使用的环境变量。

目前我正在尝试使用 aws cli 获取端点,如下所示,但有没有更简单的方法?

aws rds describe-db-instances --db-instance-identifier xxxx | jq '.DBInstances[].Endpoint.Address'
aws elb describe-tags --load-balancer-name xxxx | jq '.TagDescriptions[].LoadBalancerName'

例如,如何获取在terraform上创建的AWS栈的端点

【问题讨论】:

    标签: terraform


    【解决方案1】:

    请查看您要定位的资源的 terraform 文档。

    aws_db_instance

    aws_elb

    在每个文档中,都有一个部分叫Attributes Reference,我个人称它们为available output variables

    所以如果你需要 terraform 的 rds 端点作为输出

    resource "aws_db_instance" "default" {
      allocated_storage    = 10
      storage_type         = "gp2"
      engine               = "mysql"
      engine_version       = "5.6.17"
      instance_class       = "db.t1.micro"
      name                 = "mydb"
      username             = "foo"
      password             = "bar"
      db_subnet_group_name = "my_database_subnet_group"
      parameter_group_name = "default.mysql5.6"
    }
    
    output "rds_endpoint" {
      value = "${aws_db_instance.default.endpoint}"
    }
    

    你应该对 ELB 做同样的事情。

    有时,并非所有属性都在 terraform 文档中更新,您可以按照以下答案找到正确的输出变量

    How to get an instance id / arn of an existing ec2 instance via terraform?

    【讨论】:

    • 是否可以通过环境变量将 rds_endpoint 变量传递给 ec2 实例?
    猜你喜欢
    • 2019-06-22
    • 1970-01-01
    • 2020-05-18
    • 2020-12-01
    • 1970-01-01
    • 2020-05-06
    • 2013-09-04
    • 2020-04-21
    • 2020-07-21
    相关资源
    最近更新 更多