How to obtain endpoint of ELB,RDS made using terraform

Viewed 4708

I am trying to create an environment variable to be used in the application by acquiring the endpoint of ELB, RDS made using terraform.

Currently I am trying to get an endpoint with aws cli as follows, but is there a simpler way?

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

For example, how to obtain the endpoint of the AWS stack created on terraform

1 Answers

Please go through terraform documents for the resources you are targetting.

aws_db_instance

aws_elb

In each document, there is a part called Attributes Reference, I personally call them available output variables

So if you need rds endpoint from terraform as output

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}"
}

You should be fine to do the same for ELB.

Sometime, not all attributes are updated in terraform document, you can follow below answer to find the right output variables

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

Related