Skip to content

Commit 1dc057f

Browse files
authored
fix: fix outputs for VPC and Subnets to support new or existing (#688)
1 parent 6f095de commit 1dc057f

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ To attach access management tags to resources in this module, you need the follo
191191
| <a name="output_subnet_ids"></a> [subnet\_ids](#output\_subnet\_ids) | The IDs of the subnets |
192192
| <a name="output_subnet_zone_list"></a> [subnet\_zone\_list](#output\_subnet\_zone\_list) | A list containing subnet IDs and subnet zones |
193193
| <a name="output_vpc_crn"></a> [vpc\_crn](#output\_vpc\_crn) | CRN of VPC created |
194-
| <a name="output_vpc_data"></a> [vpc\_data](#output\_vpc\_data) | Data of the VPC created. |
194+
| <a name="output_vpc_data"></a> [vpc\_data](#output\_vpc\_data) | Data of the VPC used in this module, created or existing. |
195195
| <a name="output_vpc_flow_logs"></a> [vpc\_flow\_logs](#output\_vpc\_flow\_logs) | Details of VPC flow logs collector |
196196
| <a name="output_vpc_id"></a> [vpc\_id](#output\_vpc\_id) | ID of VPC created |
197197
| <a name="output_vpc_name"></a> [vpc\_name](#output\_vpc\_name) | Name of VPC created |

examples/default/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ output "vpc_crn" {
1212
description = "VPC crn"
1313
}
1414

15+
output "vpc_name" {
16+
value = module.slz_vpc.vpc_data.name
17+
description = "VPC name property taken from the larger data element"
18+
}
19+
20+
output "subnet_ids" {
21+
value = module.slz_vpc.subnet_ids
22+
description = "list of VPC subnet ids created"
23+
}
24+
1525
output "vpc_flow_logs_collector" {
1626
value = module.slz_vpc.vpc_flow_logs
1727
description = "VPC flow logs collector"

main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ data "ibm_is_vpc" "vpc" {
122122
}
123123

124124
locals {
125-
vpc_id = var.create_vpc ? ibm_is_vpc.vpc[0].id : var.existing_vpc_id
125+
vpc_id = var.create_vpc ? ibm_is_vpc.vpc[0].id : var.existing_vpc_id
126+
vpc_data = var.create_vpc ? ibm_is_vpc.vpc[0] : data.ibm_is_vpc.vpc[0]
126127
}
127128

128129
# Configure custom resolver on the hub vpc

outputs.tf

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
output "vpc_name" {
66
description = "Name of VPC created"
7-
value = var.create_vpc == true ? ibm_is_vpc.vpc[0].name : data.ibm_is_vpc.vpc[0].name
7+
value = local.vpc_data.name
88
}
99

1010
output "vpc_id" {
@@ -14,7 +14,7 @@ output "vpc_id" {
1414

1515
output "vpc_crn" {
1616
description = "CRN of VPC created"
17-
value = var.create_vpc == true ? ibm_is_vpc.vpc[0].crn : data.ibm_is_vpc.vpc[0].crn
17+
value = local.vpc_data.crn
1818
}
1919

2020
##############################################################################
@@ -44,7 +44,7 @@ output "public_gateways" {
4444
output "subnet_ids" {
4545
description = "The IDs of the subnets"
4646
value = [
47-
for subnet in ibm_is_subnet.subnet :
47+
for subnet in local.subnets :
4848
subnet.id
4949
]
5050
}
@@ -53,11 +53,11 @@ output "subnet_detail_list" {
5353
description = "A list of subnets containing names, CIDR blocks, and zones."
5454
value = {
5555
for zone_name in distinct([
56-
for subnet in ibm_is_subnet.subnet :
56+
for subnet in local.subnets :
5757
subnet.zone
5858
]) :
5959
zone_name => {
60-
for subnet in ibm_is_subnet.subnet :
60+
for subnet in local.subnets :
6161
subnet.name => {
6262
id = subnet.id
6363
cidr = subnet.ipv4_cidr_block
@@ -70,7 +70,7 @@ output "subnet_detail_list" {
7070
output "subnet_zone_list" {
7171
description = "A list containing subnet IDs and subnet zones"
7272
value = [
73-
for subnet in ibm_is_subnet.subnet : {
73+
for subnet in local.subnets : {
7474
name = subnet.name
7575
id = subnet.id
7676
zone = subnet.zone
@@ -84,11 +84,11 @@ output "subnet_detail_map" {
8484
description = "A map of subnets containing IDs, CIDR blocks, and zones"
8585
value = {
8686
for zone_name in distinct([
87-
for subnet in ibm_is_subnet.subnet :
87+
for subnet in local.subnets :
8888
subnet.zone
8989
]) :
9090
"zone-${substr(zone_name, -1, length(zone_name))}" => [
91-
for subnet in ibm_is_subnet.subnet :
91+
for subnet in local.subnets :
9292
{
9393
id = subnet.id
9494
zone = subnet.zone
@@ -143,8 +143,8 @@ output "cidr_blocks" {
143143
}
144144

145145
output "vpc_data" {
146-
description = "Data of the VPC created."
147-
value = ibm_is_vpc.vpc
146+
description = "Data of the VPC used in this module, created or existing."
147+
value = local.vpc_data
148148
}
149149

150150
##############################################################################

0 commit comments

Comments
 (0)