Skip to content

Commit bc9c82e

Browse files
chore: leverage vpe module in example (#214)
1 parent b152965 commit bc9c82e

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

examples/complete/main.tf

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,36 @@ data "ibm_iam_account_settings" "iam_account_settings" {
3636
##############################################################################
3737
# VPC
3838
##############################################################################
39-
resource "ibm_is_vpc" "example_vpc" {
40-
name = "${var.prefix}-vpc"
41-
resource_group = module.resource_group.resource_group_id
42-
tags = var.resource_tags
39+
40+
module "vpc" {
41+
source = "terraform-ibm-modules/landing-zone-vpc/ibm"
42+
version = "7.3.1"
43+
resource_group_id = module.resource_group.resource_group_id
44+
region = var.region
45+
prefix = var.prefix
46+
name = "${var.prefix}-vpc"
47+
tags = var.resource_tags
48+
}
49+
50+
##############################################################################
51+
# Security group
52+
##############################################################################
53+
54+
resource "ibm_is_security_group" "sg1" {
55+
name = "${var.prefix}-sg1"
56+
vpc = module.vpc.vpc_id
4357
}
4458

45-
resource "ibm_is_subnet" "testacc_subnet" {
46-
name = "${var.prefix}-subnet"
47-
vpc = ibm_is_vpc.example_vpc.id
48-
zone = "${var.region}-1"
49-
total_ipv4_address_count = 256
50-
resource_group = module.resource_group.resource_group_id
59+
# wait 30 secs after security group is destroyed before destroying VPE to workaround race condition
60+
resource "time_sleep" "wait_30_seconds" {
61+
depends_on = [ibm_is_security_group.sg1]
62+
destroy_duration = "30s"
5163
}
5264

5365
##############################################################################
5466
# Create CBR Zone
5567
##############################################################################
68+
5669
module "cbr_zone" {
5770
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-zone-module"
5871
version = "1.12.0"
@@ -61,7 +74,7 @@ module "cbr_zone" {
6174
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
6275
addresses = [{
6376
type = "vpc", # to bind a specific vpc to the zone
64-
value = ibm_is_vpc.example_vpc.crn,
77+
value = module.vpc.vpc_crn,
6578
}]
6679
}
6780

@@ -116,32 +129,22 @@ resource "time_sleep" "wait_120_seconds" {
116129
# VPE
117130
##############################################################################
118131

119-
resource "ibm_is_security_group" "sg1" {
120-
name = "${var.prefix}-sg1"
121-
vpc = ibm_is_vpc.example_vpc.id
122-
}
123-
124-
resource "ibm_is_virtual_endpoint_gateway" "pgvpe" {
125-
name = "${var.prefix}-vpe-to-pg"
126-
target {
127-
crn = module.postgresql_db.crn
128-
resource_type = "provider_cloud_service"
129-
}
130-
vpc = ibm_is_vpc.example_vpc.id
131-
ips {
132-
subnet = ibm_is_subnet.testacc_subnet.id
133-
name = "${var.prefix}-pg-access-reserved-ip"
134-
}
135-
resource_group = module.resource_group.resource_group_id
136-
security_groups = [ibm_is_security_group.sg1.id]
132+
module "vpe" {
133+
source = "terraform-ibm-modules/vpe-module/ibm"
134+
version = "2.4.0"
135+
prefix = "vpe-to-pg"
136+
cloud_service_by_crn = [
137+
{
138+
name = "${var.prefix}-postgres"
139+
crn = module.postgresql_db.crn
140+
},
141+
]
142+
vpc_id = module.vpc.vpc_id
143+
subnet_zone_list = module.vpc.subnet_zone_list
144+
resource_group_id = module.resource_group.resource_group_id
145+
security_group_ids = [ibm_is_security_group.sg1.id]
137146
depends_on = [
138147
time_sleep.wait_120_seconds,
139148
time_sleep.wait_30_seconds
140149
]
141150
}
142-
143-
# wait 30 secs after security group is destroyed before destroying VPE to workaround race condition
144-
resource "time_sleep" "wait_30_seconds" {
145-
depends_on = [ibm_is_security_group.sg1]
146-
destroy_duration = "30s"
147-
}

0 commit comments

Comments
 (0)