Skip to content

veeragoni/cdktf-provider-oci

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CDKTF Provider for Oracle Cloud Infrastructure (OCI)

npm version PyPI version

This repository contains prebuilt Terraform OCI Provider bindings for CDK for Terraform (CDKTF).

About

The cdktf-provider-oci package provides TypeScript/JavaScript and Python bindings for the Oracle Cloud Infrastructure Terraform Provider, enabling you to manage OCI resources using CDKTF with type safety and IDE support.

Features

  • Complete OCI Coverage: Access to all OCI resources and data sources available in the Terraform OCI Provider
  • Type Safety: Full TypeScript/Python type definitions for all resources
  • IDE Support: IntelliSense and autocomplete for resource properties
  • CDKTF Integration: Seamlessly works with CDK for Terraform constructs and workflows

Prerequisites

Before using this provider, ensure you have:

  1. OCI Account: An active Oracle Cloud Infrastructure account
  2. OCI CLI Configuration: Properly configured OCI CLI with credentials (~/.oci/config)
  3. Node.js/Python: Node.js 20.x+ for TypeScript/JavaScript or Python 3.8+ for Python
  4. Terraform: Terraform v1.0+ installed
  5. CDKTF CLI: Install with npm install -g cdktf-cli

Available Packages

npm

Published from this repository at https://www.npmjs.com/package/cdktf-provider-oci.

npm install cdktf-provider-oci

PyPI

Published at https://pypi.org/project/cdktf-provider-oci.

pip install cdktf-provider-oci

Configuration

Authentication

The OCI provider supports multiple authentication methods:

1. API Key Authentication (Default)

new OciProvider(this, 'oci', {
  region: 'us-ashburn-1',
  // Uses ~/.oci/config by default
});

2. Instance Principal Authentication

new OciProvider(this, 'oci', {
  region: 'us-ashburn-1',
  auth: 'InstancePrincipal',
});

3. Resource Principal Authentication

new OciProvider(this, 'oci', {
  region: 'us-ashburn-1',
  auth: 'ResourcePrincipal',
});

Usage

TypeScript

import { App, TerraformStack } from 'cdktf';
import { Construct } from 'constructs';
import { OciProvider } from 'cdktf-provider-oci/lib/provider';
import { CoreInstance } from 'cdktf-provider-oci/lib/core-instance';

class MyStack extends TerraformStack {
  constructor(scope: Construct, id: string) {
    super(scope, id);

    new OciProvider(this, 'oci', {
      region: 'us-ashburn-1',
    });

    new CoreInstance(this, 'example', {
      compartmentId: 'ocid1.compartment.oc1..exampleuniqueID',
      availabilityDomain: 'kIdk:US-ASHBURN-AD-1',
      shape: 'VM.Standard.E4.Flex',
      sourceDetails: {
        sourceType: 'image',
        imageId: 'ocid1.image.oc1..exampleuniqueID',
      },
      createVnicDetails: {
        subnetId: 'ocid1.subnet.oc1..exampleuniqueID',
      },
    });
  }
}

const app = new App();
new MyStack(app, 'oci-example');
app.synth();

Install dependencies with npm install cdktf cdktf-provider-oci constructs before synthesizing.

Python

from constructs import Construct
from cdktf import App, TerraformStack
from cdktf_provider_oci.provider import OciProvider
from cdktf_provider_oci.core_instance import CoreInstance


class MyStack(TerraformStack):
    def __init__(self, scope: Construct, construct_id: str) -> None:
        super().__init__(scope, construct_id)

        OciProvider(self, "oci", region="us-ashburn-1")

        CoreInstance(self, "example",
            compartment_id="ocid1.compartment.oc1..exampleuniqueID",
            availability_domain="kIdk:US-ASHBURN-AD-1",
            shape="VM.Standard.E4.Flex",
            source_details={
                "source_type": "image",
                "image_id": "ocid1.image.oc1..exampleuniqueID",
            },
            create_vnic_details={
                "subnet_id": "ocid1.subnet.oc1..exampleuniqueID",
            },
        )


app = App()
MyStack(app, "oci-example")
app.synth()

Install dependencies with pip install cdktf cdktf-provider-oci constructs before synthesizing.

Complete Example Project

For a complete working example of using this provider, check out the cdktf-oci-example repository, which demonstrates:

  • Setting up a VCN (Virtual Cloud Network)
  • Creating compute instances
  • Configuring security lists and route tables
  • Managing storage resources
  • And more OCI resource configurations

Quick Start with Example Project

# Clone the example repository
git clone https://github.com/veeragoni/cdktf-oci-example.git
cd cdktf-oci-example

# Install dependencies
npm install

# Deploy to OCI
cdktf deploy

Documentation

Provider Documentation

CDKTF Documentation

API Reference

Auto-generated API documentation for this provider is available in the docs folder of this repository:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the Apache-2.0 License.

Support

Versioning

This project is explicitly not tracking the Terraform oci provider version 1:1. In fact, it always tracks latest of ~> 7.19.0 with every release. If there are scenarios where you explicitly have to pin your provider version, you can do so by generating the provider constructs manually.

These are the upstream dependencies:

If there are breaking changes (backward incompatible) in any of the above, the major version of this project will be bumped.

Provider Version

The provider version can be adjusted in ./.projenrc.js.

About

CDK TF Provider for OCI

Resources

License

Stars

Watchers

Forks

Packages

No packages published