diff --git a/.gitignore b/.gitignore index 66398c2..9a2bdeb 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,7 @@ .terraform/ .terraform.lock.hcl *.auto.tfvars +*.tfstate +*.tfstate.backup __pycache__/ diff --git a/knowledge base/oci-cli.md b/knowledge base/oci-cli.md new file mode 100644 index 0000000..4cd340b --- /dev/null +++ b/knowledge base/oci-cli.md @@ -0,0 +1,60 @@ +# OCI CLI + +Oracle Cloud Infrastructure CLI. + +1. [TL;DR](#tldr) +2. [Configuration](#configuration) +3. [Further readings](#further-readings) + +## TL;DR + +```sh +# Install the CLI. +brew install 'oci-cli' + +# Start the interactive setup. +oci setup config + +# Generate a key pair to include in the config file. +oci setup keys + +# Show the current configuration. +cat ~/.oci/config + +# List available compartments. +oci iam compartment list +oci iam compartment list -c 'tenancy_id' + +# Create compartments. +oci iam compartment create -c 'root_compartment_id' \ + --name 'compartment_name' --description 'friendly_description' + +# List available availability domains. +oci iam availability-domain list +oci iam availability-domain list -c 'tenancy_id' + +# List available compute images. +# Output is paginated. +oci compute image list -c 'tenancy_id' --all +oci compute image list -c 'tenancy_id' \ + --operating-system 'Oracle Linux' --operating-system-version '8' \ + --lifecycle-state 'AVAILABLE' +``` + +## Configuration + +| Unix location | Description | +| ------------------------ | -------------------------------------------------------------------------------------- | +| `~/.oci/config` | The default configuration file. | +| `~/.oci/oci_api_key.pem` | Full path and filename of the private key. The key pair **must be in the PEM format**. | + +## Further readings + +- [Command Line Interface] +- [SDK and CLI Configuration File] +- [Required keys and OCIDs] + + +[command line interface]: https://docs.oracle.com/en-us/iaas/Content/API/Concepts/cliconcepts.htm +[required keys and ocids]: https://docs.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm +[sdk and cli configuration file]: https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm diff --git a/knowledge base/oracle cloud.md b/knowledge base/oracle cloud.md new file mode 100644 index 0000000..8cf80ed --- /dev/null +++ b/knowledge base/oracle cloud.md @@ -0,0 +1,34 @@ +# Oracle Cloud + +1. [Concepts](#concepts) + 1. [Compartments](#compartments) +2. [Further readings](#further-readings) +3. [Sources](#sources) + +## Concepts + +### Compartments + +Compartments are tenancy-wide and extend across regions. They can also be nested to create hierarchies up to 6 levels deep. + +After creating a compartment, you need to write at least one policy for it; until then, no one can access it except administrators or users who have permissions set at the tenancy level. When creating sub-compartments, they inherit access permissions from compartments higher up their hierarchy. + +Before deleting a compartment, all its resources must have been moved, deleted or terminated, including any policies attached to the compartment itself. + +## Further readings + +- [oci-cli] +- [compute images] + +## Sources + +- [Required keys and OCIDs] + + +[compute images]: https://docs.oracle.com/en-us/iaas/images/ +[required keys and ocids]: https://docs.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm + + +[oci-cli]: ./oci-cli.md + + diff --git a/terraform/oracle cloud free tier ampere instance/README.md b/terraform/oracle cloud free tier ampere instance/README.md new file mode 100644 index 0000000..7963113 --- /dev/null +++ b/terraform/oracle cloud free tier ampere instance/README.md @@ -0,0 +1,37 @@ +# Oracle free tier Ampere VM + +Simple example to create an Ampere VM instance in Oracle Cloud's free tier. + +1. [Requirements](#requirements) +2. [Further readings](#further-readings) +3. [Sources](#sources) + +## Requirements + +1. VCN +1. Public Subnet + +For a Subnet to be considered Public, it needs to have associated a Route Table with a default route pointing to an Internet Gateway. + +The default route table created using Terraform does not contain this route, nor it is possible to create the single route in it at the time of writing.
+A solution to this is to create a new Route Table **with** the default route above and attach it to the Subnet. See the code for details. + +![requirements] + +## Further readings + +## Sources + +- [Ridiculously powerful free server in the cloud] +- [Always free resources] in Oracle Cloud +- [Oracle Cloud Infrastructure Provider documentation] +- [oracle-terraform-modules/terraform-oci-compute-instance] + + +[requirements]: design/requirements.png + + +[always free resources]: https://docs.oracle.com/en-us/iaas/Content/FreeTier/freetier_topic-Always_Free_Resources.htm +[oracle cloud infrastructure provider documentation]: https://registry.terraform.io/providers/oracle/oci/latest/docs +[ridiculously powerful free server in the cloud]: https://medium.com/codex/ridiculously-powerful-free-server-in-the-cloud-dd4da8524a9c +[oracle-terraform-modules/terraform-oci-compute-instance]: https://github.com/oracle-terraform-modules/terraform-oci-compute-instance diff --git a/terraform/oracle cloud free tier ampere instance/design/requirements.png b/terraform/oracle cloud free tier ampere instance/design/requirements.png new file mode 100644 index 0000000..6de38b4 Binary files /dev/null and b/terraform/oracle cloud free tier ampere instance/design/requirements.png differ diff --git a/terraform/oracle cloud free tier ampere instance/design/requirements.py b/terraform/oracle cloud free tier ampere instance/design/requirements.py new file mode 100755 index 0000000..e1cd384 --- /dev/null +++ b/terraform/oracle cloud free tier ampere instance/design/requirements.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +from diagrams import Cluster, Diagram +from diagrams.oci.compute import VM +from diagrams.oci.network import InternetGateway, RouteTable, Vcn + +with Diagram("Requirements", show=False): + + vcn = Vcn("VCN") + vm = VM("Ampere instance") + + with Cluster("Public Subnet"): + + ig = InternetGateway("Internet Gateway") + rt = RouteTable("Route Table") + + vcn >> ig >> rt + rt >> vm diff --git a/terraform/oracle cloud free tier ampere instance/example.tfvars b/terraform/oracle cloud free tier ampere instance/example.tfvars new file mode 100644 index 0000000..0bb2d2e --- /dev/null +++ b/terraform/oracle cloud free tier ampere instance/example.tfvars @@ -0,0 +1,14 @@ +availability_domain = "FIXME" # get it with `oci iam availability-domain list` +compartment_id = "FIXME" # get it with `oci iam compartment list` + +memory_in_gbs = 24 +ocpus = 4 + +# get it with `oci compute image list -c 'tenancy_id'` +# or check https://docs.oracle.com/en-us/iaas/images/ +source_id = "ocid1.image.oc1.eu-amsterdam-1.aaaaaaaavmra3s4va4fqd4vlcrqc5v5jyqov5vdla3x3b6gzc64n6dkpuqua" + +ssh_authorized_keys = <