Terraform Error: Error: Invalid referenceTerraform Error:


C:\Users\Rajesh Kumar\Desktop\Terarform\proj1>terraform validate
│ Error: Invalid reference
│   on aws.tf line 2, in resource "aws_instance" "web":
│    2:   ami           = ami-053b0d53c279acc90
│ A reference to a resource type must be followed by at least one attribute access, specifying the resource name.

Bad Code

resource "aws_instance" "web" {
  ami           = ami-053b0d53c279acc90
  instance_type = "t3.micro"

  tags = {
    Name = "HelloWorld"

Good Code

resource "aws_instance" "web" {
  ami           = "ami-053b0d53c279acc90"
  instance_type = "t3.micro"

  tags = {
    Name = "HelloWorld"

Missing the String Quote. Check the list of Datatypes in terraform

The following is a list of data types in Terraform:

  • Primitive types:
    • String: A sequence of Unicode characters representing some text, such as “hello”.
    • Number: A numeric value. The number type can represent both whole numbers like 15 and fractional values such as 6.28318.
    • Bool: Either true or false.
  • Collection types:
    • List: A sequence of values, like [“us-west-1a”, “us-west-1c”].
    • Set: A collection of unique values that do not have any secondary identifiers or ordering.
    • Map: A collection of key-value pairs, like { “key1”: “value1”, “key2”: “value2” }.
    • Object: A collection of named attributes, like { “name”: “Terraform”, “version”: “1.2.3” }.
  • Special type:
    • Null: A value that represents absence or omission.
0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x