1

UPDATE: rewritten question

I have an ec2 instance launched via terraform which is unreachable; I manually launched the exact same type of instance, based on the exact same image and was able to connect to it no issues.

Comparing the 2 instances, the only differences I can see is in network settings:

  • Public IPv4 DNS is listed for the reachable (manually launched) instance, but blank for the terraformed instance.
  • Answer private resource DNS name is listed as IPv4 (A) for the reachable instance and blank for the terraformed instance.

Q: How do I provide this missing piece of infra?

  • the dns provider seems to be for setting up custom domains? I don't need that / don't have a custom domain name I want to use for this server.
  • the different record types are confusing to me because I'm not a networking expert.

Can anyone point me in the right direction to specify this in terraform?

yen
  • 183

3 Answers3

1

As the post EC2 instance has no public DNS was closed and the procedure to Enable auto-assign public IPv4 addresses seems to have changed (at least I can't find the option anymore) I want to provide an updated answer:

  1. Click on the concerning EC2 instance to get to the instance summary
  2. Locate it's Subnet ID and click on the link to get to it
  3. On the top right click on Actions then on Edit subnet settings
  4. Check the button that says Enable auto-assign public IPv4 address and click Save
  5. Go back to your EC2 instance and reboot it

Also make sure the Stop Protection is deactivated as it doesn't give you a warning when you try to reboot.

0

The following two posts may answer your question.

From the post EC2 instance has no public DNS :

  • Go to console.aws.amazon.com
  • Go To Services -> VPC
  • Open Your VPCs
  • select your VPC connected to your EC2 and
  • select Actions > Edit DNS Hostnames
  • Change DNS hostnames: to YES

The post EC2 instance in public subnet has no public IP adds this :

Your instances won't automatically get public IPs attached to their ENIs after you enable 'Auto-assign IPv4' in your subnet. One possible solution without spinning up a new EC2 is to attach an Elastic IP (as @Oleksii Donoha suggested in the comment) to this instance. You can follow the aws docs to allocate an Elastic IP address and then associate it with your running instance.

Side note: It's not possible to attach an ephemeral ip to an already-created ENI or EC2 instance. See discussions here.

harrymc
  • 498,455
-1

I encountered the same problem

1\ if build from ground use custom vpc and route table may try in terraform provider aws_vpc there is a parameter called enable_dns_hostnames set to true then in aws_instance public_dns will be automatically assigned a Public IPv4 DNS other workarounds may be

2\ use DEFAULT vpc route table provided by aws

3\ use a aws_ec2_module so that you do not need to build from ground