Skip to content

Commit e6eb5ed

Browse files
authored
fix: add validation block to prevent multiple protocols in security group rule (#1096)
1 parent ac076c5 commit e6eb5ed

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

.secrets.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "go.sum|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2025-10-28T06:31:36Z",
6+
"generated_at": "2025-12-08T13:33:25Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ Expected network connectivity downtime of typically around 20 seconds.
4343
* [management-vpc](./modules/management-vpc)
4444
* [workload-vpc](./modules/workload-vpc)
4545
* [Examples](./examples)
46-
* [Basic Example](./examples/basic)
47-
* [Existing networking resources Example](./examples/existing_vpc)
48-
* [Hub and Spoke VPC Example](./examples/hub-spoke-delegated-resolver)
49-
* [Hub and Spoke VPC with manual DNS resolver Example](./examples/hub-spoke-manual-resolver)
50-
* [Landing Zone example](./examples/landing_zone)
51-
* [Specific Zone Only Example](./examples/specific-zone-only)
52-
* [VPC with DNS example](./examples/vpc-with-dns)
53-
* [VPC with Flow Logs stored in COS Example](./examples/vpc-flow-logs)
46+
* <div style="display: inline-block;"><a href="./examples/basic">Basic Example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=lzv-basic-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-landing-zone-vpc/tree/main/examples/basic" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
47+
* <div style="display: inline-block;"><a href="./examples/existing_vpc">Existing networking resources Example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=lzv-existing_vpc-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-landing-zone-vpc/tree/main/examples/existing_vpc" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
48+
* <div style="display: inline-block;"><a href="./examples/hub-spoke-delegated-resolver">Hub and Spoke VPC Example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=lzv-hub-spoke-delegated-resolver-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-landing-zone-vpc/tree/main/examples/hub-spoke-delegated-resolver" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
49+
* <div style="display: inline-block;"><a href="./examples/hub-spoke-manual-resolver">Hub and Spoke VPC with manual DNS resolver Example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=lzv-hub-spoke-manual-resolver-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-landing-zone-vpc/tree/main/examples/hub-spoke-manual-resolver" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
50+
* <div style="display: inline-block;"><a href="./examples/landing_zone">Landing Zone example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=lzv-landing_zone-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-landing-zone-vpc/tree/main/examples/landing_zone" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
51+
* <div style="display: inline-block;"><a href="./examples/specific-zone-only">Specific Zone Only Example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=lzv-specific-zone-only-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-landing-zone-vpc/tree/main/examples/specific-zone-only" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
52+
* <div style="display: inline-block;"><a href="./examples/vpc-flow-logs">VPC with Flow Logs stored in COS Example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=lzv-vpc-flow-logs-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-landing-zone-vpc/tree/main/examples/vpc-flow-logs" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
53+
* <div style="display: inline-block;"><a href="./examples/vpc-with-dns">VPC with DNS example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=lzv-vpc-with-dns-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-landing-zone-vpc/tree/main/examples/vpc-with-dns" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
5454
* [Contributing](#contributing)
5555
<!-- END OVERVIEW HOOK -->
5656

variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,21 @@ variable "security_group_rules" {
479479
condition = !(var.clean_default_sg_acl && var.security_group_rules != null && length(var.security_group_rules) > 0)
480480
error_message = "var.clean_default_sg_acl is true and var.security_group_rules are not empty, which are in direct conflict. If you want to clean the default VPC Security Group, you must not pass security_group_rules."
481481
}
482+
483+
validation {
484+
error_message = "Each security group rule must specify at most one protocol (tcp, udp, or icmp), or omit all protocol blocks to allow all protocols. Found a rule with multiple protocols defined. To allow multiple protocols, create separate rules - one for each protocol. For example, instead of one rule with both tcp and udp blocks, create two rules: one with tcp only and another with udp only."
485+
condition = (var.security_group_rules == null || length(var.security_group_rules) == 0) ? true : length(distinct(
486+
flatten([
487+
for rule in var.security_group_rules :
488+
# Count how many protocols are specified (non-null)
489+
# Return false if more than one protocol is specified
490+
false if length([
491+
for protocol in [rule.tcp, rule.udp, rule.icmp] :
492+
protocol if protocol != null
493+
]) > 1
494+
])
495+
)) == 0
496+
}
482497
}
483498

484499
variable "clean_default_sg_acl" {

0 commit comments

Comments
 (0)