Having queries in Lab- Terraform challenge 3

I wrote the config file for each separately like variable.tf , output.tf , Inside main .tf i have mentiond keyname and user data
I also cross verified with below commands and showing below output
iac-server $ terraform show | grep ami
ami = “ami-06178cf087598769c”
iac-server $ terraform state show aws_eip.citadel_eip

aws_eip.citadel_eip:

resource “aws_eip” “citadel_eip” {
allocation_id = “eipalloc-d63dff00”
association_id = “eipassoc-9554f87f”
domain = “vpc”
id = “eipalloc-d63dff00”
instance = “i-8936e2536821affba”
network_interface = “eni-b32bee5a”
private_dns = “ip-10-230-96-199.eu-west-2.compute.internal”
private_ip = “10.230.96.199”
public_dns = “ec2-127-133-175-227.eu-west-2.compute.amazonaws.com
public_ip = “127.133.175.227”
tags_all = {}
vpc = true
}
But while trying to check , it is showing as task not completed
Can you please help me where i am doing mistake?

Hi @Dhana

You need to use the local-exec provisioner to print the public_dns to a file called /root/citadel_public_dns.txt.

It helps if you can enclose your code in a code block like this:

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

For lab , i created 3 separate config files in the directory mentioned

Varibale.tf
Variable “ami” {
default = “ami-06178cf087598769c”
}

variable “region” {
default = “eu-west-2”
}

variable “instance_type” {
default = “m5. large”
}

========
main.tf

resource “aws_key_pair” “citadel_key” {
key_name = “citadel-key”

public_key = file(“/root/terraform-challenges/project-citadel/.ssh/ec2-connect-key.pub”)
}

resource “aws_instance” “citadel_instance” {
ami = var.ami
instance_type = var.instance_type
key_name = aws_key_pair.citadel_key.key_name

user_data = file(“/root/terraform-challenges/project-citadel/install-nginx.sh”)
}

resource “aws_eip” “citadel_eip” {
instance = aws_instance.citadel_instance.id

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

======
output.tf
output “instance_id” {
value = aws_instance.citadel_instance.id
}

output “elastic_ip” {
value = aws_eip.citadel_eip.public_ip
}

output “public_dns” {
value = aws_eip.citadel_eip.public_dns
}
I could see output for all .

But Still its showing as not completed in Lab console