Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add simple example for Oracle Cloud Infrastructure #124

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,34 @@ jobs:
DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }}
if: github.ref == 'refs/heads/main' || env.GITHUB_REF_SLUG == 'integration' # Only run on main/integration, as these take a long time
run: ${{github.workspace}}/bin/run_digitalocean_examples.sh
ProvidersOCI:
concurrency: provider_test_oci
needs: [TFLint, TFValidate, Checks]
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
fetch-depth: 0 # Need whole history, or at least far enough back to get .test_log.log reference
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
cli_config_credentials_token: ${{ secrets.TERRAFORM_CLOUD_LOGIN_TOKEN }}
- name: Inject slug/short variables
uses: rlespinasse/[email protected]
- name: Run OCI examples
env:
CI_USE_TF_CLOUD: ${{ secrets.CI_USE_TF_CLOUD }}
TERRAFORM_CLOUD_LOGIN_TOKEN: ${{ secrets.TERRAFORM_CLOUD_LOGIN_TOKEN }}
OCI_PROFILE_FILE: ${{ secrets.OCI_PROFILE_FILE }}
OCI_PROFILE_FILENAME: ${{ secrets.OCI_PROFILE_FILENAME }}
OCI_KEY_FILE_FILE: ${{ secrets.OCI_KEY_FILE_FILE }}
OCI_KEY_FILE_FILENAME: ${{ secrets.OCI_KEY_FILE_FILENAME }}
TF_VAR_config_file_profile: ${{ secrets.OCI_CLI_PROFILE }}
if: github.ref == 'refs/heads/main' || env.GITHUB_REF_SLUG == 'integration' # Only run on main/integration, as these take a long time
run: ${{github.workspace}}/bin/run_oci_examples.sh
ProvidersAzure:
concurrency: provider_test_azure
needs: [TFLint, TFValidate, Checks]
Expand Down Expand Up @@ -207,7 +235,7 @@ jobs:
run: ${{github.workspace}}/bin/run_local_examples.sh
RecordActionSuccess:
runs-on: ubuntu-latest
needs: [ProvidersLocal, ProvidersAzure, ProvidersDigitalocean, ProvidersLinode, ProvidersGCP, ProvidersAWS]
needs: [ProvidersLocal, ProvidersAzure, ProvidersDigitalocean, ProvidersOCI, ProvidersLinode, ProvidersGCP, ProvidersAWS]
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/integration' # Only run on main/integration, as we run provider tests only there
steps:
- name: Check out repository code
Expand Down
3 changes: 2 additions & 1 deletion INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
| Feature | Links/Related Features |
| ------------- |:-------------:|
| `aws_db_cluster_snapshot` | [aws](aws/aws_db_cluster_snapshot) <p/> [simple](aws/aws_db_cluster_snapshot/simple) |
| `aws_db_instance` | [aws](aws/aws_db_instance) <p/> [simple](aws/aws_db_instance/simple) <p/> [postgres](aws/aws_db_instance/postgres) <p/> [restore_db_from_snapshot](aws/aws_db_instance/restore_db_from_snapshot) |
| `aws_db_instance` | [aws](aws/aws_db_instance) <p/> [simple](aws/aws_db_instance/simple) <p/> [postgres](aws/aws_db_instance/postgres) <p/> [restore_db_from_snapshot](aws/aws_db_instance/restore_db_from_snapshot) |
| `aws_dynamodb_table_item` | [aws](aws/aws_dynamodb_table_item) <p/> [simple](aws/aws_dynamodb_table_item/simple) |
| `aws_dynamodb_table` | [aws](aws/aws_dynamodb_table) <p/> [simple](aws/aws_dynamodb_table/simple) |
| `aws_ebs_volume` | [aws](aws/aws_ebs_volume) <p/>[simple](aws/aws_ebs_volume/simple) <p/> [volume_attachment](aws/aws_ebs_volume/volume_attachment) <p/> [ebs_snapshot](aws/aws_ebs_volume/ebs_snapshot) |
Expand Down Expand Up @@ -83,6 +83,7 @@
| `map` | [null_resource, for_each, local](local/null_resource/for_each) |
| `module` | [modules](modules) <p/> [local, module usage](variables/local_file/module) <p/> [local, module example](modules/local_file/hello_module) <p/> [local, module example consumer](modules/local_file/hello_consumer) |
| `null_resource` | [simple, local](local/null_resource/simple) |
| `oci_core_instance` | [oci, oci_core_instance](oci/oci_core_instance/simple) |
| `outputs` | [outputs](outputs) <p/> [local](outputs/local_file/local_file) <p/> [local, module](outputs/local_file/module) |
| `random_id` | [simple](aws/aws_s3_bucket/simple) |
| `remote-exec` | [aws, inline](aws/aws_instance/remote-exec/inline) |
Expand Down
2 changes: 1 addition & 1 deletion bin/apply.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

SUPPORTED_PROVIDERS="aws|azurerm|digitalocean|google|kubernetes|linode"
SUPPORTED_PROVIDERS="aws|azurerm|digitalocean|google|kubernetes|linode|oci"
if [[ -n "$1" && ! "$1" =~ ${SUPPORTED_PROVIDERS} ]]
then
echo "usage: $0 [PROVIDER]"
Expand Down
2 changes: 1 addition & 1 deletion bin/destroy.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

SUPPORTED_PROVIDERS="aws|azurerm|digitalocean|google|kubernetes|linode"
SUPPORTED_PROVIDERS="aws|azurerm|digitalocean|google|kubernetes|linode|oci"
if [[ -n "$1" && ! "$1" =~ ${SUPPORTED_PROVIDERS} ]]
then
echo "usage: $0 [PROVIDER]"
Expand Down
3 changes: 3 additions & 0 deletions bin/get_oci_folders.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
# shellcheck disable=SC2034
OCI_FOLDERS="$(find oci | grep tf$ | xargs -n1 dirname | sed 's/^.\///')"
44 changes: 44 additions & 0 deletions bin/run_oci_examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

