Skip to content

Commit 500d174

Browse files
jojustinshemau
andauthored
fix: adding VPE to access postgresql (#50)
* fix: adding vsi to access postgresql * fix: adding vpe to access pg * fix: update version for cbr * fix: update version for cbr * fix: update version for cbr * fix: adding VPE to access postgresql * tests: tests without VPE * tests: tests without VPE * feat: add VPE support * feat: add VPE support * fix: precommit fix * tests: fix test * fix: review comments * fix: review comments * fix: timeout before VPE creation * fix: timeout before VPE creation --------- Co-authored-by: shemau <shemau@gmail.com>
1 parent 4cc3239 commit 500d174

File tree

6 files changed

+81
-3
lines changed

6 files changed

+81
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ You need the following permissions to run this module.
9191

9292
| Name | Description |
9393
|------|-------------|
94+
| <a name="output_cbr_rule_ids"></a> [cbr\_rule\_ids](#output\_cbr\_rule\_ids) | CBR rule ids created to restrict Postgresql |
95+
| <a name="output_crn"></a> [crn](#output\_crn) | Postgresql instance crn |
9496
| <a name="output_guid"></a> [guid](#output\_guid) | Postgresql instance guid |
9597
| <a name="output_id"></a> [id](#output\_id) | Postgresql instance id |
9698
| <a name="output_service_credentials_json"></a> [service\_credentials\_json](#output\_service\_credentials\_json) | Service credentials json map |

examples/complete/main.tf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,36 @@ module "postgresql_db" {
104104
}
105105
]
106106
}
107+
108+
# VPE provisioning should wait for the database provisioning
109+
resource "time_sleep" "wait_120_seconds" {
110+
depends_on = [module.postgresql_db]
111+
create_duration = "120s"
112+
}
113+
114+
##############################################################################
115+
# VPE
116+
##############################################################################
117+
118+
resource "ibm_is_security_group" "sg1" {
119+
name = "${var.prefix}-sg1"
120+
vpc = ibm_is_vpc.example_vpc.id
121+
}
122+
123+
resource "ibm_is_virtual_endpoint_gateway" "pgvpe" {
124+
name = "${var.prefix}-vpe-to-pg"
125+
target {
126+
crn = module.postgresql_db.crn
127+
resource_type = "provider_cloud_service"
128+
}
129+
vpc = ibm_is_vpc.example_vpc.id
130+
ips {
131+
subnet = ibm_is_subnet.testacc_subnet.id
132+
name = "${var.prefix}-pg-access-reserved-ip"
133+
}
134+
resource_group = module.resource_group.resource_group_id
135+
security_groups = [ibm_is_security_group.sg1.id]
136+
depends_on = [
137+
time_sleep.wait_120_seconds
138+
]
139+
}

examples/complete/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ output "id" {
66
value = module.postgresql_db.id
77
}
88

9+
output "guid" {
10+
description = "Postgresql instance guid"
11+
value = module.postgresql_db.guid
12+
}
13+
914
output "version" {
1015
description = "Postgresql instance version"
1116
value = module.postgresql_db.version
@@ -22,3 +27,8 @@ output "service_credentials_object" {
2227
value = module.postgresql_db.service_credentials_object
2328
sensitive = true
2429
}
30+
31+
output "cbr_rule_ids" {
32+
description = "CBR rule ids created to restrict Postgresql"
33+
value = module.postgresql_db.cbr_rule_ids
34+
}

examples/complete/version.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ terraform {
66
source = "IBM-Cloud/ibm"
77
version = "1.49.0"
88
}
9+
time = {
10+
source = "hashicorp/time"
11+
version = ">= 0.8.0"
12+
}
913
}
1014
}

module-metadata.json

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,24 @@
248248
}
249249
},
250250
"outputs": {
251+
"cbr_rule_ids": {
252+
"name": "cbr_rule_ids",
253+
"description": "CBR rule ids created to restrict Postgresql",
254+
"pos": {
255+
"filename": "outputs.tf",
256+
"line": 38
257+
}
258+
},
259+
"crn": {
260+
"name": "crn",
261+
"description": "Postgresql instance crn",
262+
"value": "ibm_database.postgresql_db.resource_crn",
263+
"pos": {
264+
"filename": "outputs.tf",
265+
"line": 15
266+
},
267+
"type": "TypeString"
268+
},
251269
"guid": {
252270
"name": "guid",
253271
"description": "Postgresql instance guid",
@@ -274,7 +292,7 @@
274292
"sensitive": true,
275293
"pos": {
276294
"filename": "outputs.tf",
277-
"line": 20
295+
"line": 25
278296
}
279297
},
280298
"service_credentials_object": {
@@ -284,7 +302,7 @@
284302
"sensitive": true,
285303
"pos": {
286304
"filename": "outputs.tf",
287-
"line": 26
305+
"line": 31
288306
}
289307
},
290308
"version": {
@@ -293,7 +311,7 @@
293311
"value": "ibm_database.postgresql_db.version",
294312
"pos": {
295313
"filename": "outputs.tf",
296-
"line": 15
314+
"line": 20
297315
},
298316
"type": "TypeString"
299317
}

outputs.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ output "guid" {
1212
value = ibm_database.postgresql_db.guid
1313
}
1414

15+
output "crn" {
16+
description = "Postgresql instance crn"
17+
value = ibm_database.postgresql_db.resource_crn
18+
}
19+
1520
output "version" {
1621
description = "Postgresql instance version"
1722
value = ibm_database.postgresql_db.version
@@ -28,3 +33,9 @@ output "service_credentials_object" {
2833
value = local.service_credentials_object
2934
sensitive = true
3035
}
36+
37+
38+
output "cbr_rule_ids" {
39+
description = "CBR rule ids created to restrict Postgresql"
40+
value = module.cbr_rule[*].rule_id
41+
}

0 commit comments

Comments
 (0)