Skip to content

Commit 539d37a

Browse files
author
Sean Sundberg
authored
Adds base_security_group_name variable and tests for null (#46)
Signed-off-by: Sean Sundberg <[email protected]>
1 parent f628a15 commit 539d37a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ locals {
1313
ipv4_cidr_provided = var.address_prefix_count > 0 && length(var.address_prefixes) >= var.address_prefix_count
1414
ipv4_cidr_block = local.ipv4_cidr_provided ? var.address_prefixes : [ for val in range(var.address_prefix_count): "" ]
1515
provision_cidr = var.provision && local.ipv4_cidr_provided
16+
base_security_group_name = var.base_security_group_name != null && var.base_security_group_name != "" ? var.base_security_group_name : "${local.vpc_name}-base"
1617
}
1718

1819
resource ibm_is_vpc vpc {
@@ -58,22 +59,22 @@ resource null_resource setup_default_acl {
5859
resource ibm_is_security_group base {
5960
count = var.provision ? 1 : 0
6061

61-
name = "${local.vpc_name}-base"
62+
name = local.base_security_group_name
6263
vpc = data.ibm_is_vpc.vpc.id
6364
resource_group = var.resource_group_id
6465
}
6566

6667
data ibm_is_security_group base {
6768
depends_on = [ibm_is_security_group.base]
6869

69-
name = "${local.vpc_name}-base"
70+
name = local.base_security_group_name
7071
}
7172

7273
resource null_resource print_sg_name {
7374
depends_on = [data.ibm_is_security_group.base]
7475

7576
provisioner "local-exec" {
76-
command = "echo 'SG name: ${data.ibm_is_security_group.base.name}'"
77+
command = "echo 'SG name: ${data.ibm_is_security_group.base.name != null ? data.ibm_is_security_group.base.name : "null"}'"
7778
}
7879
}
7980

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@ variable "address_prefixes" {
4848
description = "List of ipv4 cidr blocks for the address prefixes (e.g. ['10.10.10.0/24']). If you are providing cidr blocks then a value must be provided for each of the subnets. If you don't provide cidr blocks for each of the subnets then values will be generated using the {ipv4_address_count} value."
4949
default = []
5050
}
51+
52+
variable "base_security_group_name" {
53+
type = string
54+
description = "The name of the base security group. If not provided the name will be based on the vpc name"
55+
default = ""
56+
}

0 commit comments

Comments
 (0)