Skip to content

Commit 21166c1

Browse files
authored
feat: additional functionality added along with fix of double ACL for rule names (#33)
BREAKING CHANGE: `vpc_name` variable is now called `name`
1 parent fbe68ec commit 21166c1

File tree

13 files changed

+119
-14
lines changed

13 files changed

+119
-14
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ You need the following permissions to run this module.
162162
| <a name="input_default_network_acl_name"></a> [default\_network\_acl\_name](#input\_default\_network\_acl\_name) | OPTIONAL - Name of the Default ACL. If null, a name will be automatically generated | `string` | `null` | no |
163163
| <a name="input_default_routing_table_name"></a> [default\_routing\_table\_name](#input\_default\_routing\_table\_name) | OPTIONAL - Name of the Default Routing Table. If null, a name will be automatically generated | `string` | `null` | no |
164164
| <a name="input_default_security_group_name"></a> [default\_security\_group\_name](#input\_default\_security\_group\_name) | OPTIONAL - Name of the Default Security Group. If null, a name will be automatically generated | `string` | `null` | no |
165+
| <a name="input_name"></a> [name](#input\_name) | Name for VPC | `string` | n/a | yes |
165166
| <a name="input_network_acls"></a> [network\_acls](#input\_network\_acls) | List of ACLs to create. Rules can be automatically created to allow inbound and outbound traffic from a VPC tier by adding the name of that tier to the `network_connections` list. Rules automatically generated by these network connections will be added at the beginning of a list, and will be web-tierlied to traffic first. At least one rule must be provided for each ACL. | <pre>list(<br> object({<br> name = string<br> network_connections = optional(list(string))<br> add_cluster_rules = optional(bool)<br> rules = list(<br> object({<br> name = string<br> action = string<br> destination = string<br> direction = string<br> source = string<br> tcp = optional(<br> object({<br> port_max = optional(number)<br> port_min = optional(number)<br> source_port_max = optional(number)<br> source_port_min = optional(number)<br> })<br> )<br> udp = optional(<br> object({<br> port_max = optional(number)<br> port_min = optional(number)<br> source_port_max = optional(number)<br> source_port_min = optional(number)<br> })<br> )<br> icmp = optional(<br> object({<br> type = optional(number)<br> code = optional(number)<br> })<br> )<br> })<br> )<br> })<br> )</pre> | <pre>[<br> {<br> "add_cluster_rules": true,<br> "name": "vpc-acl",<br> "rules": [<br> {<br> "action": "allow",<br> "destination": "0.0.0.0/0",<br> "direction": "inbound",<br> "name": "allow-all-inbound",<br> "source": "0.0.0.0/0"<br> },<br> {<br> "action": "allow",<br> "destination": "0.0.0.0/0",<br> "direction": "outbound",<br> "name": "allow-all-outbound",<br> "source": "0.0.0.0/0"<br> }<br> ]<br> }<br>]</pre> | no |
166167
| <a name="input_network_cidr"></a> [network\_cidr](#input\_network\_cidr) | Network CIDR for the VPC. This is used to manage network ACL rules for cluster provisioning. | `string` | `"10.0.0.0/8"` | no |
167168
| <a name="input_prefix"></a> [prefix](#input\_prefix) | The prefix that you would like to append to your resources | `string` | n/a | yes |
@@ -173,7 +174,6 @@ You need the following permissions to run this module.
173174
| <a name="input_tags"></a> [tags](#input\_tags) | List of Tags for the resource created | `list(string)` | `null` | no |
174175
| <a name="input_use_manual_address_prefixes"></a> [use\_manual\_address\_prefixes](#input\_use\_manual\_address\_prefixes) | OPTIONAL - Use manual address prefixes for VPC | `bool` | `false` | no |
175176
| <a name="input_use_public_gateways"></a> [use\_public\_gateways](#input\_use\_public\_gateways) | Create a public gateway in any of the three zones with `true`. | <pre>object({<br> zone-1 = optional(bool)<br> zone-2 = optional(bool)<br> zone-3 = optional(bool)<br> })</pre> | <pre>{<br> "zone-1": true,<br> "zone-2": false,<br> "zone-3": false<br>}</pre> | no |
176-
| <a name="input_vpc_name"></a> [vpc\_name](#input\_vpc\_name) | Name for vpc. If left null, one will be generated using the prefix for this module. | `string` | `null` | no |
177177

178178
## Outputs
179179

@@ -184,6 +184,7 @@ You need the following permissions to run this module.
184184
| <a name="output_subnet_zone_list"></a> [subnet\_zone\_list](#output\_subnet\_zone\_list) | A list containing subnet IDs and subnet zones |
185185
| <a name="output_vpc_crn"></a> [vpc\_crn](#output\_vpc\_crn) | CRN of VPC created |
186186
| <a name="output_vpc_id"></a> [vpc\_id](#output\_vpc\_id) | ID of VPC created |
187+
| <a name="output_vpc_name"></a> [vpc\_name](#output\_vpc\_name) | Name of VPC created |
187188
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
188189

189190
## Contributing

dynamic_values.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
module "dynamic_values" {
66
source = "./dynamic_values"
7-
prefix = var.prefix
7+
prefix = "${var.prefix}-${var.name}"
88
region = var.region
99
address_prefixes = var.address_prefixes
1010
routes = var.routes

dynamic_values/address_prefixes.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
##############################################################################
2+
# Address Prefixes
3+
##############################################################################
4+
5+
module "prefix_map" {
6+
source = "./config_modules/list_to_map"
7+
key_name_field = "zone_name"
8+
list = [
9+
for zone in ["zone-1", "zone-2", "zone-3"] :
10+
{
11+
zone_name = zone
12+
addresses = [
13+
for address in(lookup(var.address_prefixes, zone, null) == null ? [] : var.address_prefixes[zone]) :
14+
{
15+
name = "${var.prefix}-${zone}-${index(var.address_prefixes[zone], address) + 1}"
16+
cidr = address
17+
zone = "${var.region}-${index(keys(var.address_prefixes), zone) + 1}"
18+
}
19+
]
20+
}
21+
]
22+
}
23+
24+
module "address_prefixes" {
25+
source = "./config_modules/list_to_map"
26+
list = flatten([
27+
for zone in ["zone-1", "zone-2", "zone-3"] :
28+
module.prefix_map.value[zone].addresses
29+
])
30+
}
31+
32+
##############################################################################

dynamic_values/config_modules/list_to_map/main.tf

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
##############################################################################
2+
# Output
3+
##############################################################################
4+
5+
output "value" {
6+
description = "List converted into map"
7+
value = {
8+
for item in var.list :
9+
("${var.prefix == "" ? "" : "${var.prefix}-"}${item[var.key_name_field]}") =>
10+
item if(
11+
var.lookup_field == null # If not looking up
12+
? true # true
13+
: can(regex(var.lookup_value_regex, tostring(lookup(item, var.lookup_field, null)))) # Otherwise match regex
14+
)
15+
}
16+
}
17+
18+
##############################################################################
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
##############################################################################
2+
# Variables
3+
##############################################################################
4+
5+
variable "list" {
6+
description = "List of objects"
7+
type = list(any)
8+
}
9+
10+
variable "prefix" {
11+
description = "Prefix to add to map keys"
12+
type = string
13+
default = ""
14+
}
15+
16+
variable "key_name_field" {
17+
description = "Key inside each object to use as the map key"
18+
type = string
19+
default = "name"
20+
}
21+
22+
variable "lookup_field" {
23+
description = "Name of the field to find with lookup"
24+
type = string
25+
default = null
26+
}
27+
28+
variable "lookup_value_regex" {
29+
description = "regular expression for reurned value"
30+
type = string
31+
default = null
32+
}
33+
34+
##############################################################################
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
##############################################################################
2+
# Terraform Providers
3+
##############################################################################
4+
5+
terraform {
6+
required_version = ">=1.0.0"
7+
experiments = [module_variable_optional_attrs]
8+
}
9+
10+
##############################################################################

examples/default/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module "slz_vpc" {
2222
source = "../../"
2323
resource_group_id = var.resource_group != null ? data.ibm_resource_group.existing_resource_group[0].id : ibm_resource_group.resource_group[0].id
2424
region = var.region
25+
name = var.name
2526
prefix = var.prefix
2627
tags = var.resource_tags
2728
}

examples/default/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ variable "region" {
1313
variable "prefix" {
1414
description = "The prefix that you would like to append to your resources"
1515
type = string
16-
default = "test-landing-zone-vpc"
16+
default = "test-landing-zone"
17+
}
18+
19+
variable "name" {
20+
description = "The name of the vpc"
21+
type = string
22+
default = "vpc"
1723
}
1824

1925
variable "resource_group" {

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
##############################################################################
44

55
resource "ibm_is_vpc" "vpc" {
6-
name = var.vpc_name != null ? "${var.prefix}-${var.vpc_name}" : "${var.prefix}-vpc"
6+
name = var.prefix != null ? "${var.prefix}-${var.name}-vpc" : "${var.name}-vpc"
77
resource_group = var.resource_group_id
88
classic_access = var.classic_access
99
address_prefix_management = var.use_manual_address_prefixes == false ? null : "manual"
@@ -53,7 +53,7 @@ locals {
5353

5454
resource "ibm_is_vpc_route" "route" {
5555
for_each = local.routes_map
56-
name = "${var.prefix}-route-${each.value.name}"
56+
name = "${var.prefix}-${var.name}-route-${each.value.name}"
5757
vpc = ibm_is_vpc.vpc.id
5858
zone = each.value.zone
5959
destination = each.value.destination
@@ -77,7 +77,7 @@ locals {
7777

7878
resource "ibm_is_public_gateway" "gateway" {
7979
for_each = local.gateway_object
80-
name = "${var.prefix}-public-gateway-${each.key}"
80+
name = "${var.prefix}-${var.name}-public-gateway-${each.key}"
8181
vpc = ibm_is_vpc.vpc.id
8282
resource_group = var.resource_group_id
8383
zone = each.value

0 commit comments

Comments
 (0)