title: Error authorizing security group egress rules: InvalidGroup.NotFound
body: <p>I am trying to get the following Terraform script to run:-</p>
  <pre><code>
  provider &quot;aws&quot; {
    region = &quot;us-west-2&quot;
  }
  
  provider &quot;random&quot; {}
  
  resource &quot;random_pet&quot; &quot;name&quot; {}
  
  resource &quot;aws_instance&quot; &quot;web&quot; {
    ami                     = &quot;ami-a0cfeed8&quot;
    instance_type           = &quot;t2.micro&quot;
    user_data               = file(&quot;init-script.sh&quot;)
    subnet_id               = &quot;subnet-0422e48590002d10d&quot;
    vpc_security_group_ids  = [aws_security_group.web-sg.id]
  
    tags = {
      Name = random_pet.name.id
    }
  }
  
  resource &quot;aws_security_group&quot; &quot;web-sg&quot; {
    name = &quot;${random_pet.name.id}-sg&quot;
    ingress {
      from_port   = 80
      to_port     = 80
      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;]
    }
  }
  
  output &quot;domain-name&quot; {
    value = aws_instance.web.public_dns
  }
  
  output &quot;application-url&quot; {
    value = &quot;${aws_instance.web.public_dns}/index.php&quot;
  }
  
  </code></pre>
  <p>However it errors with the following:-</p>
  <p><code>Error: Error authorizing security group egress rules: InvalidGroup.NotFound: The security group 'sg-0c181b93d98173b0f' does not exist status code: 400, request id: 6cd8681b-ee70-4ec0-8509-6239c56169a1</code></p>
  <p>The SG gets created with the correct name, but it claims it does not exist.</p>
  <p>I am am unsure how to resolve this.</p>