Terraform Challenge 3

I am having the following issue with the third challenge:

Getting the following error:

Error: Error creating EIP: InvalidParameterValue: Invalid value '' for domain.
        status code: 400, request id: 7a62c49f-347e-4fc4-9331-6e8eEXAMPLE

  on main.tf line 6, in resource "aws_eip" "eip_citadel":
   6: resource "aws_eip" "eip_citadel" {

See below my code for main.tf, variables.tf and terraform.tfvars. Do you have a hint on my mistake(s)?

main.tf

resource "aws_key_pair" "citadel-key" {
  key_name   = var.key_name
  public_key = file("/root/terraform-challenges/project-citadel/.ssh/ec2-connect-key.pub")
}

resource "aws_eip" "eip_citadel" {

  provisioner "local-exec" {
    command = "echo ${self.public_dns} >> /root/citadel_public_dns.txt"
  }
}

resource "aws_instance" "citadel" {
  ami           = var.ami
  instance_type = var.instance_type
  key_name      = var.key_name
  user_data     = file("/root/terraform-challenges/project-citadel/install-nginx.sh")
}

resource "aws_eip_association" "eip_assoc_citadel" {
  instance_id   = aws_instance.citadel.id
  allocation_id = aws_eip.eip_citadel.id
}

variables.tf

variable "region" {
  type = string
}

variable "ami" {
  type = string
}

variable "instance_type" {
  type = string
}

variable "key_name" {
  type = string
}

terraform.tfvars

region        = "eu-west-2"
ami           = "ami-06178cf087598769c"
instance_type = "m5.large"
key_name      = "citadel"

Minor tweaks in the main.tf

resource "aws_key_pair" "citadel-key" {
  key_name   = var.key_name
  public_key = file("/root/terraform-challenges/project-citadel/.ssh/ec2-connect-key.pub")
}

resource "aws_eip" "eip" {
  vpc = true
  instance = aws_instance.citadel.id
  provisioner "local-exec" {
    command = "echo ${self.public_dns} >> /root/citadel_public_dns.txt"
  }
}

resource "aws_instance" "citadel" {
  ami           = var.ami
  instance_type = var.instance_type
  key_name      = var.key_name
  user_data     = file("/root/terraform-challenges/project-citadel/install-nginx.sh")
}

else all good.

Thanks, I have completed the challenge now :slight_smile:

Great! Happy learning