Skip to content

Commit 0fac547

Browse files
ABAB
authored andcommitted
oci-linux: add precondition for compartment/tenancy and clarify auth/TF_VAR guidance to avoid 401s
1 parent d39742c commit 0fac547

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

Lines changed: 5 additions & 3 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`. 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)
20+
2. **API Key**: Set env vars `OCI_TENANCY_OCID`, `OCI_USER_OCID`, `OCI_FINGERPRINT`, `OCI_PRIVATE_KEY_PATH`. If coderd/provisioner runs in a container, mount the private key path into the container.
21+
3. **Configuration File**: Use `~/.oci/config` (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,7 +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** (if you omit `compartment_ocid`, the tenancy/root compartment will be used)
95+
3. **Deploy the template** (if you omit `compartment_ocid`, set `TF_VAR_tenancy_ocid` to your tenancy OCID so the root compartment is used)
9696

9797
### Template Variables
9898

@@ -139,6 +139,8 @@ The template supports all major OCI regions:
139139
### Common Issues
140140

141141
1. **Authentication Errors**: Ensure proper OCI authentication is configured
142+
- If not using Instance Principals, set `TF_VAR_tenancy_ocid` (or `compartment_ocid`) and OCI env vars
143+
- For containers, mount `OCI_PRIVATE_KEY_PATH` and/or `~/.oci/config` into the provisioner container
142144
2. **Permission Errors**: Verify IAM policies are correctly set
143145
3. **Network Issues**: Check VCN and security list configuration
144146
4. **Volume Attachment**: Ensure the home volume is properly attached

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ locals {
219219
compartment_id = local.effective_compartment_ocid
220220
}
221221

222+
# Early, friendly validation to avoid opaque 401s from the OCI APIs
223+
resource "null_resource" "validate_configuration" {
224+
lifecycle {
225+
precondition {
226+
condition = length(trimspace(local.compartment_id)) > 0
227+
error_message = "Provide either 'compartment_ocid' or 'tenancy_ocid'. For containerized coderd, set TF_VAR_tenancy_ocid or mount ~/.oci/config and set OCI_* envs."
228+
}
229+
}
230+
}
231+
222232
# Get the latest Ubuntu image
223233
data "oci_core_images" "ubuntu" {
224234
compartment_id = local.compartment_id

0 commit comments

Comments
 (0)