title: terraform destroy error - aws_security_group: DependencyViolation: resource sg-XXX has a dependent object
body: <p>Following Terraform script always returns following error when destroying the infrastructure. Notice that security group &quot;GC-SG-VPC1&quot; is being used in ingress rule in security group &quot;default&quot;. During destroy Terraform attempts to delete &quot;GC-SG-VPC1&quot; and fails after multiple retries.</p>
  <p>Any suggestions to get around this is much appreciated.</p>
  <p><strong>aws_security_group: DependencyViolation: resource sg-XXX has a dependent object</strong></p>
  <pre><code># Security Group GC-SG-VPC1
  resource &quot;aws_security_group&quot; &quot;GC-SG-VPC1&quot; {
    name   = &quot;GC-SG-VPC1&quot;
    vpc_id = aws_vpc.vpc1.id
  
    tags = {
      Name = &quot;GCTF-SG-VPC1&quot;
    }
    #SSH and all PING
    ingress {
      description = &quot;Allow SSH&quot;
      from_port   = 22
      to_port     = 22
      protocol    = &quot;tcp&quot;
      cidr_blocks = [&quot;0.0.0.0/0&quot;]
    }
  
    ingress {
      description = &quot;Allow all PING&quot;
      from_port   = -1
      to_port     = -1
      protocol    = &quot;icmp&quot;
      cidr_blocks = [&quot;0.0.0.0/0&quot;]
    }
  
    ingress {
      description = &quot;Allow iPERF3&quot;
      from_port   = 5201
      to_port     = 5201
      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;]
    }
  }
  
  # Security Group default
  resource &quot;aws_default_security_group&quot; &quot;default&quot; {
    vpc_id = aws_vpc.vpc1.id
  
    ingress {
      description = &quot;Default SG for VPC1&quot;
      from_port   = 0
      to_port     = 0
      protocol    = &quot;-1&quot;
      self        = true
    }
  
    ingress {
      description     = &quot;Include EC2 SG in VPC1 default SG&quot;
      from_port       = 0
      to_port         = 0
      protocol        = &quot;-1&quot;
      security_groups = [aws_security_group.GC-SG-VPC1.id]
    }
  
    egress {
      from_port   = 0
      to_port     = 0
      protocol    = &quot;-1&quot;
      cidr_blocks = [&quot;0.0.0.0/0&quot;]
    }
  
    tags = {
      Name = &quot;Default VPC1-SG&quot;
    }
  }
  </code></pre>