/terraform-oci-networking

Terraform module to Quickstart deploy network resources on OCI and to be reused by other projects

Primary LanguageHCLUniversal Permissive License v1.0UPL-1.0

Terraform Oracle Cloud Infrastructure (OCI) Networking Module


Warning

$${\color{red}This \space is \space a \space pre-release \space version \space of \space the \space module, \space some \space features}$$ $${\color{red}have \space not \space been \space migrated \space from \space MuShop's}$$ $${\color{red}OKE \space Cluster \space deployment \space yet.}$$

Stack Release Stack Build AquaSec TFSec Terraform Stack License Stack Downloads GitHub issues

Terraform module to Quickstart deploy network resources on OCI and to be reused by other projects. This module is designed to be used with the OCI Resource Manager to deploy a cluster in a single step. The module can also be used with the OCI Terraform Provider to deploy a cluster using local or CloudShell Terraform cli.

Usage

There are multiple examples included in the examples folder but simple usage is as follows:

Simple module usage

module "oci-networking" {
  source = "github.com/oracle-quickstart/terraform-oci-networking?ref=0.3.2"

  # Oracle Cloud Infrastructure Tenancy and Compartment OCID
  tenancy_ocid     = var.tenancy_ocid
  compartment_ocid = var.compartment_ocid
  region           = var.region

  # Note: Just few arguments are showing here to simplify the basic example. All other arguments are using default values.
  # App Name to identify deployment. Used for naming resources.
  app_name = "Basic"

  # Freeform Tags + Defined Tags. Tags are applied to all resources.
  tag_values = { "freeformTags" = { "Environment" = "Development", "DeploymentType" = "basic", "QuickstartExample" = "basic-vcn" }, "definedTags" = {} }

  subnets = [
    {
      subnet_name                = "test_subnet"
      cidr_block                 = cidrsubnet("10.0.0.0/16", 8, 35) # e.g.: "10.0.35.0/24" = 254 usable IPs (10.20.35.0 - 10.20.35.255)
      display_name               = "Test subnet (Basic)"
      dns_label                  = null
      prohibit_public_ip_on_vnic = false
      prohibit_internet_ingress  = false
      route_table_id             = ""
      dhcp_options_id            = ""
      security_list_ids          = []
      ipv6cidr_block             = null
    },
  ]
}

Separate each module usage

module "vcn" {
  source = "github.com/oracle-quickstart/terraform-oci-networking//modules/vcn?ref=0.3.2"

  # Oracle Cloud Infrastructure Tenancy and Compartment OCID
  compartment_ocid = var.compartment_ocid

  # Deployment Tags + Freeform Tags + Defined Tags
  vcn_tags = local.oci_tag_values

  # Virtual Cloud Network (VCN) arguments
  create_new_vcn          = true
  existent_vcn_ocid       = ""
  cidr_blocks             = ["10.0.0.0/16"]
  display_name            = "[Example] VCN (Dev)"
  dns_label               = "example123"
  is_ipv6enabled          = false
  ipv6private_cidr_blocks = []
}

module "subnets" {
  for_each = { for map in local.subnets : map.subnet_name => map }
  source   = "github.com/oracle-quickstart/terraform-oci-networking//modules/subnet?ref=0.3.2"

  # Oracle Cloud Infrastructure Tenancy and Compartment OCID
  compartment_ocid = var.compartment_ocid
  vcn_id           = module.vcn.vcn_id

  # Deployment Tags + Freeform Tags + Defined Tags
  subnet_tags = local.oci_tag_values

  # Subnet arguments
  create_subnet              = true
  subnet_name                = each.value.subnet_name
  cidr_block                 = each.value.cidr_block
  display_name               = each.value.display_name # If null, is autogenerated
  dns_label                  = each.value.dns_label    # If null, is autogenerated
  prohibit_public_ip_on_vnic = each.value.prohibit_public_ip_on_vnic
  prohibit_internet_ingress  = each.value.prohibit_internet_ingress
  route_table_id             = each.value.route_table_id    # If null, the VCN's default route table is used
  dhcp_options_id            = each.value.dhcp_options_id   # If null, the VCN's default set of DHCP options is used
  security_list_ids          = each.value.security_list_ids # If null, the VCN's default security list is used
  ipv6cidr_block             = each.value.ipv6cidr_block    # If null, no IPv6 CIDR block is assigned
}

locals {
  oci_tag_values = {
    "freeformTags" = {"CreatedBy" = "Terraform"},
    "definedTags"  = {}
  }
  subnets = [
    {
      subnet_name                = "test_subnet"
      cidr_block                 = cidrsubnet("10.0.0.0/16", 8, 35) # e.g.: "10.0.35.0/24" = 254 usable IPs (10.20.35.0 - 10.20.35.255)
      display_name               = "Test subnet (Dev)"
      dns_label                  = ""
      prohibit_public_ip_on_vnic = false
      prohibit_internet_ingress  = false
      route_table_id             = "" # module.route_tables["public"].route_table_id
      dhcp_options_id            = module.vcn.default_dhcp_options_id
      security_list_ids          = [] # [module.security_lists["test_security_list"].security_list_id]
      ipv6cidr_block             = null
    },
  ]
}

How is this Terraform Module versioned?

This Terraform Module follows the principles of Semantic Versioning. You can find each new release, along with the changelog, in the Releases Page.

During initial development, the major version will be 0 (e.g., 0.x.y), which indicates the code does not yet have a stable API. Once we hit 1.0.0, we will make every effort to maintain a backwards compatible API and use the MAJOR, MINOR, and PATCH versions on each release to indicate any incompatibilities.

Questions

If you have an issue or a question, please take a look at our FAQs or open an issue.

Contributing

This project welcomes contributions from the community. Before submitting a pull request, see CONTRIBUTING for details.

License

Copyright (c) 2022 Oracle and/or its affiliates. Released under the Universal Permissive License (UPL), Version 1.0. See LICENSE for more details.