Skip to content

Commit 069d418

Browse files
authored
fix: added fix to ensure vpc_data is always output after initial apply (#781)
1 parent 75ce6e9 commit 069d418

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ To attach access management tags to resources in this module, you need the follo
133133
| [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 |
134134
| [ibm_resource_instance.dns_instance_hub](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_instance) | resource |
135135
| [time_sleep.wait_for_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
136+
| [time_sleep.wait_for_vpc_creation_data](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
136137
| [ibm_iam_account_settings.iam_account_settings](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/iam_account_settings) | data source |
137138
| [ibm_is_subnet.subnet](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/is_subnet) | data source |
138139
| [ibm_is_vpc.vpc](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/is_vpc) | data source |

default_security_group.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ locals {
1212

1313
resource "ibm_is_security_group_rule" "default_vpc_rule" {
1414
for_each = local.security_group_rule_object
15-
group = var.create_vpc == true ? ibm_is_vpc.vpc[0].default_security_group : data.ibm_is_vpc.vpc[0].default_security_group
15+
group = var.create_vpc == true ? ibm_is_vpc.vpc[0].default_security_group : data.ibm_is_vpc.vpc.default_security_group
1616
direction = each.value.direction
1717
remote = each.value.remote
1818

examples/default/outputs.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ output "vpc_crn" {
1313
}
1414

1515
output "vpc_name" {
16-
value = module.slz_vpc.vpc_data.name
16+
value = module.slz_vpc.vpc_name
1717
description = "VPC name property taken from the larger data element"
1818
}
1919

20+
output "vpc_data" {
21+
value = module.slz_vpc.vpc_data
22+
description = "Data of the VPC used in this module, created or existing."
23+
}
24+
2025
output "subnet_ids" {
2126
value = module.slz_vpc.subnet_ids
2227
description = "list of VPC subnet ids created"

main.tf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,24 @@ locals {
4747
##############################################################################
4848

4949
data "ibm_is_vpc" "vpc" {
50-
count = var.create_vpc == false ? 1 : 0
51-
identifier = var.existing_vpc_id
50+
depends_on = [time_sleep.wait_for_vpc_creation_data]
51+
identifier = local.vpc_id
5252
}
5353

5454
locals {
55-
vpc_id = var.create_vpc ? ibm_is_vpc.vpc[0].id : var.existing_vpc_id
56-
vpc_data = var.create_vpc ? ibm_is_vpc.vpc[0] : data.ibm_is_vpc.vpc[0]
55+
vpc_id = var.create_vpc ? resource.ibm_is_vpc.vpc[0].id : var.existing_vpc_id
5756
}
5857

5958
##############################################################################
6059
# Create new VPC
6160
##############################################################################
6261

62+
resource "time_sleep" "wait_for_vpc_creation_data" {
63+
depends_on = [resource.ibm_is_vpc.vpc, resource.ibm_is_subnet.subnet]
64+
count = var.create_vpc == true || var.create_subnets ? 1 : 0
65+
create_duration = "30s"
66+
}
67+
6368
resource "ibm_is_vpc" "vpc" {
6469
count = var.create_vpc == true ? 1 : 0
6570
name = var.prefix != null ? "${var.prefix}-${var.name}-vpc" : var.name

outputs.tf

Lines changed: 4 additions & 3 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 = local.vpc_data.name
7+
value = data.ibm_is_vpc.vpc.resource_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 = local.vpc_data.crn
17+
value = data.ibm_is_vpc.vpc.crn
1818
}
1919

2020
##############################################################################
@@ -137,14 +137,15 @@ output "vpc_flow_logs" {
137137
}
138138

139139
##############################################################################
140+
140141
output "cidr_blocks" {
141142
description = "List of CIDR blocks present in VPC stack"
142143
value = [for address in data.ibm_is_vpc_address_prefixes.get_address_prefixes.address_prefixes : address.cidr]
143144
}
144145

145146
output "vpc_data" {
146147
description = "Data of the VPC used in this module, created or existing."
147-
value = local.vpc_data
148+
value = data.ibm_is_vpc.vpc
148149
}
149150

150151
##############################################################################

tests/pr_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ func TestRunDefaultExample(t *testing.T) {
6464
output, err := options.RunTestConsistency()
6565
assert.Nil(t, err, "This should not have errored")
6666
assert.NotNil(t, output, "Expected some output")
67+
68+
expectedOutputs := []string{"vpc_data"}
69+
missingOutputs, outputErr := testhelper.ValidateTerraformOutputs(options.LastTestTerraformOutputs, expectedOutputs...)
70+
assert.Empty(t, outputErr, fmt.Sprintf("Missing expected outputs: %s", missingOutputs))
6771
}
6872

6973
func TestRunNoPrefixExample(t *testing.T) {

0 commit comments

Comments
 (0)