Skip to content

Commit c1f3e5c

Browse files
authored
Add OCI Linux template
1 parent 0449051 commit c1f3e5c

File tree

3 files changed

+192
-0
lines changed

3 files changed

+192
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
display_name: Oracle Cloud Infrastructure (Linux)
3+
description: Provision OCI VMs as Coder workspaces
4+
icon: ../../../../.icons/oci.svg
5+
verified: false
6+
tags: [vm, linux, oci]
7+
---
8+
9+
# Remote Development on Oracle Cloud Infrastructure (OCI)
10+
11+
Provision OCI VMs as [Coder workspaces](https://coder.com/docs/workspaces) with this template.
12+
13+
## Prerequisites
14+
15+
### Oracle Cloud Infrastructure Account
16+
You need an active OCI account.
17+
18+
### Required Variables
19+
To use this template, you must provide the following variables. These can be found in your OCI Console.
20+
21+
1. **tenancy_ocid**: The OCID of your tenancy. Found in **Governance & Administration** -> **Tenancy Details**.
22+
2. **user_ocid**: The value of the specific user's OCID. Found in **Identity** -> **Users**.
23+
3. **fingerprint**: Create an API key for the user (in **User Details** -> **API Keys**) and get the fingerprint.
24+
4. **private_key_path**: The local path to the private key file corresponding to the public key you uploaded. This path must be accessible by the Coder server or provisioner.
25+
5. **region**: Your OCI region (e.g., `us-ashburn-1`).
26+
6. **compartment_ocid**: The OCID of the compartment where resources will be created.
27+
7. **image_id**: The OCID of the Linux image (e.g., Ubuntu 22.04) you want to use.
28+
* Go to **Compute** -> **Platform Images** to find the generic image OCID for your region (e.g. `Canonical Ubuntu`).
29+
30+
## Resources Created
31+
- VCN, Subnet, Internet Gateway, Route Table
32+
- OCI Compute Instance (default shape: VM.Standard.A1.Flex)
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
oci = {
7+
source = "oracle/oci"
8+
}
9+
}
10+
}
11+
12+
provider "oci" {
13+
tenancy_ocid = var.tenancy_ocid
14+
user_ocid = var.user_ocid
15+
fingerprint = var.fingerprint
16+
private_key_path = var.private_key_path
17+
region = var.region
18+
}
19+
20+
data "coder_workspace" "me" {}
21+
22+
resource "coder_agent" "main" {
23+
auth = "token"
24+
arch = length(regexall("A1", var.instance_shape)) > 0 ? "arm64" : "amd64"
25+
os = "linux"
26+
startup_script = <<EOT
27+
#!/bin/bash
28+
set -euo pipefail
29+
# Install code-server
30+
curl -fsSL https://code-server.dev/install.sh | sh
31+
code-server --auth none --port 13337 >/dev/null 2>&1 &
32+
EOT
33+
}
34+
35+
resource "coder_app" "code-server" {
36+
agent_id = coder_agent.main.id
37+
slug = "code-server"
38+
display_name = "code-server"
39+
url = "http://localhost:13337/?folder=/home/coder"
40+
icon = "/icon/code.svg"
41+
subdomain = false
42+
share = "owner"
43+
44+
healthcheck {
45+
url = "http://localhost:13337/healthz"
46+
interval = 5
47+
threshold = 6
48+
}
49+
}
50+
51+
resource "oci_core_vcn" "main" {
52+
cidr_block = "10.0.0.0/16"
53+
compartment_id = var.compartment_ocid
54+
display_name = "coder-vcn"
55+
}
56+
57+
resource "oci_core_subnet" "main" {
58+
cidr_block = "10.0.1.0/24"
59+
compartment_id = var.compartment_ocid
60+
vcn_id = oci_core_vcn.main.id
61+
display_name = "coder-subnet"
62+
route_table_id = oci_core_route_table.main.id
63+
security_list_ids = [oci_core_vcn.main.default_security_list_id]
64+
}
65+
66+
resource "oci_core_internet_gateway" "main" {
67+
compartment_id = var.compartment_ocid
68+
vcn_id = oci_core_vcn.main.id
69+
display_name = "coder-internet-gateway"
70+
}
71+
72+
resource "oci_core_route_table" "main" {
73+
compartment_id = var.compartment_ocid
74+
vcn_id = oci_core_vcn.main.id
75+
display_name = "coder-route-table"
76+
77+
route_rules {
78+
destination = "0.0.0.0/0"
79+
destination_type = "CIDR_BLOCK"
80+
network_entity_id = oci_core_internet_gateway.main.id
81+
}
82+
}
83+
84+
data "oci_identity_availability_domains" "ads" {
85+
compartment_id = var.tenancy_ocid
86+
}
87+
88+
resource "oci_core_instance" "main" {
89+
availability_domain = data.oci_identity_availability_domains.ads.availability_domains[0].name
90+
compartment_id = var.compartment_ocid
91+
display_name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}"
92+
shape = var.instance_shape
93+
94+
dynamic "shape_config" {
95+
for_each = length(regexall("Flex", var.instance_shape)) > 0 ? [1] : []
96+
content {
97+
memory_in_gbs = 6
98+
ocpus = 1
99+
}
100+
}
101+
102+
create_vnic_details {
103+
subnet_id = oci_core_subnet.main.id
104+
assign_public_ip = true
105+
}
106+
107+
source_details {
108+
source_type = "image"
109+
source_id = var.image_id
110+
}
111+
112+
metadata = {
113+
ssh_authorized_keys = coder_agent.main.initial_runner_user_public_key
114+
user_data = base64encode(coder_agent.main.init_script) // Crucial requirement
115+
}
116+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
variable "tenancy_ocid" {
2+
description = "The OCID of your tenancy."
3+
type = string
4+
sensitive = true
5+
}
6+
7+
variable "user_ocid" {
8+
description = "The OCID of the user calling the API."
9+
type = string
10+
sensitive = true
11+
}
12+
13+
variable "fingerprint" {
14+
description = "The fingerprint for the API key."
15+
type = string
16+
sensitive = true
17+
}
18+
19+
variable "private_key_path" {
20+
description = "The path to the private key used for authentication."
21+
type = string
22+
sensitive = true
23+
}
24+
25+
variable "region" {
26+
description = "The OCI region (e.g. us-ashburn-1)."
27+
type = string
28+
}
29+
30+
variable "compartment_ocid" {
31+
description = "The OCID of the compartment to contain the resources."
32+
type = string
33+
sensitive = true
34+
}
35+
36+
variable "instance_shape" {
37+
description = "The shape of the instance."
38+
default = "VM.Standard.A1.Flex"
39+
}
40+
41+
variable "image_id" {
42+
description = "The OCID of an Ubuntu image (or other Linux) in your region."
43+
type = string
44+
}

0 commit comments

Comments
 (0)