Lesson 2 of 4 ยท Debugging Terraform

Fix incorrect references

A reference must match both the resource type and local name that Terraform declared. A subnet referencing aws_vpc.production cannot work if the configuration only declares aws_vpc.main.

Example

resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_subnet" "public" {
  vpc_id = aws_vpc.main.id
}

Step by step

  1. Find the declaration.
  2. Copy the type and local name.
  3. Check the final attribute.
  4. Run validate again.

Common mistakes to avoid

  • Using a similarly named resource from another example.
  • Changing the attribute when the real problem is the local name.