'terraform destroy error - aws_security_group: DependencyViolation: resource sg-XXX has a dependent object
Following Terraform script always returns following error when destroying the infrastructure. Notice that security group "GC-SG-VPC1" is being used in ingress rule in security group "default". During destroy Terraform attempts to delete "GC-SG-VPC1" and fails after multiple retries.
Any suggestions to get around this is much appreciated.
aws_security_group: DependencyViolation: resource sg-XXX has a dependent object
# Security Group GC-SG-VPC1
resource "aws_security_group" "GC-SG-VPC1" {
name = "GC-SG-VPC1"
vpc_id = aws_vpc.vpc1.id
tags = {
Name = "GCTF-SG-VPC1"
}
#SSH and all PING
ingress {
description = "Allow SSH"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "Allow all PING"
from_port = -1
to_port = -1
protocol = "icmp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "Allow iPERF3"
from_port = 5201
to_port = 5201
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
# Security Group default
resource "aws_default_security_group" "default" {
vpc_id = aws_vpc.vpc1.id
ingress {
description = "Default SG for VPC1"
from_port = 0
to_port = 0
protocol = "-1"
self = true
}
ingress {
description = "Include EC2 SG in VPC1 default SG"
from_port = 0
to_port = 0
protocol = "-1"
security_groups = [aws_security_group.GC-SG-VPC1.id]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "Default VPC1-SG"
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
