11
22locals  {
3-   zone_count         =  3 
4-   subnet_count       =  length (var. subnets ) >  0  ?  length (var. subnets ) :  var. subnet_count 
5-   vpc_zone_names     =  for  index  in  range (local. subnet_count ):  " ${ var . region } -${ (index %  local. zone_count ) +  1 } " 
63  prefix_name        =  . name_prefix  !=  " " ?  var. name_prefix  :  var. resource_group_name 
74  vpc_name           =  lower (replace (var. name  !=  " " ?  var. name  :  " ${ local . prefix_name } -vpc" " _" " -" 
85  vpc_id             =  . vpc . id 
9-   subnet_ids         =  . vpc_subnet [* ]. id 
10-   gateway_ids        =  . public_gateway  ?  ibm_is_public_gateway. vpc_gateway [* ]. id  :  [ for  val  in  range (local. zone_count ):  " " 
116  security_group_id  =  . vpc . default_security_group 
12-   ipv4_cidr_blocks   =  . vpc_subnet [* ]. ipv4_cidr_block 
13-   distinct_subnet_labels  =  distinct ([ for  val  in  var . subnets :  val . label  ])
14-   #  creates an intermediate object where the key is the label and the value is an array of labels, one for each appearance
15-   #  e.g. [{label = "basic"}, {label = "basic"}, {label = "test"}] would yield {basic = ["basic", "basic"], test = ["test"]}
16-   subnet_labels_tmp  =  for  subnet  in  var . subnets :  subnet . label  =>  subnet . label ...  }
17-   #  creates an object where the key is the label and the value is number of times the label appears in the original list
18-   #  e.g. {basic = ["basic", "basic"], test = ["test"]} would yield {basic = 2, test = 1}
19-   subnet_label_counts  =  length (var. subnets ) >  0  ?  [ for  val  in  local . distinct_subnet_labels : 
20-         {
21-           label =  val
22-           count =  length (local. subnet_labels_tmp [val ])
23-         } ] :  [ {
24-           label =  " default" 
25-           count =  local.subnet_count
26-       } ]
27- }
28- 
29- resource  null_resource  print_names  {
30-   provisioner  "local-exec"  {
31-     command  =  " echo 'Resource group: ${ var . resource_group_name } '" 
32-   }
33-   provisioner  "local-exec"  {
34-     command  =  " echo 'Subnets: ${ jsonencode (local. subnet_labels_tmp )} '" 
35-   }
36- }
37- 
38- data  ibm_resource_group  resource_group  {
39-   depends_on  =  . print_names ]
40- 
41-   name  =  . resource_group_name 
427}
438
449resource  ibm_is_vpc  vpc  {
4510  name                         =  . vpc_name 
46-   resource_group               =  data . ibm_resource_group . resource_group . id 
11+   resource_group               =  var . resource_group_id 
4712  default_security_group_name  =  " ${ local . vpc_name } -security-group" 
4813}
4914
50- resource  ibm_is_public_gateway  vpc_gateway  {
51-   count  =  . public_gateway  ?  min (local. zone_count , local. subnet_count ) :  0 
52- 
53-   name            =  " ${ local . vpc_name } -gateway-${ format (" %02s" . index )} " 
54-   vpc             =  . vpc_id 
55-   zone            =  . vpc_zone_names [count . index ]
56-   resource_group  =  . ibm_resource_group . resource_group . id 
57- 
58-   // User can configure timeouts
59-   timeouts  {
60-     create  =  " 90m" 
61-   }
62- }
63- 
6415resource  ibm_is_network_acl  network_acl  {
6516  name            =  " ${ local . vpc_name } -acl" 
6617  vpc             =  . vpc . id 
67-   resource_group  =  data . ibm_resource_group . resource_group . id 
18+   resource_group  =  var . resource_group_id 
6819
6920  rules  {
7021    name         =  " egress" 
@@ -82,37 +33,6 @@ resource ibm_is_network_acl network_acl {
8233  }
8334}
8435
85- resource  ibm_is_subnet  vpc_subnet  {
86-   count                     =  . subnet_count 
87- 
88-   name                      =  " ${ local . vpc_name } -subnet-${ format (" %02s" . index )} " 
89-   zone                      =  . vpc_zone_names [count . index ]
90-   vpc                       =  . vpc_id 
91-   public_gateway            =  . gateway_ids [count . index  %  local . zone_count ]
92-   total_ipv4_address_count  =  256 
93-   resource_group            =  . ibm_resource_group . resource_group . id 
94-   network_acl               =  . network_acl . id 
95- }
96- 
97- data  ibm_is_subnet  vpc_subnet  {
98-   count       =  . subnet_count 
99- 
100-   identifier  =  . vpc_subnet [count . index ]. id 
101- }
102- 
103- resource  ibm_is_security_group_rule  rule_tcp_k8s  {
104-   count      =  . subnet_count 
105- 
106-   group      =  . security_group_id 
107-   direction  =  " inbound" 
108-   remote     =  . ipv4_cidr_blocks [count . index ]
109- 
110-   tcp  {
111-     port_min  =  30000 
112-     port_max  =  32767 
113-   }
114- }
115- 
11636resource  ibm_is_security_group_rule  rule_icmp_ping  {
11737  group      =  . security_group_id 
11838  direction  =  " inbound" 
0 commit comments