title: │ Error: Reference to undeclared resource
body: <p>I am new to terraform and trying to make an instance of AWS (t2.nano) by the image below.
  this is my tf file:</p>
  <pre><code>provider &quot;aws&quot; {
    profile = &quot;default&quot;
    region  = &quot;us-west-2&quot;
  }
  
  resource &quot;aws_s3_bucket&quot; &quot;prod_tf_course&quot; {
    bucket = &quot;tf-course-20210607&quot;
    acl    = &quot;private&quot;
  }
  
  resource &quot;aws_default_vpc&quot; &quot;default&quot; {}
  
  resource &quot;aws_security_group&quot; &quot;group_web&quot;{
    name = &quot;prod_web&quot;
    description = &quot;allow standard http and https ports inbound and everithing outbound&quot;
  
    ingress{
      from_port = 80
      to_port = 80
      protocol = &quot;tcp&quot;
      cidr_blocks = [&quot;0.0.0.0/0&quot;]
    }
  
   ingress{
      from_port = 443 
      to_port = 443
      protocol = &quot;tcp&quot;
      cidr_blocks = [&quot;0.0.0.0/0&quot;]
    }
  
    egress{
      from_port = 0
      to_port = 0
      protocol = &quot;-1&quot;
      cidr_blocks = [&quot;0.0.0.0/0&quot;]
    
    }
    tags = {
      &quot;Terraform&quot; : &quot;true&quot;
    }
  
  }
  
  resource &quot;aws_instance&quot; &quot;prod_web&quot;{
    ami = &quot;ami-05105e44227712eb6&quot;
    instance_type =&quot;t2.nano&quot;
  
    vpc_security_group_ids = [
      aws_security_group.prod_web.id
    ]
  
    tags = {
      &quot;Terraform&quot; : &quot;true&quot;
    }
  }
  </code></pre>
  <p>When I run the command <code>terraform plan</code>, its produces the following error:</p>
  <pre><code>$ terraform plan
  ╷
  │ Error: Reference to undeclared resource
  │
  │   on prod.tf line 50, in resource &quot;aws_instance&quot; &quot;prod_web&quot;:
  │   50:     aws_security_group.prod_web.id
  │
  │ A managed resource &quot;aws_security_group&quot; &quot;prod_web&quot; has not been declared in
  │ the root module.
  ╵
  </code></pre>
  <p>if someone can help me fix it , i will be so happy.</p>