set -o errexit
set -o nounset

cd "${0%/*}/.."

echo "$OCI_PROFILE_FILE" > "$OCI_PROFILE_FILENAME"
echo "$OCI_KEY_FILE_FILE" > "$OCI_KEY_FILE_FILENAME"

last_successful_commit=$(./bin/get_last_successful_commit.sh)
changed_folders=$(./bin/get_changed_folders.sh)
# shellcheck disable=SC1091
source bin/get_oci_folders.sh
for folder in ${OCI_FOLDERS}
do
echo "================================================================================"
echo -n "$0 checking folder: ${folder} ... "
if [[ -a ${folder}/.skiptest ]]
then
echo -n "found .skiptest file, skipping "
continue
fi
if ! echo "$changed_folders" | tr ' ' '\n' | grep "$folder"
then
if [[ -a oci/.forcetest ]]
then
echo "oci/.forcetest file exists, forcing test run"
elif [[ -a ${folder}/.forcetest ]]
then
echo "${folder}/.forcetest file exists, forcing test run"
else
echo "Folder ${folder} has not changed since last successful test on main (${last_successful_commit})"
continue
fi
fi
pushd "${folder}" >/dev/null
echo -n "./run.sh"
# If the run fails, try and clean up
./run.sh || ( ./destroy.sh && exit 1 )
echo -n "./destroy.sh"
./destroy.sh
popd >/dev/null
done
31 changes: 31 additions & 0 deletions bin/shared_oci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -o errexit
set -o pipefail


if [ -z "$OCI_CLI_CONFIG_FILE" ]
then
OCI_CLI_CONFIG_FILE="${HOME}/.oci/config"
echo "By default we look for oci config file in ${OCI_CLI_CONFIG_FILE}"
echo "To use a custom oci config path, run 'export OCI_CLI_CONFIG_FILE=<YOUR_OCI_CLI_CONFIG_FILE>'"
if [ ! -f "$OCI_CLI_CONFIG_FILE" ]
then
echo "No config file was found"
echo "Make sure oci-cli is initialised, by running: 'oci setup config'"
echo "More info available here: https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm#configfile__setupdialog"
fi
echo "NOTE: Terraform provider doesn't use this value. It is used only by oci-cli."
fi
if [ -z "$TF_VAR_config_file_profile" ]
then
TF_VAR_config_file_profile="DEFAULT"
echo "By default we use profile: ${TF_VAR_config_file_profile}"
echo "To use a custom profile, run 'export TF_VAR_config_file_profile=<YOUR_CONFIG_FILE_PROFILE>'"
echo "More info avaiable at: https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/terraformproviderconfiguration.htm#terraformproviderconfiguration_topic-SDK_and_CLI_Config_File"
fi

set -o nounset

export OCI_CLI_CONFIG_FILE
export TF_VAR_config_file_profile
2 changes: 2 additions & 0 deletions oci/oci_core_instance/simple/destroy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
../../../bin/destroy.sh oci
70 changes: 70 additions & 0 deletions oci/oci_core_instance/simple/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Summary: Creates the simplest VM instance

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
required_version = ">= 1.0.0"
required_providers {
oci = {
source = "hashicorp/oci"
version = "~> 4.51.0"
}
}
}

# Oracle Cloud Infrastructure Provider
# Documentation: https://registry.terraform.io/providers/hashicorp/oci/latest/docs
provider "oci" {
}

# The OCID of the compartment
# Documentation: https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_instance#compartment_id
variable "changeme_compartment_id" {
type = string

default = "ocid1.compartment.oc1..aaaaaaaavrhfdoos3wg4qnl52iy22pxyiseyjp4yn67x4mukc34dc6uruliq"
}

# Subnet to create the VNIC in
# Documentation: https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_instance#subnet_id
variable "changeme_subnet_id" {
type = string

default = "ocid1.subnet.oc1.eu-amsterdam-1.aaaaaaaawd2edyewykhmjgfqrzxhlpk4q7hvyz5xv6p4tuxbhknp2jwo2xda"
}

# Oracle Cloud Infrastructure Images
# https://docs.oracle.com/en-us/iaas/images/ubuntu-2004/
variable "changeme_image_id" {
type = string

default = "ocid1.image.oc1.eu-amsterdam-1.aaaaaaaawlrfkqdc4fm4tco6ifgmd4pcbjg232hyo6gscvu6xcgnufdznqtq"
}

# Data source for a single Availability Domain
# Documentation: https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/identity_availability_domain
data "oci_identity_availability_domain" "changeme_availability_domain" {
compartment_id = var.changeme_compartment_id
ad_number = 1
}

# Instance resource
# Documentation: https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_instance
resource "oci_core_instance" "changeme_oci_simple_instance" {
availability_domain = data.oci_identity_availability_domain.changeme_availability_domain.name
compartment_id = data.oci_identity_availability_domain.changeme_availability_domain.compartment_id
display_name = "changeme-oci-simple-instance"
shape = "VM.Standard.E2.1.Micro"

create_vnic_details {
subnet_id = var.changeme_subnet_id
}

source_details {
source_type = "image"
source_id = var.changeme_image_id
}

freeform_tags = {
cs_terraform_examples = "oci_core_instance/simple"
}
}
2 changes: 2 additions & 0 deletions oci/oci_core_instance/simple/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
../../../bin/apply.sh oci