Skip to content

Commit 1c15668

Browse files
feat: expose hub vpc inputs (#662)
1 parent c659a93 commit 1c15668

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ To attach access management tags to resources in this module, you need the follo
116116
| [ibm_is_vpc.vpc](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_vpc) | resource |
117117
| [ibm_is_vpc_address_prefix.address_prefixes](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_vpc_address_prefix) | resource |
118118
| [ibm_is_vpc_address_prefix.subnet_prefix](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_vpc_address_prefix) | resource |
119+
| [ibm_is_vpc_dns_resolution_binding.vpc_dns_resolution_binding_crn](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_vpc_dns_resolution_binding) | resource |
120+
| [ibm_is_vpc_dns_resolution_binding.vpc_dns_resolution_binding_id](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_vpc_dns_resolution_binding) | resource |
119121
| [ibm_is_vpc_routing_table.route_table](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_vpc_routing_table) | resource |
120122
| [ibm_is_vpc_routing_table_route.routing_table_routes](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_vpc_routing_table_route) | resource |
121123
| [time_sleep.wait_for_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
@@ -137,6 +139,8 @@ To attach access management tags to resources in this module, you need the follo
137139
| <a name="input_enable_vpc_flow_logs"></a> [enable\_vpc\_flow\_logs](#input\_enable\_vpc\_flow\_logs) | Flag to enable vpc flow logs. If true, flow log collector will be created | `bool` | `false` | no |
138140
| <a name="input_existing_cos_instance_guid"></a> [existing\_cos\_instance\_guid](#input\_existing\_cos\_instance\_guid) | GUID of the COS instance to create Flow log collector | `string` | `null` | no |
139141
| <a name="input_existing_storage_bucket_name"></a> [existing\_storage\_bucket\_name](#input\_existing\_storage\_bucket\_name) | Name of the COS bucket to collect VPC flow logs | `string` | `null` | no |
142+
| <a name="input_hub_vpc_crn"></a> [hub\_vpc\_crn](#input\_hub\_vpc\_crn) | Hub VPC CRN | `string` | `null` | no |
143+
| <a name="input_hub_vpc_id"></a> [hub\_vpc\_id](#input\_hub\_vpc\_id) | Hub VPC ID | `string` | `null` | no |
140144
| <a name="input_ibmcloud_api_visibility"></a> [ibmcloud\_api\_visibility](#input\_ibmcloud\_api\_visibility) | IBM Cloud API visibility used by scripts run in this module. Must be 'public', 'private', or 'public-and-private' | `string` | `"public"` | no |
141145
| <a name="input_is_flow_log_collector_active"></a> [is\_flow\_log\_collector\_active](#input\_is\_flow\_log\_collector\_active) | Indicates whether the collector is active. If false, this collector is created in inactive mode. | `bool` | `true` | no |
142146
| <a name="input_name"></a> [name](#input\_name) | Name for VPC | `string` | n/a | yes |

main.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ locals {
55
# input variable validation
66
# tflint-ignore: terraform_unused_declarations
77
validate_default_secgroup_rules = var.clean_default_sg_acl && (var.security_group_rules != null && length(var.security_group_rules) > 0) ? tobool("var.clean_default_sg_acl is true and var.security_group_rules are not empty, which are in direct conflict of each other. If you would like the default VPC Security Group to be empty, you must remove default rules from var.security_group_rules.") : true
8+
9+
# tflint-ignore: terraform_unused_declarations
10+
validate_hub_vpc_input = (var.hub_vpc_id != null && var.hub_vpc_crn != null) ? tobool("var.hub_vpc_id and var.hub_vpc_crn are mutually exclusive. Hence cannot have values at the same time.") : true
811
}
912

1013
##############################################################################
@@ -25,6 +28,34 @@ resource "ibm_is_vpc" "vpc" {
2528

2629
dns {
2730
enable_hub = var.enable_hub
31+
32+
dynamic "resolver" {
33+
for_each = var.enable_hub == false && (var.hub_vpc_id != null || var.hub_vpc_crn != null) ? [1] : []
34+
content {
35+
type = "delegated"
36+
vpc_id = var.hub_vpc_id != null ? var.hub_vpc_id : null
37+
vpc_crn = var.hub_vpc_crn != null ? var.hub_vpc_crn : null
38+
}
39+
}
40+
}
41+
42+
}
43+
44+
resource "ibm_is_vpc_dns_resolution_binding" "vpc_dns_resolution_binding_id" {
45+
count = (var.enable_hub == false && var.hub_vpc_id != null) ? 1 : 0
46+
name = "${var.prefix}-dns-binding"
47+
vpc_id = ibm_is_vpc.vpc.id # Source VPC
48+
vpc {
49+
id = var.hub_vpc_id # Target VPC ID
50+
}
51+
}
52+
53+
resource "ibm_is_vpc_dns_resolution_binding" "vpc_dns_resolution_binding_crn" {
54+
count = (var.enable_hub == false && var.hub_vpc_crn != null) ? 1 : 0
55+
name = "${var.prefix}-dns-binding"
56+
vpc_id = ibm_is_vpc.vpc.id # Source VPC
57+
vpc {
58+
crn = var.hub_vpc_crn # Target VPC CRN
2859
}
2960
}
3061

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,15 @@ variable "enable_hub" {
465465
type = bool
466466
default = false
467467
}
468+
469+
variable "hub_vpc_id" {
470+
description = "Hub VPC ID"
471+
type = string
472+
default = null
473+
}
474+
475+
variable "hub_vpc_crn" {
476+
description = "Hub VPC CRN"
477+
type = string
478+
default = null
479+
}

0 commit comments

Comments
 (0)