Table of Contents

The Error

Plan: 0 to add, X to change, 0 to destroy (every run)

What Causes This

Terraform detects differences every plan because the cloud provider modifies values after creation (normalization).

How to Fix It

Solution 1: Use ignore_changes

lifecycle {
  ignore_changes = [ami, tags["Updated"], user_data]
}

Solution 2: Use jsonencode for Policies

# Consistent JSON formatting prevents diffs
policy = jsonencode({ Version = "2012-10-17", Statement = [...] })

Solution 3: Explicitly Set Defaults

resource "aws_security_group" "web" {
  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

Prevention Tips

  1. Pin provider versions — avoid surprise breaking changes
  2. Use CI/CD — catch errors before they hit production
  3. Test with terraform plan — always review before applying
  4. Keep Terraform updated — newer versions have better error messages
  5. Use terraform validate — catches syntax errors early

Hands-On Courses

Conclusion

This error is common and fixable. Follow the solutions above, and check our Terraform course for hands-on training that covers real-world troubleshooting scenarios.