Skip to content

Commit e2e5528

Browse files
committed
adding localGatewayPeering resource to enable VCN Local Peering
1 parent 88d8588 commit e2e5528

File tree

14 files changed

+1473
-3
lines changed

14 files changed

+1473
-3
lines changed

crud/helpers.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,7 @@ func UpdateResource(d *schema.ResourceData, sync ResourceUpdater) (e error) {
301301
func DeleteResource(d *schema.ResourceData, sync ResourceDeleter) (e error) {
302302
if e = sync.Delete(); e != nil {
303303
handleMissingResourceError(sync, &e)
304-
if e != nil {
305-
return
306-
}
304+
return
307305
}
308306

309307
//d.SetId(sync.ID())
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# oci_core_local_peering_gateway
2+
3+
## LocalPeeringGateway Resource
4+
5+
### LocalPeeringGateway Reference
6+
7+
The following attributes are exported:
8+
9+
* `compartment_id` - The OCID of the compartment containing the Local Peering Gateway (LPG).
10+
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
11+
* `id` - The LPG's Oracle ID (OCID).
12+
* `is_cross_tenancy_peering` - Whether the VCN at the other end of the peering is in a different tenancy. Cross tenancy local peering will be enabled when identity enables cross-tenancy authorization policies. Example: `false`
13+
* `peer_advertised_cidr` - The range of IP addresses available on the VCN at the other end of the peering from this LPG. The value is `null` if the LPG is not peered. You can use this as the destination CIDR for a route rule to route a subnet's traffic to this LPG. Example: `192.168.0.0/16`
14+
* `peering_status` - Whether the LPG is peered with another LPG. `NEW` means the LPG has not yet been peered. `PENDING` means the peering is being established. `REVOKED` means the LPG at the other end of the peering has been deleted.
15+
* `peering_status_details` - Additional information regarding the peering status, if applicable.
16+
* `state` - The LPG's current lifecycle state.
17+
* `time_created` - The date and time the LPG was created, in the format defined by RFC3339. Example: `2016-08-25T21:10:29.600Z`
18+
* `vcn_id` - The OCID of the VCN the LPG belongs to.
19+
20+
21+
22+
### Create Operation
23+
Creates a new local peering gateway (LPG) for the specified VCN.
24+
25+
* Specifying a peer_id creates a connection to the specified LPG ID.
26+
* If the specified peer_id is also a resource in the terraform config you will have do a `terraform refresh` after the `terraform apply` in order to get the latest connection information on that resource.
27+
* To disconnect the peering connection at least one of the LPG resources in the connection will have to be destroyed, however in terraform we recommend that when one LPG is destroyed the peer should also be destroyed. If one of them is not destroyed it will have a `REVOKED` peering_status. If another LPG resource tries to connect to this LPG resource it will get a `400 Error: The Local Peering Gateway with ID X has already been connected`. To solve this you will have to run `terraform taint oci_core_local_peering_gateway.test_local_peering_gateway` on that resource or target delete it `terraform destroy -target="oci_core_local_peering_gateway.test_local_peering_gateway"`.
28+
29+
30+
The following arguments are supported:
31+
32+
* `compartment_id` - (Required) The OCID of the compartment containing the local peering gateway (LPG).
33+
* `display_name` - (Optional) A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
34+
* `peer_id` - (Optional) The OCID of the LPG you want to peer with. Specifying a peer_id connects this local peering gateway (LPG) to another one in the same region. This operation must be called by the VCN administrator who is designated as the *requestor* in the peering relationship. The *acceptor* must implement an Identity and Access Management (IAM) policy that gives the requestor permission to connect to LPGs in the acceptor's compartment. Without that permission, this operation will fail. For more information, see [VCN Peering](https://docs.us-phoenix-1.oraclecloud.com/Content/Network/Tasks/VCNpeering.htm).
35+
* `vcn_id` - (Required) The OCID of the VCN the LPG belongs to.
36+
37+
38+
### Update Operation
39+
Updates the specified local peering gateway (LPG).
40+
41+
42+
The following arguments support updates:
43+
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
44+
45+
46+
** IMPORTANT **
47+
Any change to a property that does not support update will force the destruction and recreation of the resource with the new property values
48+
49+
### Example Usage
50+
51+
```
52+
resource "oci_core_local_peering_gateway" "test_local_peering_gateway" {
53+
#Required
54+
compartment_id = "${var.compartment_id}"
55+
vcn_id = "${oci_core_vcn.test_vcn.id}"
56+
57+
#Optional
58+
display_name = "${var.local_peering_gateway_display_name}"
59+
peer_id = "${oci_core_local_peering_gateway.test_local_peering_gateway2}"
60+
}
61+
```
62+
63+
# oci_core_local_peering_gateways
64+
65+
## LocalPeeringGateway DataSource
66+
67+
Gets a list of local_peering_gateways.
68+
69+
### List Operation
70+
Lists the local peering gateways (LPGs) for the specified VCN and compartment
71+
(the LPG's compartment).
72+
73+
The following arguments are supported:
74+
75+
* `compartment_id` - (Required) The OCID of the compartment.
76+
* `vcn_id` - (Required) The OCID of the VCN.
77+
78+
79+
The following attributes are exported:
80+
81+
* `local_peering_gateways` - The list of local_peering_gateways.
82+
83+
### Example Usage
84+
85+
```
86+
data "oci_core_local_peering_gateways" "test_local_peering_gateways" {
87+
#Required
88+
compartment_id = "${var.compartment_id}"
89+
vcn_id = "${oci_core_vcn.test_vcn.id}"
90+
91+
#Optional
92+
}
93+
```
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
variable "tenancy_ocid" {}
2+
variable "user_ocid" {}
3+
variable "fingerprint" {}
4+
variable "private_key_path" {}
5+
variable "compartment_ocid" {}
6+
variable "region" {}
7+
8+
provider "oci" {
9+
tenancy_ocid = "${var.tenancy_ocid}"
10+
user_ocid = "${var.user_ocid}"
11+
fingerprint = "${var.fingerprint}"
12+
private_key_path = "${var.private_key_path}"
13+
region = "${var.region}"
14+
}
15+
16+
resource "oci_core_vcn" "vcn1" {
17+
cidr_block = "10.0.1.0/24"
18+
dns_label = "vcn1"
19+
compartment_id = "${var.compartment_ocid}"
20+
display_name = "vcn1"
21+
}
22+
23+
resource "oci_core_vcn" "vcn2" {
24+
cidr_block = "10.0.2.0/24"
25+
dns_label = "vcn2"
26+
compartment_id = "${var.compartment_ocid}"
27+
display_name = "vcn2"
28+
}
29+
30+
resource "oci_core_vcn" "vcn3" {
31+
cidr_block = "10.0.3.0/24"
32+
dns_label = "vcn3"
33+
compartment_id = "${var.compartment_ocid}"
34+
display_name = "vcn3"
35+
}
36+
37+
# Peer vcn1 and vcn2 to vcn3. You need one peering gateway on each VCN per peering connection.
38+
39+
resource "oci_core_local_peering_gateway" "test_local_peering_gateway_1" {
40+
#Required
41+
compartment_id = "${var.compartment_ocid}"
42+
vcn_id = "${oci_core_vcn.vcn1.id}"
43+
44+
#Optional
45+
display_name = "localPeeringGateway1"
46+
peer_id = "${oci_core_local_peering_gateway.test_local_peering_gateway_3_A.id}"
47+
}
48+
49+
resource "oci_core_local_peering_gateway" "test_local_peering_gateway_2" {
50+
#Required
51+
compartment_id = "${var.compartment_ocid}"
52+
vcn_id = "${oci_core_vcn.vcn2.id}"
53+
54+
#Optional
55+
display_name = "localPeeringGateway2"
56+
peer_id = "${oci_core_local_peering_gateway.test_local_peering_gateway_3_B.id}"
57+
}
58+
59+
resource "oci_core_local_peering_gateway" "test_local_peering_gateway_3_A" {
60+
#Required
61+
compartment_id = "${var.compartment_ocid}"
62+
vcn_id = "${oci_core_vcn.vcn3.id}"
63+
64+
#Optional
65+
display_name = "localPeeringGateway3A"
66+
}
67+
68+
resource "oci_core_local_peering_gateway" "test_local_peering_gateway_3_B" {
69+
#Required
70+
compartment_id = "${var.compartment_ocid}"
71+
vcn_id = "${oci_core_vcn.vcn3.id}"
72+
73+
#Optional
74+
display_name = "localPeeringGateway3B"
75+
}
76+
77+
data "oci_core_local_peering_gateways" "test_local_peering_gateways" {
78+
#Required
79+
compartment_id = "${var.compartment_ocid}"
80+
vcn_id = "${oci_core_vcn.vcn3.id}"
81+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Local VCN Peering Example
2+
3+
This example demonstrates how to do a VCN local peering connection using Local Peering Gateway (LPG) resources when you have different administrators of the VCNs in the connection.
4+
5+
** IMPORTANT **
6+
You would not want to use this example the way it is written as it uses multiple users. This example is there to demonstrate the workflow of establishing a local peering connection when the 2 VCNs are administered by different users.
7+
8+
This example creates policies so it should be run in the home region.
9+
10+
One of the users will have the `requestor` LPG that will request a local peering connection to the `acceptor` LPG that is managed by a different user. See [Local VCN Peering](https://docs.us-phoenix-1.oraclecloud.com/Content/Network/Tasks/localVCNpeering.htm) for more details.
11+
12+
* policies.tf show the policies that are needed for each of the users.
13+
* requestor.tf shows what the requestor config would look like, including the LPG, the Route Table and the Security List.
14+
* acceptor.tf shows what the acceptor config would look like, including the LPG, the Route Table and the Security List.
15+
16+
An instance is created on the requestor side and the acceptor side so that you can test the connection.
17+
You can SSH to one of the instances using its public IP and try to PING from there the other instance using its Private IP.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
variable "user_acceptor" {}
2+
variable "compartment_ocid_acceptor" {}
3+
variable "compartment_name_acceptor" {}
4+
variable "fingerprint_acceptor" {}
5+
variable "private_key_path_acceptor" {}
6+
7+
variable "acceptor_cidr" {
8+
default = "10.1.0.0/16"
9+
}
10+
11+
provider "oci" {
12+
alias = "acceptor"
13+
region = "${var.region}"
14+
tenancy_ocid = "${var.tenancy_ocid}"
15+
user_ocid = "${var.user_acceptor}"
16+
fingerprint = "${var.fingerprint_acceptor}"
17+
private_key_path = "${var.private_key_path_acceptor}"
18+
}
19+
20+
resource "oci_core_vcn" "vcn2" {
21+
depends_on = ["oci_identity_policy.acceptor_policy", "oci_identity_user_group_membership.acceptor_user_group_membership"]
22+
provider = "oci.acceptor"
23+
display_name = "vcn2"
24+
dns_label = "vcn2"
25+
cidr_block = "${var.acceptor_cidr}"
26+
compartment_id = "${var.compartment_ocid_acceptor}"
27+
}
28+
29+
resource "oci_core_local_peering_gateway" "acceptor" {
30+
depends_on = ["oci_identity_policy.acceptor_policy", "oci_identity_user_group_membership.acceptor_user_group_membership"]
31+
provider = "oci.acceptor"
32+
compartment_id = "${var.compartment_ocid_acceptor}"
33+
vcn_id = "${oci_core_vcn.vcn2.id}"
34+
display_name = "localPeeringGateway2"
35+
}
36+
37+
resource "oci_core_internet_gateway" "acceptorIG" {
38+
depends_on = ["oci_identity_policy.acceptor_policy", "oci_identity_user_group_membership.acceptor_user_group_membership"]
39+
provider = "oci.acceptor"
40+
compartment_id = "${var.compartment_ocid_acceptor}"
41+
display_name = "acceptorIG"
42+
vcn_id = "${oci_core_vcn.vcn2.id}"
43+
}
44+
45+
resource "oci_core_route_table" "acceptor_route_table" {
46+
depends_on = ["oci_identity_policy.acceptor_policy", "oci_identity_user_group_membership.acceptor_user_group_membership"]
47+
provider = "oci.acceptor"
48+
compartment_id = "${var.compartment_ocid_acceptor}"
49+
vcn_id = "${oci_core_vcn.vcn2.id}"
50+
display_name = "acceptorRouteTable"
51+
route_rules {
52+
cidr_block = "${var.requestor_cidr}"
53+
network_entity_id = "${oci_core_local_peering_gateway.acceptor.id}"
54+
}
55+
route_rules {
56+
cidr_block = "0.0.0.0/0"
57+
network_entity_id = "${oci_core_internet_gateway.acceptorIG.id}"
58+
}
59+
}
60+
61+
resource "oci_core_security_list" "acceptor_security_list" {
62+
depends_on = ["oci_identity_policy.acceptor_policy", "oci_identity_user_group_membership.acceptor_user_group_membership"]
63+
provider = "oci.acceptor"
64+
compartment_id = "${var.compartment_ocid_acceptor}"
65+
vcn_id = "${oci_core_vcn.vcn2.id}"
66+
display_name = "AcceptorSecurityList"
67+
68+
egress_security_rules {
69+
destination = "${var.requestor_cidr}"
70+
protocol = "all"
71+
}
72+
73+
ingress_security_rules {
74+
protocol = "all"
75+
source = "${var.requestor_cidr}"
76+
}
77+
78+
ingress_security_rules {
79+
protocol = "${var.tcp_protocol}"
80+
source = "0.0.0.0/0"
81+
tcp_options {
82+
max = "${var.ssh_port}"
83+
min = "${var.ssh_port}"
84+
}
85+
}
86+
}
87+
88+
resource "oci_core_subnet" "acceptor_subnet" {
89+
depends_on = ["oci_identity_policy.acceptor_policy", "oci_identity_user_group_membership.acceptor_user_group_membership"]
90+
provider = "oci.acceptor"
91+
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[0],"name")}"
92+
cidr_block = "${cidrsubnet("${var.acceptor_cidr}", 4, 0)}"
93+
display_name = "AcceptorSubnet"
94+
dns_label = "acceptorsubnet"
95+
compartment_id = "${var.compartment_ocid_acceptor}"
96+
vcn_id = "${oci_core_vcn.vcn2.id}"
97+
security_list_ids = ["${oci_core_security_list.acceptor_security_list.id}"]
98+
route_table_id = "${oci_core_route_table.acceptor_route_table.id}"
99+
dhcp_options_id = "${oci_core_vcn.vcn2.default_dhcp_options_id}"
100+
}
101+
102+
resource "oci_core_instance" "acceptor_instance" {
103+
depends_on = ["oci_identity_policy.acceptor_policy", "oci_identity_user_group_membership.acceptor_user_group_membership"]
104+
provider = "oci.acceptor"
105+
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[0],"name")}"
106+
compartment_id = "${var.compartment_ocid_acceptor}"
107+
display_name = "acceptorInstance"
108+
image = "${var.InstanceImageOCID[var.region]}"
109+
shape = "${var.InstanceShape}"
110+
111+
create_vnic_details {
112+
subnet_id = "${oci_core_subnet.acceptor_subnet.id}"
113+
display_name = "primaryvnic"
114+
assign_public_ip = true
115+
hostname_label = "acceptorinstance"
116+
},
117+
118+
metadata {
119+
ssh_authorized_keys = "${var.ssh_public_key}"
120+
}
121+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
variable "ssh_public_key" {}
2+
3+
variable "InstanceShape" {
4+
default = "VM.Standard1.2"
5+
}
6+
7+
variable "InstanceImageOCID" {
8+
type = "map"
9+
default = {
10+
// See https://docs.us-phoenix-1.oraclecloud.com/Content/Resources/Assets/OracleProvidedImageOCIDs.pdf
11+
// Oracle-provided image "Oracle-Linux-7.4-2018.02.21-1"
12+
us-phoenix-1 = "ocid1.image.oc1.phx.aaaaaaaaupbfz5f5hdvejulmalhyb6goieolullgkpumorbvxlwkaowglslq"
13+
us-ashburn-1 = "ocid1.image.oc1.iad.aaaaaaaajlw3xfie2t5t52uegyhiq2npx7bqyu4uvi2zyu3w3mqayc2bxmaa"
14+
eu-frankfurt-1 = "ocid1.image.oc1.eu-frankfurt1.aaaaaaaa7d3fsb6272srnftyi4dphdgfjf6gurxqhmv6ileds7ba3m2gltxq"
15+
uk-london-1 = "ocid1.image.oc1.uk-london1.aaaaaaaaa6h6gj6v4n56mqrbgnosskq63blyv2752g36zerymy63cfkojiiq"
16+
}
17+
}
18+
19+
variable "tcp_protocol" {
20+
default = "6"
21+
}
22+
23+
variable "ssh_port" {
24+
default = "22"
25+
}
26+
27+
data "oci_identity_availability_domains" "ADs" {
28+
provider = "oci.admin"
29+
compartment_id = "${var.tenancy_ocid}"
30+
}
31+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# You can test the peering connection by ssh-ing into an instance (using the public_ip) and doing a ping command to the private IP address of the other instance"]
2+
3+
output "requestorInstancePublicIP" {
4+
value = ["${oci_core_instance.requestor_instance.public_ip}"]
5+
}
6+
7+
output "requestorInstancePrivateIP" {
8+
value = ["${oci_core_instance.requestor_instance.private_ip}"]
9+
}
10+
11+
output "acceptorInstancePublicIP" {
12+
value = ["${oci_core_instance.acceptor_instance.public_ip}"]
13+
}
14+
15+
output "acceptorInstancePrivateIP" {
16+
value = ["${oci_core_instance.acceptor_instance.private_ip}"]
17+
}
18+

0 commit comments

Comments
 (0)