Skip to content

Commit d39742c

Browse files
ABAB
authored andcommitted
oci-linux: docs/auth updates; remove SSH var; default compartment to tenancy; fix instance_shape default; use effective compartment for image/AD; update OCI logo to official wordmark
1 parent fcecb98 commit d39742c

File tree

4 files changed

+28
-46
lines changed

4 files changed

+28
-46
lines changed

registry/aybanda/templates/oci-linux/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Provision Oracle Cloud Infrastructure (OCI) VMs as [Coder workspaces](https://co
1717
This template assumes that coderd is run in an environment that is authenticated with Oracle Cloud Infrastructure. The recommended authentication methods are:
1818

1919
1. **Instance Principal** (Recommended for production): Run Coder on an OCI instance with proper IAM policies
20-
2. **API Key**: Set environment variables `OCI_TENANCY_OCID`, `OCI_USER_OCID`, `OCI_FINGERPRINT`, and `OCI_PRIVATE_KEY_PATH`
21-
3. **Configuration File**: Use `~/.oci/config` file
20+
2. **API Key**: Set environment variables `OCI_TENANCY_OCID`, `OCI_USER_OCID`, `OCI_FINGERPRINT`, and `OCI_PRIVATE_KEY_PATH`. If running coderd/provisioner in a container, ensure the private key file path is mounted into the container so it is accessible at the specified path.
21+
3. **Configuration File**: Use `~/.oci/config` file (mount into the container if coderd runs in a container)
2222

2323
For detailed authentication setup, see the [OCI Terraform provider documentation](https://registry.terraform.io/providers/oracle/oci/latest/docs#authentication).
2424

@@ -92,8 +92,7 @@ The template uses Ubuntu 22.04 LTS as the base image and includes:
9292

9393
1. **Set up authentication** using one of the methods above
9494
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
95+
3. **Deploy the template** (if you omit `compartment_ocid`, the tenancy/root compartment will be used)
9796

9897
### Template Variables
9998

registry/aybanda/templates/oci-linux/cloud-init/cloud-config.yaml.tftpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ users:
99
- curl
1010
shell: /bin/bash
1111
sudo: ['ALL=(ALL) NOPASSWD:ALL']
12-
ssh_authorized_keys:
13-
- ${ssh_public_key}
12+
ssh_authorized_keys: []
1413

1514
# Update package list and install basic packages
1615
package_update: true

registry/aybanda/templates/oci-linux/cloud-init/userdata.sh.tftpl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ fi
1414
mkdir -p /opt/coder
1515
mkdir -p /home/${linux_user}
1616

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
17+
# SSH key management is handled by Coder agent; no direct SSH key injection
2518

2619
# Mount home volume if it exists
2720
if [ -b /dev/sdb ]; then

registry/aybanda/templates/oci-linux/main.tf

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ terraform {
1414

1515
# Variables
1616
variable "compartment_ocid" {
17-
description = "The OCID of the compartment to create resources in"
17+
description = "The OCID of the compartment to create resources in. If empty, defaults to tenancy OCID (root compartment)."
1818
type = string
19+
default = ""
1920
}
2021

21-
variable "ssh_public_key" {
22-
description = "SSH public key for the instance"
22+
variable "tenancy_ocid" {
23+
description = "Tenancy OCID used as the root compartment when compartment_ocid is unset. Typically set from environment (OCI_TENANCY_OCID)."
2324
type = string
2425
default = ""
2526
}
@@ -123,7 +124,7 @@ data "coder_parameter" "instance_shape" {
123124
name = "instance_shape"
124125
display_name = "Instance Shape"
125126
description = "What instance shape should your workspace use?"
126-
default = "VM.Standard.A1.Flex"
127+
default = "VM.Standard.E2.1.Micro"
127128
mutable = false
128129
option {
129130
name = "VM.Standard.A1.Flex (1 OCPU, 6 GB RAM)"
@@ -208,16 +209,19 @@ provider "oci" {
208209
data "coder_workspace" "me" {}
209210
data "coder_workspace_owner" "me" {}
210211

211-
# Get the compartment OCID from environment variable
212-
data "oci_identity_compartments" "compartments" {
213-
compartment_id = var.compartment_ocid
214-
access_level = "ACCESSIBLE"
215-
state = "ACTIVE"
212+
# Determine effective compartment (defaults to tenancy/root when not provided)
213+
locals {
214+
effective_compartment_ocid = length(trimspace(var.compartment_ocid)) > 0 ? var.compartment_ocid : var.tenancy_ocid
215+
}
216+
217+
# Validate we have an effective compartment id
218+
locals {
219+
compartment_id = local.effective_compartment_ocid
216220
}
217221

218222
# Get the latest Ubuntu image
219223
data "oci_core_images" "ubuntu" {
220-
compartment_id = var.compartment_ocid
224+
compartment_id = local.compartment_id
221225
operating_system = "Canonical Ubuntu"
222226
operating_system_version = "22.04"
223227
state = "AVAILABLE"
@@ -320,7 +324,6 @@ data "cloudinit_config" "user_data" {
320324
content = templatefile("${path.module}/cloud-init/cloud-config.yaml.tftpl", {
321325
hostname = local.hostname
322326
linux_user = local.linux_user
323-
ssh_public_key = var.ssh_public_key
324327
coder_agent_token = coder_agent.dev[0].token
325328
})
326329
}
@@ -332,30 +335,29 @@ data "cloudinit_config" "user_data" {
332335
content = templatefile("${path.module}/cloud-init/userdata.sh.tftpl", {
333336
hostname = local.hostname
334337
linux_user = local.linux_user
335-
ssh_public_key = var.ssh_public_key
336338
coder_agent_token = coder_agent.dev[0].token
337339
})
338340
}
339341
}
340342

341343
# VCN
342344
resource "oci_core_vcn" "vcn" {
343-
compartment_id = var.compartment_ocid
345+
compartment_id = local.compartment_id
344346
cidr_blocks = ["10.0.0.0/16"]
345347
display_name = "coder-vcn-${data.coder_workspace.me.id}"
346348
dns_label = "coder${data.coder_workspace.me.id}"
347349
}
348350

349351
# Internet Gateway
350352
resource "oci_core_internet_gateway" "internet_gateway" {
351-
compartment_id = var.compartment_ocid
353+
compartment_id = local.compartment_id
352354
vcn_id = oci_core_vcn.vcn.id
353355
display_name = "coder-internet-gateway-${data.coder_workspace.me.id}"
354356
}
355357

356358
# Route Table
357359
resource "oci_core_route_table" "route_table" {
358-
compartment_id = var.compartment_ocid
360+
compartment_id = local.compartment_id
359361
vcn_id = oci_core_vcn.vcn.id
360362
display_name = "coder-route-table-${data.coder_workspace.me.id}"
361363

@@ -368,7 +370,7 @@ resource "oci_core_route_table" "route_table" {
368370

369371
# Security List
370372
resource "oci_core_security_list" "security_list" {
371-
compartment_id = var.compartment_ocid
373+
compartment_id = local.compartment_id
372374
vcn_id = oci_core_vcn.vcn.id
373375
display_name = "coder-security-list-${data.coder_workspace.me.id}"
374376

@@ -377,16 +379,6 @@ resource "oci_core_security_list" "security_list" {
377379
protocol = "all"
378380
}
379381

380-
ingress_security_rules {
381-
protocol = "6"
382-
source = "0.0.0.0/0"
383-
384-
tcp_options {
385-
min = 22
386-
max = 22
387-
}
388-
}
389-
390382
ingress_security_rules {
391383
protocol = "6"
392384
source = "0.0.0.0/0"
@@ -410,7 +402,7 @@ resource "oci_core_security_list" "security_list" {
410402

411403
# Subnet
412404
resource "oci_core_subnet" "subnet" {
413-
compartment_id = var.compartment_ocid
405+
compartment_id = local.compartment_id
414406
vcn_id = oci_core_vcn.vcn.id
415407
cidr_block = "10.0.1.0/24"
416408
display_name = "coder-subnet-${data.coder_workspace.me.id}"
@@ -422,22 +414,22 @@ resource "oci_core_subnet" "subnet" {
422414

423415
# Home disk
424416
resource "oci_core_volume" "home_volume" {
425-
compartment_id = var.compartment_ocid
417+
compartment_id = local.compartment_id
426418
display_name = "coder-${data.coder_workspace.me.id}-home"
427419
size_in_gbs = data.coder_parameter.home_size.value
428420
availability_domain = data.oci_identity_availability_domains.ads.availability_domains[0].name
429421
}
430422

431423
# Get availability domains
432424
data "oci_identity_availability_domains" "ads" {
433-
compartment_id = var.compartment_ocid
425+
compartment_id = local.compartment_id
434426
}
435427

436428
# OCI Instance
437429
resource "oci_core_instance" "dev" {
438430
count = data.coder_workspace.me.start_count
439431
availability_domain = data.oci_identity_availability_domains.ads.availability_domains[0].name
440-
compartment_id = var.compartment_ocid
432+
compartment_id = local.compartment_id
441433
display_name = "coder-${lower(data.coder_workspace_owner.me.name)}-${lower(data.coder_workspace.me.name)}"
442434
shape = local.base_shape
443435

@@ -460,7 +452,6 @@ resource "oci_core_instance" "dev" {
460452
}
461453

462454
metadata = {
463-
ssh_authorized_keys = var.ssh_public_key
464455
user_data = base64encode(data.cloudinit_config.user_data.rendered)
465456
}
466457

@@ -473,7 +464,7 @@ resource "oci_core_instance" "dev" {
473464
resource "oci_core_volume_attachment" "home_attachment" {
474465
count = data.coder_workspace.me.start_count
475466
attachment_type = "paravirtualized"
476-
compartment_id = var.compartment_ocid
467+
compartment_id = local.compartment_id
477468
instance_id = oci_core_instance.dev[0].id
478469
volume_id = oci_core_volume.home_volume.id
479470
}

0 commit comments

Comments
 (0)