terraform-provider-aws: Removing ingress rules from aws_security_group is not detected
This issue was originally opened by @BookOfGreg as hashicorp/terraform#17967. It was migrated here as a result of the provider split. The original body of the issue is below.
Terraform Version
Terraform v0.11.7
+ provider.aws v1.15.0
Terraform Configuration Files
Removing Ingress from a security group has no effect
Before:
resource "aws_security_group" "my_group" {
vpc_id = "${aws_vpc.my_vpc.id}"
name = "my_group"
description = "App security group"
ingress {
from_port = 80
to_port = 80
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"]
}
}
After:
resource "aws_security_group" "my_group" {
vpc_id = "${aws_vpc.my_vpc.id}"
name = "my_group"
description = "App security group"
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
Expected Behavior
My security group has no ingress on it
Actual Behavior
My security group still has port 80
References
I’ve seen issues with similar symptoms for tools written in Go, such as this K8s bug I found: https://github.com/kubernetes/kubernetes/issues/59482 Not sure if relevant or not, feel free to remove the link from this post if it’s a red herring.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 24
- Comments: 15 (5 by maintainers)
What happens if you set ingress/egress to an empty list, rather than removing it entirely?
Still occurring for me as well on:
This one works and can also be applied as workaroud when you tried to use the
dynamicblock.Bugged with
dynamic:Workaround using a
forloop:the downside is that you have to provide all parameters (event the ones that are not required) and set unused to
null.It’s ugly, but it works for now if you cannot use
aws_security_group_ruleresource.I ran into this on egress rules as well. I feel like it is a pretty important bug since
applyruns with no errors, but rules are not removed. This could potentially lead to security issues due to extra rules that are still there.Using separate aws_security_group_rule resources instead of inline rules works around this problem.
Two years later, aws provider version 3.58.0 - issue is still here. It is disappointing that terraform can not handle crucial for security resources well.
This does work, unless you are trying to transition from inline ingress rules to separate aws_security_group_rule resources. Then you just get errors back from AWS telling you that you have duplicate rules.
A (somewhat ugly) solution that I’m using is to add a dummy ingress rule to force it to remove the real ingress rules as I move them to aws_security_group_rule resources. Then later the dummy rule can be removed (though the actual ingress rule won’t be removed until/unless this bug is fixed at some point or someone manually fixes it).
Edit: Actually doing it this way will cause it to cycle back and forth between removing external rules and adding them back in, so there’s no good non-manual solution I have found yet.