Trying to debug betteraw

Hi,

I have the main.tf file which I am using for my test, so I expand some blocks or remove something and check what happens. Now I damaged that file too much and need rescue.

That’s why I am thinking how can better debug with Terraform. As I sa one very handy command #terraform state show which shows all parameters which I might use. It is a bit similar for me to #kubernetes explain from k8s. The problem until I apply my configuration that command does not print anything. And I was not able to apply because of:

$ t validate
╷
│ Error: Reference to undeclared resource
│ │   on main.tf line 125, in resource "aws_instance" "ubuntu_server":
│  125:   security_groups             = [aws_security_group.ingress-ssh.id, aws_security_group.vpc-web.id] │
│ A managed resource "aws_security_group" "vpc-web" has not been declared in the root module.

So I add that resource and it works: #resource “aws_security_group” “vpc-web” {}.

I run #terraform validate and see that everything is okay.

 $ t validate
 Success! The configuration is valid.

Going forward I run # terraform apply, and I saw another error:

Now questions, the first is above about debugging such cases, and your experience how to debug such cases? which tool are you using?

The second is, why #terraform validate does not show above error, but #terraform apply does.

 Error: creating Security Group (terraform-20230902071424196100000001): VPCIdNotSpecified: No default VPC 
for this user
│       status code: 400, request id: 430de92d-7485-4a06-9e1c-6fdf36cdccc8
│
│   with aws_security_group.vpc-web,
│   on main.tf line 168, in resource "aws_security_group" "vpc-web":
│  168: resource "aws_security_group" "vpc-web" {}
│
╵
╷
│ Error: creating EC2 Instance: VPCIdNotSpecified: No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC.
│       status code: 400, request id: 395645b8-a037-43f0-9d4f-10f2b74b7119
│
│   with aws_instance.web_server,
│   on main.tf line 169, in resource "aws_instance" "web_server":
│  169: resource "aws_instance" "web_server" {

And the last one, how to fix that issue? I am trying to resolve it also on my own, but in this case I am not sure.

I attached main.tf for reference: Download - UploadNow.io
Thanks!