Assign aws name identification to an ec2 instance using Terraform

Viewed 90

I created an ec2 instance using Terraform code and added one tag. But I would like to add a default instance name as well to appear in the field shown in the below screenshot.

enter image description here

How do I do that using Terraform?.

Right now, I tried the default argument for the tag but did not seem to work. I find it hard to figure out from the doc.

Code that I currently used to create it:

resource "aws_instance" "webserver" {
  ami = "ami-09a41e26df464c548"
  instance_type = "t2.micro"

  tags = {
    default = "my-ec2-instance"
    "Terraform" = "Yes"
  }
}
1 Answers

You would want to add a tag with the key of Name:

resource "aws_instance" "webserver" {
  ami = "ami-09a41e26df464c548"
  instance_type = "t2.micro"

  tags = {
    Name = "my-ec2-instance"
    "Terraform" = "Yes"
  }
}

The name of the instance will appear as such:

enter image description here

Related