Skip to content

Commit fd276e3

Browse files
authored
add support for multiple RPCs (#11)
* add support for multiple RPCs * OCA requirement
1 parent b3077f7 commit fd276e3

File tree

5 files changed

+33
-49
lines changed

5 files changed

+33
-49
lines changed

drg.tf

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,16 @@ resource "oci_core_drg_attachment" "vcns" {
4444
remove_export_drg_route_distribution_trigger = false # (Optional) (Updatable) boolean
4545
}
4646

47-
resource "oci_core_remote_peering_connection" "rpc" {
48-
47+
resource "oci_core_remote_peering_connection" "rpcs" {
48+
for_each = var.remote_peering_connections != null ? var.remote_peering_connections : {}
4949
compartment_id = var.compartment_id
5050
drg_id = var.drg_id == null ? oci_core_drg.drg[0].id : var.drg_id
51-
display_name = var.label_prefix == "none" ? "rpc_created_from_${var.drg_display_name}" : "${var.label_prefix}_rpc"
51+
display_name = var.label_prefix == "none" ? each.key : "${var.label_prefix}-${each.key}"
5252

5353
freeform_tags = var.freeform_tags
5454
defined_tags = var.defined_tags
5555

56-
57-
peer_id = var.rpc_acceptor_id
58-
peer_region_name = var.rpc_acceptor_region
59-
60-
count = var.create_rpc == true ? 1 : 0
56+
peer_id = can(each.value.rpc_acceptor_id) == false ? null : each.value.rpc_acceptor_id
57+
peer_region_name = can(each.value.rpc_acceptor_region) == false ? null : each.value.rpc_acceptor_region
6158

6259
}
63-

examples/rpc/main.tf

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ module "drg_acceptor" {
8585
drg_display_name = "drg-rpc-acceptor"
8686

8787
# rpc parameters
88-
create_rpc = true
88+
remote_peering_connections = { "rpc_acceptor" = {} }
8989

9090
providers = {
9191
oci = oci.acceptor
@@ -95,7 +95,7 @@ module "drg_acceptor" {
9595

9696
module "vcn_requestor" {
9797
# this module use the generic vcn module and configure it to act as rpc requestor vcn
98-
98+
9999
source = "github.com/oracle-terraform-modules/terraform-oci-vcn"
100100
# to use the terraform registry version comment the previous line and uncomment the 2 lines below
101101
# source = "oracle-terraform-modules/vcn/oci"
@@ -167,9 +167,12 @@ module "drg_requestor" {
167167
drg_display_name = "drg-rpc-requestor"
168168

169169
# rpc parameters
170-
create_rpc = true
171-
rpc_acceptor_id = module.drg_acceptor.rpc_id
172-
rpc_acceptor_region = var.region_acceptor
170+
remote_peering_connections = {
171+
"rpc_requestor" = {
172+
"rpc_acceptor_id" = module.drg_acceptor.rpc_all_attributes["rpc_acceptor"].id,
173+
"rpc_acceptor_region" = var.region_acceptor
174+
}
175+
}
173176

174177
providers = {
175178
oci = oci.requestor

outputs.tf

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,20 @@ output "drg_summary" {
3131
vcn_attachments = { for k, v in oci_core_drg_attachment.vcns : k => v.network_details[0].id }
3232

3333
}
34-
"rpc" = {
35-
display_name = join(",", oci_core_remote_peering_connection.rpc[*].display_name)
36-
rpc_id = join(",", oci_core_remote_peering_connection.rpc[*].id)
37-
}
3834
}
3935
}
4036

41-
42-
output "rpc_id" {
43-
description = "id of RPC if it is created"
44-
value = join(",", oci_core_remote_peering_connection.rpc[*].id)
45-
}
46-
47-
output "rpc_display_name" {
48-
description = "display name of RPC if it is created"
49-
value = join(",", oci_core_remote_peering_connection.rpc[*].display_name)
37+
# RPCS
38+
output "rpc_ids" {
39+
description = "IDs of created RPCs"
40+
value = values(oci_core_remote_peering_connection.rpcs)[*].id
5041
}
5142

5243
output "rpc_all_attributes" {
53-
description = "all attributes of created RPC"
54-
value = { for k, v in oci_core_remote_peering_connection.rpc : k => v }
44+
description = "all attributes of created RPCs"
45+
value = { for k, v in oci_core_remote_peering_connection.rpcs : k => v }
5546
}
5647

5748

5849

50+

terraform.tfvars.example

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ drg_vcn_attachments = null
3535

3636

3737
# rpc parameters
38-
39-
create_rpc = false
40-
rpc_acceptor_id = null
41-
rpc_acceptor_region = null
42-
38+
remote_peering_connections = null
39+
40+
#remote_peering_connections = {
41+
# "rpc1" : {}
42+
# "rpc2" : {
43+
# "rpc_acceptor_id" : "ocid1.remotepeeringconnection.oc1.aaaaaa" # <-- edit this OCID
44+
# "rpc_acceptor_region" : "us-ashburn-1" <-- replace the region
45+
# }
46+
#}
4347

variables.tf

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,12 @@ variable "drg_id" {
5757
}
5858

5959
# rpc parameters
60-
variable "create_rpc" {
61-
description = "Whether to create Remote Peering Connection. If set to true, creates an RPC"
62-
type = bool
63-
default = false
64-
}
65-
66-
variable "rpc_acceptor_id" {
67-
description = "the ID of the remote RPC"
68-
type = string
69-
default = null
70-
}
71-
variable "rpc_acceptor_region" {
72-
# List of regions: https://docs.cloud.oracle.com/iaas/Content/General/Concepts/regions.htm#ServiceAvailabilityAcrossRegions
73-
description = "the OCI region where the Remote Peering Connection will be established with"
74-
type = string
60+
variable "remote_peering_connections" {
61+
description = "List of parameters to add and optionally peer remote peering connections"
62+
type = map(any)
7563
default = null
7664
}
7765

7866

7967

68+

0 commit comments

Comments
 (0)