terraform import doesn't handle aws_security_group_rule descriptions properly #8866
Labels
service/ec2
Issues and PRs that pertain to the ec2 service.
stale
Old or inactive issues managed by automation, if no further action taken these will get closed.
Community Note
Terraform Version
(also tested with v0.11.14)
Affected Resource(s)
Expected Behavior
When importing aws_security_group resources into Terraform, aws_security_group_rule objects are also created as discussed in #6652 - whether this is desirable or not is out of scope here :)
However, if two (or more) rules within the security group have the same port/protocol combination, differences in rule descriptions between each rule will be lost.
Actual Behavior
Terraform import seems to consolidate rules with the same port/protocol combination into a single rule with a list of CIDRs, and pick one of the rule descriptions, discarding the others. If you look at
aws ec2 describe-security-groups
output (see step 1 below), it does seem like the two rules have been effectively condensed down into a single rule - however, the ability to resolve different descriptions for each CIDR has been retained.Once imported into Terraform, it becomes impossible to manage state as reflected in the AWS console without destroying/recreating rules on the first run of
terraform apply
Note that if you work only with aws_security_group objects, everything works just fine - but this is suboptimal when managing SGs with lots of rules.
Also note that if TF creates the SGs and rules in the first place, everything also works as expected.
Steps to Reproduce
The text was updated successfully, but these errors were encountered: