Skip to content

Commit 31c802f

Browse files
committed
feat: add Oracle Cloud Infrastructure (OCI) template
1 parent 0a3c9b0 commit 31c802f

File tree

5 files changed

+754
-0
lines changed

5 files changed

+754
-0
lines changed

.icons/oci.svg

Lines changed: 13 additions & 0 deletions
Loading
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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+
87+
- Code Server for web-based development
88+
- JetBrains Gateway for IDE access
89+
- Persistent home directory storage
90+
- Automatic Coder agent installation
91+
92+
## Usage
93+
94+
1. **Set up authentication** using one of the methods above
95+
2. **Create a compartment** in your OCI tenancy
96+
3. **Deploy the template** with your compartment OCID
97+
4. **Optionally provide an SSH public key** for direct SSH access
98+
99+
### Template Variables
100+
101+
- `compartment_ocid`: The OCID of your OCI compartment
102+
- `ssh_public_key`: (Optional) SSH public key for direct access
103+
104+
### Instance Shapes
105+
106+
The template supports various OCI instance shapes:
107+
108+
- **VM.Standard.A1.Flex**: ARM-based flexible shapes (1-4 OCPUs, 6-24 GB RAM)
109+
- **VM.Standard.E2.1.Micro**: Cost-effective micro instances
110+
- **VM.Standard.E2.1.Small**: Small instances for development
111+
- **VM.Standard.E2.1.Medium**: Medium instances for larger workloads
112+
- **VM.Standard.E3.Flex**: AMD-based flexible shapes
113+
114+
### Regions
115+
116+
The template supports all major OCI regions:
117+
118+
- **Americas**: US East (Ashburn), US West (Phoenix), Canada Southeast (Montreal)
119+
- **Europe**: UK South (London), Germany Central (Frankfurt), Netherlands Northwest (Amsterdam), Switzerland North (Zurich)
120+
- **Asia Pacific**: Japan East (Tokyo), Japan Central (Osaka), South Korea Central (Seoul), Australia Southeast (Sydney), India West (Mumbai), India South (Hyderabad)
121+
- **Middle East**: Saudi Arabia West (Jeddah), UAE East (Dubai)
122+
- **South America**: Brazil East (São Paulo), Chile (Santiago)
123+
124+
## Cost Optimization
125+
126+
- Use **VM.Standard.A1.Flex** shapes for cost-effective ARM-based instances
127+
- Choose **VM.Standard.E2.1.Micro** for minimal development workloads
128+
- Consider **VM.Standard.E3.Flex** for AMD-based workloads requiring more memory
129+
- Use smaller home disk sizes (50 GB) for basic development
130+
- Stop workspaces when not in use to avoid charges
131+
132+
## Security
133+
134+
- Instances are created with public IP addresses for Coder access
135+
- SSH access is restricted to the provided public key
136+
- Security lists allow only necessary ports (22, 80, 443)
137+
- All resources are tagged with `Coder_Provisioned = true`
138+
139+
## Troubleshooting
140+
141+
### Common Issues
142+
143+
1. **Authentication Errors**: Ensure proper OCI authentication is configured
144+
2. **Permission Errors**: Verify IAM policies are correctly set
145+
3. **Network Issues**: Check VCN and security list configuration
146+
4. **Volume Attachment**: Ensure the home volume is properly attached
147+
148+
### Debugging
149+
150+
- Check OCI console for instance status and logs
151+
- Verify network connectivity and security list rules
152+
- Review Terraform logs for detailed error messages
153+
154+
## Contributing
155+
156+
This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.
157+
158+
For issues and contributions, please visit the [Coder Registry repository](https://github.com/coder/registry).
159+
160+
## Contributors
161+
162+
- [aybanda](https://github.com/aybanda)
163+
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)