Skip to content
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

fix: Security group for secondary interface #557

Merged
merged 9 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/complete/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ output "slz_vsi" {
value = module.slz_vsi
description = "VSI module values"
}

output "secondary_subnets" {
description = "Secondary subnets created"
value = local.secondary_subnet_zone_list
}

output "secondary_security_groups" {
description = "Secondary security groups created"
value = local.secondary_security_groups
}
10 changes: 9 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@ resource "ibm_is_instance" "vsi" {
}
content {
subnet = network_interfaces.value.id
security_groups = flatten([
# If security_groups is empty(list is len(0)) then default list to default_security_group_id.
# If list is empty it will fail on reapply as when vsi is passed an empty security group list it will attach the default security group.
security_groups = length(flatten([
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ocofaigh any ideas how I could avoid code duplication here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jor2 Its pretty hard to follow that logic - could you maybe add some code comments to explain what its doing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments. It just checks if security group list is empty don't pass empty list, instead pass default security group. This avoid reapply failures.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thanks, comment is good. As for code duplication, have you tried using locals?

(var.create_security_group && var.secondary_use_vsi_security_group ? [ibm_is_security_group.security_group[var.security_group.name].id] : []),
[
for group in var.secondary_security_groups :
group.security_group_id if group.interface_name == network_interfaces.value.name
]
])) == 0 ? [local.default_security_group_id] : flatten([
(var.create_security_group && var.secondary_use_vsi_security_group ? [ibm_is_security_group.security_group[var.security_group.name].id] : []),
[
for group in var.secondary_security_groups :
Expand Down
4 changes: 2 additions & 2 deletions module-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@
},
"pos": {
"filename": "main.tf",
"line": 174
"line": 182
}
},
"ibm_is_floating_ip.vsi_fip": {
Expand All @@ -485,7 +485,7 @@
},
"pos": {
"filename": "main.tf",
"line": 166
"line": 174
}
},
"ibm_is_instance.vsi": {
Expand Down