Skip to content

Commit 97b5fad

Browse files
committed
feat: add Oracle Cloud Infrastructure (OCI) template (#201)
1 parent 0a3c9b0 commit 97b5fad

File tree

5 files changed

+746
-0
lines changed

5 files changed

+746
-0
lines changed

.icons/oci.svg

Lines changed: 13 additions & 0 deletions
Loading
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
display_name: Oracle Cloud Infrastructure (Linux)
3+
description: Provision Oracle Cloud Infrastructure VMs as Coder workspaces
4+
icon: ../../../../.icons/oci.svg
5+
maintainer_github: coder
6+
verified: false
7+
tags: [vm, linux, oci, oracle]
8+
---
9+
10+
# Remote Development on Oracle Cloud Infrastructure (Linux)
11+
12+
Provision Oracle Cloud Infrastructure (OCI) VMs as [Coder workspaces](https://coder.com/docs/workspaces) with this example template.
13+
14+
## Prerequisites
15+
16+
### Authentication
17+
18+
This template assumes that coderd is run in an environment that is authenticated with Oracle Cloud Infrastructure. The recommended authentication methods are:
19+
20+
1. **Instance Principal** (Recommended for production): Run Coder on an OCI instance with proper IAM policies
21+
2. **API Key**: Set environment variables `OCI_TENANCY_OCID`, `OCI_USER_OCID`, `OCI_FINGERPRINT`, and `OCI_PRIVATE_KEY_PATH`
22+
3. **Configuration File**: Use `~/.oci/config` file
23+
24+
For detailed authentication setup, see the [OCI Terraform provider documentation](https://registry.terraform.io/providers/oracle/oci/latest/docs#authentication).
25+
26+
### Required IAM Policies
27+
28+
The following IAM policies are required for the template to work:
29+
30+
```json
31+
{
32+
"statements": [
33+
{
34+
"effect": "Allow",
35+
"action": [
36+
"core:instance:create",
37+
"core:instance:delete",
38+
"core:instance:get",
39+
"core:instance:update",
40+
"core:volume:create",
41+
"core:volume:delete",
42+
"core:volume:get",
43+
"core:volume:update",
44+
"core:volumeAttachment:create",
45+
"core:volumeAttachment:delete",
46+
"core:volumeAttachment:get",
47+
"core:vcn:create",
48+
"core:vcn:delete",
49+
"core:vcn:get",
50+
"core:vcn:update",
51+
"core:subnet:create",
52+
"core:subnet:delete",
53+
"core:subnet:get",
54+
"core:subnet:update",
55+
"core:internetGateway:create",
56+
"core:internetGateway:delete",
57+
"core:internetGateway:get",
58+
"core:internetGateway:update",
59+
"core:routeTable:create",
60+
"core:routeTable:delete",
61+
"core:routeTable:get",
62+
"core:routeTable:update",
63+
"core:securityList:create",
64+
"core:securityList:delete",
65+
"core:securityList:get",
66+
"core:securityList:update",
67+
"core:image:get",
68+
"identity:compartment:get"
69+
],
70+
"resource": "*"
71+
}
72+
]
73+
}
74+
```
75+
76+
## Architecture
77+
78+
This template provisions the following resources:
79+
80+
- **OCI VM** (ephemeral, deleted on stop)
81+
- **OCI Block Volume** (persistent, mounted to `/home/coder`)
82+
- **VCN with Internet Gateway** (for network connectivity)
83+
- **Security List** (with SSH, HTTP, and HTTPS access)
84+
85+
The template uses Ubuntu 22.04 LTS as the base image and includes:
86+
- Code Server for web-based development
87+
- JetBrains Gateway for IDE access
88+
- Persistent home directory storage
89+
- Automatic Coder agent installation
90+
91+
## Usage
92+
93+
1. **Set up authentication** using one of the methods above
94+
2. **Create a compartment** in your OCI tenancy
95+
3. **Deploy the template** with your compartment OCID
96+
4. **Optionally provide an SSH public key** for direct SSH access
97+
98+
### Template Variables
99+
100+
- `compartment_ocid`: The OCID of your OCI compartment
101+
- `ssh_public_key`: (Optional) SSH public key for direct access
102+
103+
### Instance Shapes
104+
105+
The template supports various OCI instance shapes:
106+
- **VM.Standard.A1.Flex**: ARM-based flexible shapes (1-4 OCPUs, 6-24 GB RAM)
107+
- **VM.Standard.E2.1.Micro**: Cost-effective micro instances
108+
- **VM.Standard.E2.1.Small**: Small instances for development
109+
- **VM.Standard.E2.1.Medium**: Medium instances for larger workloads
110+
- **VM.Standard.E3.Flex**: AMD-based flexible shapes
111+
112+
### Regions
113+
114+
The template supports all major OCI regions:
115+
- **Americas**: US East (Ashburn), US West (Phoenix), Canada Southeast (Montreal)
116+
- **Europe**: UK South (London), Germany Central (Frankfurt), Netherlands Northwest (Amsterdam), Switzerland North (Zurich)
117+
- **Asia Pacific**: Japan East (Tokyo), Japan Central (Osaka), South Korea Central (Seoul), Australia Southeast (Sydney), India West (Mumbai), India South (Hyderabad)
118+
- **Middle East**: Saudi Arabia West (Jeddah), UAE East (Dubai)
119+
- **South America**: Brazil East (São Paulo), Chile (Santiago)
120+
121+
## Cost Optimization
122+
123+
- Use **VM.Standard.A1.Flex** shapes for cost-effective ARM-based instances
124+
- Choose **VM.Standard.E2.1.Micro** for minimal development workloads
125+
- Consider **VM.Standard.E3.Flex** for AMD-based workloads requiring more memory
126+
- Use smaller home disk sizes (50 GB) for basic development
127+
- Stop workspaces when not in use to avoid charges
128+
129+
## Security
130+
131+
- Instances are created with public IP addresses for Coder access
132+
- SSH access is restricted to the provided public key
133+
- Security lists allow only necessary ports (22, 80, 443)
134+
- All resources are tagged with `Coder_Provisioned = true`
135+
136+
## Troubleshooting
137+
138+
### Common Issues
139+
140+
1. **Authentication Errors**: Ensure proper OCI authentication is configured
141+
2. **Permission Errors**: Verify IAM policies are correctly set
142+
3. **Network Issues**: Check VCN and security list configuration
143+
4. **Volume Attachment**: Ensure the home volume is properly attached
144+
145+
### Debugging
146+
147+
- Check OCI console for instance status and logs
148+
- Verify network connectivity and security list rules
149+
- Review Terraform logs for detailed error messages
150+
151+
## Contributing
152+
153+
This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.
154+
155+
For issues and contributions, please visit the [Coder Registry repository](https://github.com/coder/registry).
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#cloud-config
2+
hostname: ${hostname}
3+
users:
4+
- name: ${linux_user}
5+
uid: 1000
6+
gid: 1000
7+
groups: sudo
8+
packages:
9+
- curl
10+
shell: /bin/bash
11+
sudo: ['ALL=(ALL) NOPASSWD:ALL']
12+
ssh_authorized_keys:
13+
- ${ssh_public_key}
14+
15+
# Update package list and install basic packages
16+
package_update: true
17+
package_upgrade: true
18+
packages:
19+
- curl
20+
- wget
21+
- git
22+
- unzip
23+
- software-properties-common
24+
- apt-transport-https
25+
- ca-certificates
26+
- gnupg
27+
- lsb-release
28+
29+
# Write the Coder agent token to a file
30+
write_files:
31+
- path: /opt/coder/init.env
32+
content: |
33+
CODER_AGENT_TOKEN=${coder_agent_token}
34+
owner: ${linux_user}:${linux_user}
35+
permissions: '0600'
36+
37+
# Run commands after package installation
38+
runcmd:
39+
- systemctl enable --now coder-agent
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Set hostname
5+
hostnamectl set-hostname ${hostname}
6+
7+
# Create coder user if it doesn't exist
8+
if ! id "${linux_user}" &>/dev/null; then
9+
useradd -m -s /bin/bash -G sudo ${linux_user}
10+
echo "${linux_user} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
11+
fi
12+
13+
# Create necessary directories
14+
mkdir -p /opt/coder
15+
mkdir -p /home/${linux_user}
16+
17+
# Set up SSH key if provided
18+
if [ -n "${ssh_public_key}" ]; then
19+
mkdir -p /home/${linux_user}/.ssh
20+
echo "${ssh_public_key}" >> /home/${linux_user}/.ssh/authorized_keys
21+
chown -R ${linux_user}:${linux_user} /home/${linux_user}/.ssh
22+
chmod 700 /home/${linux_user}/.ssh
23+
chmod 600 /home/${linux_user}/.ssh/authorized_keys
24+
fi
25+
26+
# Mount home volume if it exists
27+
if [ -b /dev/sdb ]; then
28+
# Check if the disk is already formatted
29+
if ! blkid /dev/sdb; then
30+
mkfs.ext4 /dev/sdb
31+
fi
32+
33+
# Create mount point and mount
34+
mkdir -p /home/${linux_user}
35+
mount /dev/sdb /home/${linux_user}
36+
37+
# Add to fstab for persistence
38+
echo "/dev/sdb /home/${linux_user} ext4 defaults 0 2" >> /etc/fstab
39+
40+
# Set ownership
41+
chown -R ${linux_user}:${linux_user} /home/${linux_user}
42+
fi
43+
44+
# Download and install Coder agent
45+
curl -fsSL https://coder.com/install.sh | sh
46+
47+
# Start the Coder agent
48+
systemctl enable --now coder-agent

0 commit comments

Comments
 (0)