Skip to content

Commit ae6efe1

Browse files
committed
chore: first commit
Reviewed-by: Avi Miller <[email protected]> Signed-off-by: Ali Mukadam <[email protected]>
0 parents  commit ae6efe1

21 files changed

+823
-0
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Local .terraform directories
2+
**/.terraform/*
3+
4+
provider.tf
5+
6+
# .tfstate files
7+
*.tfstate
8+
*.tfstate.*
9+
10+
# .tfvars files
11+
*.tfvars
12+
13+
# visual code
14+
**/.vscode/*
15+
16+
.terraform.lock.hcl

CHANGELOG.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
= CHANGELOG
2+
:idprefix:
3+
:idseparator: *
4+
5+
:uri-changelog: http://keepachangelog.com/
6+
All notable changes to this project are documented in this file.
7+
8+
The format is based on {uri-changelog}[Keep a Changelog].

CONTRIBUTING.adoc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
= CONTRIBUTING
2+
3+
:uri-oracle-oca: https://oca.opensource.oracle.com
4+
5+
Oracle welcomes contributions to this repository from anyone.
6+
7+
If you want to submit a pull request to fix a bug or enhance an existing
8+
feature, please first open an issue and link to that issue when you
9+
submit your pull request.
10+
11+
If you have any questions about a possible submission, feel free to open
12+
an issue too.
13+
14+
== Contributing to the terraform-oci-wireguard repository
15+
16+
Pull requests can be made under
17+
{uri-oracle-oca}[The Oracle Contributor Agreement](OCA).
18+
19+
For pull requests to be accepted, the bottom of your commit message must have
20+
the following line using your name and e-mail address as it appears in the
21+
OCA Signatories list.
22+
23+
----
24+
Signed-off-by: Your Name <[email protected]>
25+
----
26+
27+
This can be automatically added to pull requests by committing with:
28+
29+
----
30+
git commit --signoff
31+
----
32+
33+
Only pull requests from committers that can be verified as having
34+
signed the OCA can be accepted.
35+
36+
=== Pull request process
37+
38+
. Fork this repository
39+
. Create a branch in your fork to implement the changes. We recommend using
40+
the issue number as part of your branch name, e.g. `1234-fixes`
41+
. Ensure that any documentation is updated with the changes that are required
42+
by your fix.
43+
. Ensure that any samples are updated if the base image has been changed.
44+
. Submit the pull request. *Do not leave the pull request blank*. Explain exactly
45+
what your changes are meant to do and provide simple steps on how to validate
46+
your changes. Ensure that you reference the issue you created as well.
47+
We will assign the pull request to 2-3 people for review before it is merged.

CONTRIBUTORS.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
== GitHub userids of contributors
2+
3+
OWNERS # have admin access and can merge code to main:
4+
5+
- @hyder

LICENSE.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2022 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Terraform module for WireGuard on OCI
2+
3+
[uri-docs]: https://github.com/oracle-terraform-modules/terraform-oci-wireguard/blob/main/docs
4+
[uri-oci]: https://cloud.oracle.com/cloud-infrastructure
5+
[uri-prereqs]: https://github.com/oracle-terraform-modules/terraform-oci-wireguard/blob/main/docs/prerequisites.adoc
6+
[uri-quickstart]: https://github.com/oracle-terraform-modules/terraform-oci-wireguard/blob/main/docs/quickstart.adoc
7+
[uri-wireguard]: https://www.wireguard.com/
8+
9+
From [wireguard.com][uri-wireguard]:
10+
11+
_WireGuard &reg; is an extremely simple yet fast and modern VPN that utilizes state-of-the-art cryptography. WireGuard is designed as a general purpose VPN for running on embedded interfaces and super computers alike, fit for many different circumstances._
12+
13+
This Terraform module automates the deployment of a WireGuard VPN endpoint instance on [Oracle Cloud Infrastructure][uri-oci]. It can be used to enable secure connectivity to private subnets without needing a bastion host or using the Bastion service.
14+
15+
## [Documentation][uri-docs]
16+
17+
* [Prerequisites][uri-prereqs]
18+
19+
* [Quick Start][uri-quickstart]
20+
21+
## License
22+
23+
The content in this repository is copyright (c) 2022, Oracle and/or its affiliates. It is released under the Universal Permissive License v1.0 as shown at <https://oss.oracle.com/licenses/upl>.
24+
25+
"WireGuard" and the "WireGuard" logo are registered trademarks of Jason A. Donenfeld.

cloudinit/wireguard.template.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#cloud-config
2+
package_upgrade: ${upgrade_wireguard}
3+
timezone: ${wireguard_timezone}
4+
packages:
5+
- wireguard-tools
6+
write_files:
7+
- path: "/root/wireguard/wireguard.sh"
8+
permissions: "0700"
9+
encoding: "gzip+base64"
10+
content: |
11+
${wireguard_setup}
12+
- path: "/root/wireguard/wg0.conf"
13+
permissions: "0700"
14+
encoding: "gzip+base64"
15+
content: |
16+
${wireguard_conf}
17+
runcmd:
18+
- bash /root/wireguard/wireguard.sh
19+
- touch /home/opc/wireguard.finish

compute.tf

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
resource "oci_core_instance" "wireguard" {
2+
availability_domain = data.oci_identity_availability_domain.ad.name
3+
compartment_id = var.compartment_id
4+
5+
agent_config {
6+
7+
are_all_plugins_disabled = true
8+
is_management_disabled = true
9+
is_monitoring_disabled = true
10+
11+
12+
}
13+
14+
create_vnic_details {
15+
assign_public_ip = var.wireguard_type == "public" ? true : false
16+
display_name = var.label_prefix == "none" ? "wireguard-vnic" : "${var.label_prefix}-wireguard-vnic"
17+
hostname_label = "wireguard"
18+
subnet_id = oci_core_subnet.wireguard.id
19+
}
20+
21+
display_name = var.label_prefix == "none" ? "wireguard" : "${var.label_prefix}-wireguard"
22+
23+
launch_options {
24+
boot_volume_type = "PARAVIRTUALIZED"
25+
network_type = "PARAVIRTUALIZED"
26+
}
27+
28+
# prevent the wireguard from destroying and recreating itself if the image ocid changes
29+
lifecycle {
30+
ignore_changes = [source_details[0].source_id]
31+
}
32+
33+
metadata = {
34+
ssh_authorized_keys = (var.ssh_public_key != "") ? var.ssh_public_key : (var.ssh_public_key_path != "none") ? file(var.ssh_public_key_path) : ""
35+
user_data = data.cloudinit_config.wireguard.rendered
36+
}
37+
38+
shape = lookup(var.wireguard_shape, "shape", "VM.Standard.E2.2")
39+
40+
dynamic "shape_config" {
41+
for_each = length(regexall("Flex", lookup(var.wireguard_shape, "shape", "VM.Standard.E3.Flex"))) > 0 ? [1] : []
42+
content {
43+
ocpus = max(1, lookup(var.wireguard_shape, "ocpus", 1))
44+
memory_in_gbs = (lookup(var.wireguard_shape, "memory", 4) / lookup(var.wireguard_shape, "ocpus", 1)) > 64 ? (lookup(var.wireguard_shape, "ocpus", 1) * 4) : lookup(var.wireguard_shape, "memory", 4)
45+
}
46+
}
47+
48+
source_details {
49+
boot_volume_size_in_gbs = lookup(var.wireguard_shape, "boot_volume_size", 50)
50+
source_type = "image"
51+
source_id = local.wireguard_image_id
52+
}
53+
54+
state = var.wireguard_state
55+
56+
timeouts {
57+
create = "60m"
58+
}
59+
60+
}

conf/wg.template.conf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Interface]
2+
Address = 192.168.2.1/24
3+
SaveConfig = true
4+
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o ens3 -j MASQUERADE
5+
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o ens3 -j MASQUERADE
6+
ListenPort = 51820
7+
PrivateKey = SERVER_PRIVATE_KEY
8+
9+
# [Peer]
10+
# PublicKey = CLIENT_PUBLIC_KEY
11+
# AllowedIPs = 192.168.2.2/32
12+
# Endpoint = CLIENT_PUBLIC_IP:60477

datasources.tf

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright 2019, 2021 Oracle Corporation and/or affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
data "oci_identity_availability_domain" "ad" {
5+
compartment_id = var.tenancy_id
6+
ad_number = var.availability_domain
7+
}
8+
9+
data "oci_core_vcn" "vcn" {
10+
vcn_id = var.vcn_id
11+
}
12+
13+
data "oci_core_images" "oracle_images" {
14+
compartment_id = var.compartment_id
15+
operating_system = "Oracle Linux"
16+
operating_system_version = "9"
17+
shape = lookup(var.wireguard_shape, "shape", "VM.Standard.E2.2")
18+
sort_by = "TIMECREATED"
19+
sort_order = "DESC"
20+
}
21+
22+
# cloud init for wireguard
23+
data "cloudinit_config" "wireguard" {
24+
gzip = true
25+
base64_encode = true
26+
27+
part {
28+
filename = "wireguard.yaml"
29+
content_type = "text/cloud-config"
30+
content = templatefile(
31+
local.wireguard_template, {
32+
wireguard_conf = local.wireguard_conf_template,
33+
wireguard_setup = local.setup_wireguard_template,
34+
wireguard_timezone = var.wireguard_timezone,
35+
upgrade_wireguard = var.upgrade_wireguard
36+
}
37+
)
38+
}
39+
}
40+
41+
# Gets a list of VNIC attachments on the wireguard instance
42+
data "oci_core_vnic_attachments" "wireguard_vnics_attachments" {
43+
availability_domain = data.oci_identity_availability_domain.ad.name
44+
compartment_id = var.compartment_id
45+
depends_on = [oci_core_instance.wireguard]
46+
instance_id = oci_core_instance.wireguard.id
47+
}
48+
49+
# Gets the OCID of the first (default) VNIC on the wireguard instance
50+
data "oci_core_vnic" "wireguard_vnic" {
51+
depends_on = [oci_core_instance.wireguard]
52+
vnic_id = lookup(data.oci_core_vnic_attachments.wireguard_vnics_attachments.vnic_attachments[0], "vnic_id")
53+
}
54+
55+
data "oci_core_instance" "wireguard" {
56+
depends_on = [oci_core_instance.wireguard]
57+
instance_id = oci_core_instance.wireguard.id
58+
}

0 commit comments

Comments
 (0)