-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resource/aws_security_group_rule: Prevent crash when reading rules from groups containing an ALL/-1 protocol rule #6419
Conversation
…om groups containing an ALL/-1 protocol rule The rule searching logic was missing `nil` checks. This crash was only triggered under the context of other rules existing in the group having `FromPort` and `ToPort` in comparison to the local rule not having `FromPort` and `ToPort`. This also prevents an errant difference when `to_port` is specified as 65535 in an ALL/-1 protocol rule, which is allowed by the API and previously supported in Terraform without this difference. ``` --- PASS: TestAccAWSSecurityGroupRule_ExpectInvalidTypeError (1.53s) --- PASS: TestAccAWSSecurityGroupRule_ExpectInvalidCIDR (1.70s) --- PASS: TestAccAWSSecurityGroupRule_Ingress_VPC (22.23s) --- PASS: TestAccAWSSecurityGroupRule_EgressDescription (21.89s) --- PASS: TestAccAWSSecurityGroupRule_Egress (25.56s) --- PASS: TestAccAWSSecurityGroupRule_MultipleRuleSearching_AllProtocolCrash (26.06s) --- PASS: TestAccAWSSecurityGroupRule_Issue5310 (26.90s) --- PASS: TestAccAWSSecurityGroupRule_Ingress_Classic (27.31s) --- PASS: TestAccAWSSecurityGroupRule_Description_AllPorts (34.32s) --- PASS: TestAccAWSSecurityGroupRule_Description_AllPorts_ToPort65535 (36.12s) --- PASS: TestAccAWSSecurityGroupRule_IngressDescription_updates (35.41s) --- PASS: TestAccAWSSecurityGroupRule_EgressDescription_updates (37.68s) --- PASS: TestAccAWSSecurityGroupRule_IngressDescription (39.34s) --- PASS: TestAccAWSSecurityGroupRule_Ingress_Ipv6 (41.93s) --- PASS: TestAccAWSSecurityGroupRule_Ingress_Protocol (42.58s) --- PASS: TestAccAWSSecurityGroupRule_SelfReference (43.87s) --- PASS: TestAccAWSSecurityGroupRule_SelfSource (45.94s) --- PASS: TestAccAWSSecurityGroupRule_MultiIngress (25.31s) --- PASS: TestAccAWSSecurityGroupRule_PartialMatching_Source (48.62s) --- PASS: TestAccAWSSecurityGroupRule_PartialMatching_basic (51.84s) --- PASS: TestAccAWSSecurityGroupRule_PrefixListEgress (57.50s) --- PASS: TestAccAWSSecurityGroupRule_MultiDescription (88.64s) --- PASS: TestAccAWSSecurityGroupRule_Race (274.35s) ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one minor 🤔 for future enhancement but this otherwise LGTM 👍
@@ -62,6 +62,13 @@ func resourceAwsSecurityGroupRule() *schema.Resource { | |||
Type: schema.TypeInt, | |||
Required: true, | |||
ForceNew: true, | |||
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { | |||
protocol := protocolForValue(d.Get("protocol").(string)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the future it'd be good for protocolForValue
to return a *string
so we can easily detect this is invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protocolForValue()
returns the lowercased input string if it cannot find a match. Since we're specifically checking for a known value (should probably be a constant 🤔 ), I don't think it matters too much in this context since we do not have the opportunity to throw an error (other than panic()
) within a DiffSuppressFunc
. Definitely open to chatting about this further if I'm missing something (🥁). 😄
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Fixes #6416
The rule searching logic was missing
nil
checks. This crash was only triggered under the context of other rules existing in the group havingFromPort
andToPort
in comparison to the local rule not havingFromPort
andToPort
.This also prevents an errant difference when
to_port
is specified as 65535 in an ALL/-1 protocol rule, which is allowed by the API and previously supported in Terraform without this difference.Previously:
Output from acceptance testing: