Skip to content

Commit

Permalink
fix: add fix to support passing null for the prefix input variable (
Browse files Browse the repository at this point in the history
  • Loading branch information
Khuzaima05 authored Aug 25, 2023
1 parent 25cfdca commit 51856ff
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ To attach access management tags to resources in this module, you need the follo
| <a name="input_name"></a> [name](#input\_name) | Name for VPC | `string` | n/a | yes |
| <a name="input_network_acls"></a> [network\_acls](#input\_network\_acls) | The list of ACLs to create. Provide at least one rule for each ACL. | <pre>list(<br> object({<br> name = string<br> add_ibm_cloud_internal_rules = optional(bool)<br> add_vpc_connectivity_rules = optional(bool)<br> prepend_ibm_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_ibm_cloud_internal_rules": true,<br> "add_vpc_connectivity_rules": true,<br> "name": "vpc-acl",<br> "prepend_ibm_rules": true,<br> "rules": []<br> }<br>]</pre> | no |
| <a name="input_network_cidrs"></a> [network\_cidrs](#input\_network\_cidrs) | List of Network CIDRs for the VPC. This is used to manage network ACL rules for cluster provisioning. | `list(string)` | <pre>[<br> "10.0.0.0/8"<br>]</pre> | no |
| <a name="input_prefix"></a> [prefix](#input\_prefix) | The prefix that you would like to append to your resources | `string` | n/a | yes |
| <a name="input_prefix"></a> [prefix](#input\_prefix) | The prefix that you would like to append to your resources. Explicitly set to null if you do not wish to use a prefix. | `string` | n/a | yes |
| <a name="input_region"></a> [region](#input\_region) | The region to which to deploy the VPC | `string` | n/a | yes |
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The resource group ID where the VPC to be created | `string` | n/a | yes |
| <a name="input_routes"></a> [routes](#input\_routes) | OPTIONAL - Allows you to specify the next hop for packets based on their destination address | <pre>list(<br> object({<br> name = string<br> route_direct_link_ingress = optional(bool)<br> route_transit_gateway_ingress = optional(bool)<br> route_vpc_zone_ingress = optional(bool)<br> routes = optional(<br> list(<br> object({<br> action = optional(string)<br> zone = number<br> destination = string<br> next_hop = string<br> })<br> ))<br> })<br> )</pre> | `[]` | no |
Expand Down
2 changes: 1 addition & 1 deletion common-dev-assets
2 changes: 1 addition & 1 deletion dynamic_values.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module "dynamic_values" {
source = "./dynamic_values"
prefix = "${var.prefix}-${var.name}"
prefix = var.prefix != null ? "${var.prefix}-${var.name}" : var.name
region = var.region
address_prefixes = var.address_prefixes
routes = var.routes
Expand Down
2 changes: 1 addition & 1 deletion dynamic_values/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ locals {
for address in var.address_prefixes[zone] :
# Return object containing name, zone, and CIDR
{
name = "${var.prefix}-${zone}-${index(var.address_prefixes[zone], address) + 1}"
name = var.prefix != null ? "${var.prefix}-${zone}-${index(var.address_prefixes[zone], address) + 1}" : "{${zone}-${index(var.address_prefixes[zone], address) + 1}"
cidr = address
zone = "${var.region}-${index(keys(var.address_prefixes), zone) + 1}"
}
Expand Down
6 changes: 2 additions & 4 deletions examples/default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ data "ibm_resource_group" "existing_resource_group" {
#############################################################################

resource "ibm_resource_instance" "cos_instance" {
count = var.enable_vpc_flow_logs ? 1 : 0

count = var.enable_vpc_flow_logs ? 1 : 0
name = "${var.prefix}-vpc-logs-cos"
resource_group_id = var.resource_group != null ? data.ibm_resource_group.existing_resource_group[0].id : ibm_resource_group.resource_group[0].id
service = "cloud-object-storage"
Expand All @@ -29,8 +28,7 @@ resource "ibm_resource_instance" "cos_instance" {
}

resource "ibm_cos_bucket" "cos_bucket" {
count = var.enable_vpc_flow_logs ? 1 : 0

count = var.enable_vpc_flow_logs ? 1 : 0
bucket_name = "${var.prefix}-vpc-logs-cos-bucket"
resource_instance_id = ibm_resource_instance.cos_instance[0].id
region_location = var.region
Expand Down
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ resource "time_sleep" "wait_for_authorization_policy" {

resource "ibm_is_vpc_routing_table" "route_table" {
for_each = module.dynamic_values.routing_table_map
name = "${var.prefix}-${var.name}-route-${each.value.name}"
name = var.prefix != null ? "${var.prefix}-${var.name}-route-${each.value.name}" : "${var.name}-route-${each.value.name}"
vpc = ibm_is_vpc.vpc.id
route_direct_link_ingress = each.value.route_direct_link_ingress
route_transit_gateway_ingress = each.value.route_transit_gateway_ingress
Expand Down Expand Up @@ -91,7 +91,7 @@ locals {

resource "ibm_is_public_gateway" "gateway" {
for_each = local.gateway_object
name = "${var.prefix}-${var.name}-public-gateway-${each.key}"
name = var.prefix != null ? "${var.prefix}-${var.name}-public-gateway-${each.key}" : "${var.name}-public-gateway-${each.key}"
vpc = ibm_is_vpc.vpc.id
resource_group = var.resource_group_id
zone = each.value
Expand Down Expand Up @@ -125,7 +125,7 @@ resource "ibm_iam_authorization_policy" "policy" {
resource "ibm_is_flow_log" "flow_logs" {
count = (var.enable_vpc_flow_logs) ? 1 : 0

name = "${var.prefix}-${var.name}-logs"
name = var.prefix != null ? "${var.prefix}-${var.name}-logs" : "${var.name}-logs"
target = ibm_is_vpc.vpc.id
active = var.is_flow_log_collector_active
storage_bucket = var.existing_storage_bucket_name
Expand Down
2 changes: 1 addition & 1 deletion module-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
"prefix": {
"name": "prefix",
"type": "string",
"description": "The prefix that you would like to append to your resources",
"description": "The prefix that you would like to append to your resources. Explicitly set to null if you do not wish to use a prefix.",
"required": true,
"source": [
"ibm_is_flow_log.flow_logs.name",
Expand Down
2 changes: 1 addition & 1 deletion network_acls.tf
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ locals {

resource "ibm_is_network_acl" "network_acl" {
for_each = local.acl_object
name = "${var.prefix}-${each.key}" #already has name of vpc in each.key
name = var.prefix != null ? "${var.prefix}-${each.key}" : each.key #already has name of vpc in each.key
vpc = ibm_is_vpc.vpc.id
resource_group = var.resource_group_id
access_tags = var.access_tags
Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ variable "region" {
}

variable "prefix" {
description = "The prefix that you would like to append to your resources"
description = "The prefix that you would like to append to your resources. Explicitly set to null if you do not wish to use a prefix."
type = string
}

Expand Down

0 comments on commit 51856ff

Please sign in to comment.