-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds prefix filters functionality to the transit gateway connec…
…tions that is used to permit or deny specific IP address ranges (called prefixes) on specific network connections(#544)
- Loading branch information
Showing
19 changed files
with
296 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Example transit gateway that connects two VPCs with prefix filtering | ||
|
||
This example provisions two VPCs and a transit gateway that configures connectivity between them. | ||
|
||
Add prefix filtering that determine the routes that transit gateway should accept or deny. | ||
|
||
**Explanation:** | ||
- Prefix filters can be used to permit or deny specific specific IP address ranges (called prefixes) on specific network connections. | ||
- This helps to allow only traffic from trusted networks and block unwanted traffic from certain ranges. | ||
- In this example, once deployed- | ||
- For both VPC connections vpc_conn_inst1 and vpc_conn_inst2, prefix filter will be created. | ||
- For VPC connection vpc_conn_inst1, default_prefix_filter is set to `permit` and prefix filters are `allow` 10.10.10.0/24 but `deny` 10.20.10.0/24. This means after processing the entries in the prefix filter list (allow 10.10.10.0/24 and deny 10.20.10.0/24) it accepts rest of the IP addresses. | ||
- For VPC connection vpc_conn_inst2, default_prefix_filter is set to `deny` and prefix filters is `allow` 10.20.10.0/24. This means after processing the entries in the prefix filter list (allow 10.20.10.0/24) it denies rest of the IP addresses. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
############################################################################## | ||
# Resource Group | ||
############################################################################## | ||
|
||
module "resource_group" { | ||
source = "terraform-ibm-modules/resource-group/ibm" | ||
version = "1.1.6" | ||
# if an existing resource group is not set (null) create a new one using prefix | ||
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null | ||
existing_resource_group_name = var.resource_group | ||
} | ||
|
||
############################################################################## | ||
# 2 VPCs | ||
############################################################################## | ||
|
||
module "vpc_1" { | ||
source = "terraform-ibm-modules/landing-zone-vpc/ibm" | ||
version = "7.19.0" | ||
resource_group_id = module.resource_group.resource_group_id | ||
region = var.region | ||
prefix = var.prefix | ||
tags = var.resource_tags | ||
name = "${var.prefix}-vpc1" | ||
use_public_gateways = { | ||
zone-1 = false | ||
zone-2 = false | ||
zone-3 = false | ||
} | ||
} | ||
|
||
module "vpc_2" { | ||
source = "terraform-ibm-modules/landing-zone-vpc/ibm" | ||
version = "7.19.0" | ||
resource_group_id = module.resource_group.resource_group_id | ||
region = var.region | ||
prefix = var.prefix | ||
tags = var.resource_tags | ||
name = "${var.prefix}-vpc2" | ||
use_public_gateways = { | ||
zone-1 = false | ||
zone-2 = false | ||
zone-3 = false | ||
} | ||
} | ||
|
||
############################################################################## | ||
# Transit Gateway connects the 2 VPCs with prefix filters | ||
############################################################################## | ||
|
||
module "tg_gateway_connection" { | ||
source = "../.." | ||
transit_gateway_name = var.transit_gateway_name | ||
region = var.region | ||
global_routing = false | ||
resource_tags = var.resource_tags | ||
resource_group_id = module.resource_group.resource_group_id | ||
classic_connections_count = 0 | ||
vpc_connections = [ | ||
{ | ||
vpc_crn = module.vpc_1.vpc_crn | ||
default_prefix_filter = "permit" | ||
}, | ||
{ | ||
vpc_crn = module.vpc_2.vpc_crn | ||
default_prefix_filter = "deny" | ||
} | ||
] | ||
add_prefix_filters = [ | ||
{ | ||
action = "permit" | ||
prefix = "10.10.10.0/24" | ||
le = 24 | ||
ge = 24 | ||
connection = module.vpc_1.vpc_crn | ||
}, | ||
{ | ||
action = "deny" | ||
prefix = "10.20.10.0/24" | ||
le = 24 | ||
ge = 24 | ||
connection = module.vpc_1.vpc_crn | ||
}, | ||
{ | ||
action = "permit" | ||
prefix = "10.20.10.0/24" | ||
le = 24 | ||
ge = 24 | ||
connection = module.vpc_2.vpc_crn | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
############################################################################## | ||
# Outputs | ||
############################################################################## | ||
|
||
output "tg_id" { | ||
description = "The ID of the transit gateway" | ||
value = module.tg_gateway_connection.tg_id | ||
} | ||
|
||
output "filter_ids" { | ||
description = "Prefix filter IDs" | ||
value = module.tg_gateway_connection.filter_ids | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
provider "ibm" { | ||
ibmcloud_api_key = var.ibmcloud_api_key | ||
region = var.region | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
variable "ibmcloud_api_key" { | ||
description = "API key that is associated with the account to provision resources to" | ||
type = string | ||
sensitive = true | ||
} | ||
|
||
variable "prefix" { | ||
description = "The prefix to append to your resources" | ||
type = string | ||
} | ||
|
||
variable "transit_gateway_name" { | ||
description = "Name of the transit gateway" | ||
type = string | ||
} | ||
|
||
variable "region" { | ||
description = "Location of the transit gateway." | ||
type = string | ||
} | ||
|
||
variable "resource_group" { | ||
type = string | ||
description = "An existing resource group name to use for this example. If not set, a new resource group is created." | ||
default = null | ||
} | ||
|
||
variable "resource_tags" { | ||
type = list(string) | ||
description = "List of tags" | ||
default = null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
terraform { | ||
required_version = ">= 1.0.0" | ||
# Ensure that there is always 1 example locked into the lowest provider version of the range defined in the main | ||
# module's version.tf (basic), and 1 example that will always use the latest provider version. | ||
required_providers { | ||
ibm = { | ||
source = "IBM-Cloud/ibm" | ||
version = ">= 1.69.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ terraform { | |
required_providers { | ||
ibm = { | ||
source = "IBM-Cloud/ibm" | ||
version = "1.52.0" | ||
version = "1.69.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.