We use the public IPv4 address to access this server. However, when this server is rebooted or recreated, this IP address would change.
To fix this, let’s create an Elastic IP Address.
An Elastic IP address is a static IPv4 address which does not change over time.
Create an Elastic IP resource with the following specifications:
- 
Resource Name:
eip - 
vpc:
true - 
instance: id of the
EC2instance created for resourcecerberus(use a reference expression) - 
create a local-exec provisioner for the
eipresource and use it to print the attribute calledpublic_dnsto a file/root/cerberus_public_dns.txton theiac-server. 
If unsure, refer to the documentation. Documentation tab is available at the top right.
this main.tf file created
resource “aws_instance” “cerberus” {
ami           = var.ami
instance_type = var.instance_type
user_data     = file(“./install-nginx.sh”)
}
resource “aws_key_pair” “cerberus-key” {
key_name   = “cerberus”
public_key = file(“.ssh/cerberus.pub”)
}
resource “aws_eip” “eip” {
vpc      = true
instance = aws_instance.cerberus.id
provisioner “local-exec” {
command = “echo ${aws_eip.eip.public_dns} >> /root/cerberus_public_dns.txt”
}
}
variable “ami” {
default = “ami-06178cf087598769c”
}
variable “instance_type” {
default = “m5.large”
}
variable “region” {
default = “eu-west-2”
}
still it says
The public_dns for the EIP is not stored in /root/cerberus_public_dns.txt