Route53 and elastic IP - associating FQDN with elastic IP

I am trying to setup a test web server for which I obtain a domain name via route53 and the IP I get from Elastic IP

What additional steps do I need to perform via Terraform so that I can successfully do a connection to http://www.nicholastest.ca ?

provider "aws" {
  region  = "ca-central-1"
}

resource "aws_route53_zone" "main" {
  name = "nicholastest.ca"
}

resource "aws_route53_zone" "www" {
  name = "www.nicholastest.ca"

  tags = {
    Environment = "www"
  }
}

resource "aws_route53_record" "www-ns" {
  zone_id = aws_route53_zone.main.zone_id
  name    = "www.nicholastest.ca"
  type    = "NS"
  ttl     = "30"
  records = aws_route53_zone.www.name_servers
}

resource "aws_security_group" "myec2_allow_ssh" {
  name        = "myec2_allow_ssh"
  description = "Allow SSH inbound traffic"

  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  ingress {
    from_port   = 443
    to_port     = 443
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    from_port       = 0
    to_port         = 0
    protocol        = "-1"
    cidr_blocks     = ["0.0.0.0/0"]
  }
}

resource "aws_instance" "web" {
  ami             = "ami-0a269ca7cc3e3beff" # data.aws_ami.myec2.id
  instance_type   = "t3.micro"
  security_groups = [aws_security_group.myec2_allow_ssh.name]
  key_name        = "testssh"

  tags = {
    Name = "Elastic IP Route 53"
  }
}

resource "aws_eip" "eip_manager" {
  instance = aws_instance.web.id
  vpc = true
  
}


resource "aws_eip_association" "eip_assoc" {
  instance_id   = aws_instance.web.id
  allocation_id = aws_eip.eip_manager.id
}

Instead of type NS you would like to use an type A or AAAA record here.

1 Like