Skip to content

Commit 93e6785

Browse files
author
Sean Sundberg
authored
Removes enabled variable (#55)
Signed-off-by: Sean Sundberg <[email protected]>
1 parent 2826b53 commit 93e6785

File tree

3 files changed

+14
-37
lines changed

3 files changed

+14
-37
lines changed

main.tf

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,31 @@ locals {
77
vpc_name = lower(replace(var.name != "" ? var.name : "${local.prefix_name}-vpc", "_", "-"))
88
vpc_id = lookup(local.vpc, "id", "")
99
security_group_count = var.provision ? 2 : 0
10-
security_group_ids = var.provision && var.enabled ? [ lookup(local.vpc, "default_security_group", ""), data.ibm_is_security_group.base[0].id ] : []
10+
security_group_ids = var.provision ? [ lookup(local.vpc, "default_security_group", ""), data.ibm_is_security_group.base.id ] : []
1111
acl_id = lookup(local.vpc, "default_network_acl", "")
1212
crn = lookup(local.vpc, "resource_crn", "")
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
1616
base_security_group_name = var.base_security_group_name != null && var.base_security_group_name != "" ? var.base_security_group_name : "${local.vpc_name}-base"
17-
vpc = try(var.enabled ? data.ibm_is_vpc.vpc[0] : tomap(false), {})
18-
resource_group_id = length(data.ibm_resource_group.resource_group) > 0 ? data.ibm_resource_group.resource_group[0].id : ""
17+
vpc = data.ibm_is_vpc.vpc
18+
resource_group_id = data.ibm_resource_group.resource_group.id
1919
}
2020

2121
resource null_resource print_names {
22-
count = var.enabled ? 1 : 0
23-
2422
provisioner "local-exec" {
2523
command = "echo 'Resource group: ${var.resource_group_name}'"
2624
}
2725
}
2826

2927
data ibm_resource_group resource_group {
30-
count = var.enabled ? 1 : 0
3128
depends_on = [null_resource.print_names]
3229

3330
name = var.resource_group_name
3431
}
3532

3633
resource ibm_is_vpc vpc {
37-
count = var.provision && var.enabled ? 1 : 0
34+
count = var.provision ? 1 : 0
3835

3936
name = local.vpc_name
4037
resource_group = local.resource_group_id
@@ -45,14 +42,13 @@ resource ibm_is_vpc vpc {
4542
}
4643

4744
data ibm_is_vpc vpc {
48-
count = var.enabled ? 1 : 0
4945
depends_on = [ibm_is_vpc.vpc]
5046

5147
name = local.vpc_name
5248
}
5349

5450
resource ibm_is_vpc_address_prefix cidr_prefix {
55-
count = local.provision_cidr && var.enabled ? var.address_prefix_count : 0
51+
count = local.provision_cidr ? var.address_prefix_count : 0
5652

5753
name = "${local.vpc_name}-cidr-${format("%02s", count.index)}"
5854
zone = local.vpc_zone_names[count.index]
@@ -62,7 +58,6 @@ resource ibm_is_vpc_address_prefix cidr_prefix {
6258
}
6359

6460
resource ibm_is_network_acl_rule allow_internal_egress {
65-
count = var.enabled ? 1 : 0
6661

6762
network_acl = lookup(local.vpc, "default_network_acl", "")
6863
name = "allow-internal-egress"
@@ -73,19 +68,17 @@ resource ibm_is_network_acl_rule allow_internal_egress {
7368
}
7469

7570
resource ibm_is_network_acl_rule allow_internal_ingress {
76-
count = var.enabled ? 1 : 0
7771

7872
network_acl = lookup(local.vpc, "default_network_acl", "")
7973
name = "allow-internal-ingress"
8074
action = "allow"
8175
source = var.internal_cidr
8276
destination = var.internal_cidr
8377
direction = "inbound"
84-
before = lookup(ibm_is_network_acl_rule.deny_external_ssh[0], "rule_id", "")
78+
before = lookup(ibm_is_network_acl_rule.deny_external_ssh, "rule_id", "")
8579
}
8680

8781
resource ibm_is_network_acl_rule deny_external_ssh {
88-
count = var.enabled ? 1 : 0
8982

9083
network_acl = lookup(local.vpc, "default_network_acl", "")
9184
name = "deny-external-ssh"
@@ -99,11 +92,10 @@ resource ibm_is_network_acl_rule deny_external_ssh {
9992
source_port_max = 22
10093
source_port_min = 22
10194
}
102-
before = lookup(ibm_is_network_acl_rule.deny_external_rdp[0], "rule_id", "")
95+
before = lookup(ibm_is_network_acl_rule.deny_external_rdp, "rule_id", "")
10396
}
10497

10598
resource ibm_is_network_acl_rule deny_external_rdp {
106-
count = var.enabled ? 1 : 0
10799

108100
network_acl = lookup(local.vpc, "default_network_acl", "")
109101
name = "deny-external-rdp"
@@ -117,11 +109,10 @@ resource ibm_is_network_acl_rule deny_external_rdp {
117109
source_port_max = 3389
118110
source_port_min = 3389
119111
}
120-
before = lookup(ibm_is_network_acl_rule.deny_external_ingress[0], "rule_id", "")
112+
before = lookup(ibm_is_network_acl_rule.deny_external_ingress, "rule_id", "")
121113
}
122114

123115
resource ibm_is_network_acl_rule deny_external_ingress {
124-
count = var.enabled ? 1 : 0
125116

126117
network_acl = lookup(local.vpc, "default_network_acl", "")
127118
name = "deny-external-ingress"
@@ -132,23 +123,21 @@ resource ibm_is_network_acl_rule deny_external_ingress {
132123
}
133124

134125
resource ibm_is_security_group base {
135-
count = var.provision && var.enabled ? 1 : 0
126+
count = var.provision ? 1 : 0
136127

137128
name = local.base_security_group_name
138129
vpc = lookup(local.vpc, "id", "")
139130
resource_group = local.resource_group_id
140131
}
141132

142133
data ibm_is_security_group base {
143-
count = var.enabled ? 1 : 0
144134
depends_on = [ibm_is_security_group.base]
145135

146136
name = local.base_security_group_name
147137
}
148138

149139
# from https://cloud.ibm.com/docs/vpc?topic=vpc-service-endpoints-for-vpc
150140
resource ibm_is_security_group_rule default_inbound_ping {
151-
count = var.enabled ? 1 : 0
152141

153142
group = lookup(local.vpc, "default_security_group", "")
154143
direction = "inbound"
@@ -160,7 +149,6 @@ resource ibm_is_security_group_rule default_inbound_ping {
160149
}
161150

162151
resource ibm_is_security_group_rule default_inbound_http {
163-
count = var.enabled ? 1 : 0
164152

165153
group = lookup(local.vpc, "default_security_group", "")
166154
direction = "inbound"
@@ -173,7 +161,7 @@ resource ibm_is_security_group_rule default_inbound_http {
173161
}
174162

175163
resource ibm_is_security_group_rule cse_dns_1 {
176-
count = var.enabled ? local.security_group_count : 0
164+
count = local.security_group_count
177165

178166
group = local.security_group_ids[count.index]
179167
direction = "outbound"
@@ -185,7 +173,7 @@ resource ibm_is_security_group_rule cse_dns_1 {
185173
}
186174

187175
resource ibm_is_security_group_rule cse_dns_2 {
188-
count = var.enabled ? local.security_group_count : 0
176+
count = local.security_group_count
189177

190178
group = local.security_group_ids[count.index]
191179
direction = "outbound"
@@ -197,7 +185,7 @@ resource ibm_is_security_group_rule cse_dns_2 {
197185
}
198186

199187
resource ibm_is_security_group_rule private_dns_1 {
200-
count = var.enabled ? local.security_group_count : 0
188+
count = local.security_group_count
201189

202190
group = local.security_group_ids[count.index]
203191
direction = "outbound"
@@ -209,7 +197,7 @@ resource ibm_is_security_group_rule private_dns_1 {
209197
}
210198

211199
resource ibm_is_security_group_rule private_dns_2 {
212-
count = var.enabled ? local.security_group_count : 0
200+
count = local.security_group_count
213201

214202
group = local.security_group_ids[count.index]
215203
direction = "outbound"

outputs.tf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,11 @@ output "ids" {
4040
}
4141

4242
output "base_security_group" {
43-
value = var.enabled ? data.ibm_is_security_group.base[0].id : ""
43+
value = data.ibm_is_security_group.base.id
4444
description = "The id of the base security group to be shared by other resources. The base group is different from the default security group."
4545
}
4646

4747
output "addresses" {
4848
value = [for obj in lookup(local.vpc, "cse_source_addresses[*]", []): obj.address]
4949
description = "The ip address ranges for the VPC"
5050
}
51-
52-
output "enabled" {
53-
value = var.enabled
54-
description = "Flag indicating that the module will provision resources"
55-
}

variables.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,3 @@ variable "internal_cidr" {
5050
description = "The cidr range of the internal network"
5151
default = "10.0.0.0/8"
5252
}
53-
54-
variable "enabled" {
55-
type = bool
56-
description = "Flag to indicate that IBM VPC module should be enabled"
57-
default = true
58-
}

0 commit comments

Comments
 (0)