aws ec2 private and public DNS name

1,274 views
Skip to first unread message

deepak.d...@gmail.com

unread,
Nov 5, 2016, 1:26:31 AM11/5/16
to Terraform
Hi, I am new to terraform, i am using it to provision ec2 instances and i want to store the private and public DNS names of my ec2 instances as terraform's outputs variables - how can i do that?
Can some one please help me with it?

Thanks,
Deepak

deepak.d...@gmail.com

unread,
Nov 5, 2016, 1:32:26 AM11/5/16
to Terraform
i got it now, i used below in my outputs,tf

output "subnet_id" {

  value = "${aws_subnet.us-west-2b-private-subnet.id}"

}

~  

deepak.d...@gmail.com

unread,
Nov 5, 2016, 1:33:55 AM11/5/16
to Terraform

Sorry the correct code is below:

output "private_dns" {

  value = "${aws_instance.test.private_dns}"

}

On Saturday, November 5, 2016 at 10:56:31 AM UTC+5:30, deepak.d...@gmail.com wrote:

David Maze

unread,
Nov 7, 2016, 9:13:11 AM11/7/16
to Terraform
On Saturday, November 5, 2016 at 1:26:31 AM UTC-4, deepak.d...@gmail.com wrote:
Hi, I am new to terraform, i am using it to provision ec2 instances and i want to store the private and public DNS names of my ec2 instances as terraform's outputs variables - how can i do that?

One thing it took me months to realize is that, if you have a standard pattern to provision EC2 instances, it's all but free to also provision a Route 53 DNS name of your choosing while you're in there.  "myinstance.example.com" is a lot easier to remember than "ip-10-0-1-2.ec2.internal".

var "name" { default = "foo" }
resource "aws_instance" "instance" {
  name = "${var.name}"
  ...
}
resource "aws_route53_record" "dns" {
  name = "${var.name}.${var.domain}"
  ...
}
output "fqdn" {
  value = "${aws_route_53_record.dns.fqdn}"
}
Reply all
Reply to author
Forward
0 new messages