Skip to content

Commit

Permalink
fix: resolve idempotency issue by explicitly using the vpc default sg (
Browse files Browse the repository at this point in the history
  • Loading branch information
vburckhardt authored Jul 4, 2022
1 parent 81521a8 commit a4fefd8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ No modules.
| [ibm_is_security_group.security_group](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_security_group) | resource |
| [ibm_is_security_group_rule.security_group_rules](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_security_group_rule) | resource |
| [ibm_is_volume.volume](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_volume) | resource |
| [ibm_is_vpc.vpc](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/is_vpc) | data source |
| [ibm_is_vpcs.vpcs](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/is_vpcs) | data source |

## Inputs

Expand Down
5 changes: 5 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extends: [
'@commitlint/config-angular'
]
}
2 changes: 1 addition & 1 deletion common-dev-assets
15 changes: 14 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,20 @@ locals {
}

##############################################################################
# Lookup default security group id in the vpc
##############################################################################

data "ibm_is_vpcs" "vpcs" {
}

data "ibm_is_vpc" "vpc" {
name = local.vpc_by_id[var.vpc_id].name
}

locals {
vpc_by_id = { for vpc in data.ibm_is_vpcs.vpcs.vpcs : vpc.id => vpc }
default_security_group_id = data.ibm_is_vpc.vpc.default_security_group
}

##############################################################################
# Create Virtual Servers
Expand All @@ -61,7 +74,7 @@ resource "ibm_is_instance" "vsi" {
primary_network_interface {
subnet = each.value.subnet_id
security_groups = flatten([
(var.create_security_group ? [ibm_is_security_group.security_group[var.security_group.name].id] : []),
(var.create_security_group ? [ibm_is_security_group.security_group[var.security_group.name].id] : [local.default_security_group_id]),
var.security_group_ids
])
allow_ip_spoofing = var.allow_ip_spoofing
Expand Down

0 comments on commit a4fefd8

Please sign in to comment.