Giter Site home page Giter Site logo

terraform-oci-cloudbricks-linux-compute's Introduction

OCI Cloud Bricks: Linux Compute Instance

License: UPL Quality gate

Introduction

The following cloud brick enables you to create batches of linux computes, starting from 1 to many associated to a specific compartment and specific subnet.

Reference Architecture

The following is the reference architecture associated to this brick

Reference Architecture

In this case, you can take advantage of the decoupled nature of the network compartment and the artifact compartment for cost tracking purposes.

Prerequisites

  • Pre existent Compartment structure
  • Pre existent VCN, Subnet and NSG (if applies)

Sample tfvar file

If Flex Shape is in use

########## FLEX SHAPE IN USE ##########
########## SAMPLE TFVAR FILE ##########
########## PROVIDER SPECIFIC VARIABLES ##########
region           = "foo-region-1"
tenancy_ocid     = "ocid1.tenancy.oc1..abcdefg"
user_ocid        = "ocid1.user.oc1..aaaaaaabcdefg"
fingerprint      = "fo:oo:ba:ar:ba:ar"
private_key_path = "/absolute/path/to/api/key/your_api_key.pem"
########## PROVIDER SPECIFIC VARIABLES ##########


########## ARTIFACT SPECIFIC VARIABLES ##########****
ssh_public_key                   = "./relative/path/to/ssh/key/public_ssh_key.pub"
ssh_private_key                  = "./relative/path/to/ssh/key/private_ssh_key"
ssh_public_is_path               = true
ssh_private_is_path              = true
compute_availability_domain_list = ["aBCD:foo-REGION-1-AD-1", "aBCD:foo-REGION-1-AD-2","aBCD:foo-REGION-1-AD-3" ]

network_subnet_name                     = "My_Subnet"
assign_public_ip_flag                   = true
fault_domain_name                       = ["FAULT-DOMAIN-1", "FAULT-DOMAIN-2", "FAULT-DOMAIN-3"]
bkp_policy_boot_volume                  = "gold"
linux_compute_instance_compartment_name = "MY_ARTIFACT_COMPARTMENT"
linux_compute_network_compartment_name  = "MY_NETWORK_COMPARTMENT"
vcn_display_name                        = "MY_VCN"
num_instances                           = 1
is_nsg_required                         = true
compute_nsg_name                        = "My_NSG"
compute_display_name_base               = "lnxmachine"
instance_image_ocid                     = "ocid1.image.oc1.sa-santiago-1.aaaaaaaa4wkfbnujci2u7tfm2eqhliuunxy2hwesmf5kwsclpamf4xgqs2wa" #Image: Oracle-Autonomous-Linux-7.9-2021.04-0
instance_shape                          = "VM.Standard.E4.Flex"
is_flex_shape                           = true
instance_shape_config_ocpus             = 1
instance_shape_config_memory_in_gbs     = 16
########## ARTIFACT SPECIFIC VARIABLES ##########
########## SAMPLE TFVAR FILE ##########
########## FLEX SHAPE IN USE ##########

If flex shape is not in use

########## FLEX SHAPE NOT IN USE ##########
########## SAMPLE TFVAR FILE ##########
########## PROVIDER SPECIFIC VARIABLES ##########
region           = "foo-region-1"
tenancy_ocid     = "ocid1.tenancy.oc1..abcdefg"
user_ocid        = "ocid1.user.oc1..aaaaaaabcdefg"
fingerprint      = "fo:oo:ba:ar:ba:ar"
private_key_path = "/absolute/path/to/api/key/your_api_key.pem"
########## PROVIDER SPECIFIC VARIABLES ##########


########## ARTIFACT SPECIFIC VARIABLES ##########****
ssh_public_key                   = "./relative/path/to/ssh/key/public_ssh_key.pub"
ssh_private_key                  = "./relative/path/to/ssh/key/private_ssh_key"
ssh_public_is_path               = true
ssh_private_is_path              = true
compute_availability_domain_list = ["aBCD:foo-REGION-1-AD-1", "aBCD:foo-REGION-1-AD-2","aBCD:foo-REGION-1-AD-3" ]

network_subnet_name                     = "My_Subnet"
assign_public_ip_flag                   = true
fault_domain_name                       = ["FAULT-DOMAIN-1", "FAULT-DOMAIN-2", "FAULT-DOMAIN-3"]
bkp_policy_boot_volume                  = "gold"
linux_compute_instance_compartment_name = "MY_INSTANCE_COMPARTMENT"
linux_compute_network_compartment_name  = "MY_NETWORK_COMPARTMENT"
vcn_display_name                        = "MY_VCN"
num_instances                           = 1
is_nsg_required                         = true
compute_nsg_name                        = "My_NSG"
compute_display_name_base               = "lnxmachine"
instance_image_ocid                     = "ocid1.image.oc1.sa-santiago-1.aaaaaaaa4wkfbnujci2u7tfm2eqhliuunxy2hwesmf5kwsclpamf4xgqs2wa" #Image: Oracle-Autonomous-Linux-7.9-2021.04-0
instance_shape                          = "VM.Standard2.1"
########## ARTIFACT SPECIFIC VARIABLES ##########
########## SAMPLE TFVAR FILE ##########
########## FLEX SHAPE NOT IN USE ##########

Variable specific considerations

  • Specific SSH Keys can be used for creating compute in batches. These can be included inside the same system from where brick module is being used.
  • Is possible to use as many AD as are available on the region currently in use. These can be passed on separated by commas and enclosed by double quotes
  • Any boot volume backup policy available in your tenancy can be used, whereas this can be default or a custom one
  • The number of instances can be overriden by providing a number on variable num_instances. This variable can never be less than 1
  • NSG creation is optonal. If NSG is required or not for your instance. If NSG is required for instance, provide variable is_nsg_required as true and pass on an NSG Name on variable compute_nsg_name. Otherwise, set is_nsg_required as false and either drop/delete the variable compute_nsg_name or blank it out by passing "" as argument
  • A full OCID of the image wanted to be used to create compute is required. A full list of OCID is available in the following link
  • If FLEX image is required, variable is_flex_shape should be set to true
    • Mandatory instance_shape_config_ocpu and instance_shape_config_memory_in_gbs are required when flex image is in use
    • If instance_shape is not flex, variable is_flex_shape should be set to false and then drop the usage of instance_shape_config_ocpu and instance_shape_config_memory_in_gbs variables by drop/delete or passing out "" as argument

Sample provider

The following is the base provider definition to be used with this module

terraform {
  required_version = ">= 0.13.5"
}
provider "oci" {
  region       = var.region
  tenancy_ocid = var.tenancy_ocid
  user_ocid        = var.user_ocid
  fingerprint      = var.fingerprint
  private_key_path = var.private_key_path
  disable_auto_retries = "true"
}

provider "oci" {
  alias        = "home"
  region       = data.oci_identity_region_subscriptions.home_region_subscriptions.region_subscriptions[0].region_name
  tenancy_ocid = var.tenancy_ocid  
  user_ocid        = var.user_ocid
  fingerprint      = var.fingerprint
  private_key_path = var.private_key_path
  disable_auto_retries = "true"
}

Variable documentation

Requirements

Name Version
terraform >= 0.13.5

Providers

Name Version
oci 4.35.0
oci.home 4.35.0
random 3.1.0

Modules

No modules.

Resources

Name Type
oci_core_instance.Compute resource
oci_core_volume_backup_policy_assignment.backup_policy_assignment_BootVolume resource
oci_identity_tag.release resource
oci_identity_tag_namespace.devrel resource
random_id.tag resource
oci_core_network_security_groups.NSG data source
oci_core_subnets.SUBNET data source
oci_core_vcns.VCN data source
oci_core_volume_backup_policies.BACKUPPOLICYBOOTVOL data source
oci_identity_compartments.COMPARTMENTS data source
oci_identity_compartments.NWCOMPARTMENTS data source
oci_identity_region_subscriptions.home_region_subscriptions data source

Inputs

Name Description Type Default Required
assign_public_ip_flag Defines either machine will have or not a Public IP assigned. All Pvt networks this variable must be false bool false no
bkp_policy_boot_volume Describes the backup policy attached to the boot volume string "gold" no
compute_availability_domain_list Defines the availability domain list where OCI artifact will be created. This is a numeric value greater than 0 list(any) n/a yes
compute_display_name_base Defines the compute and hostname Label for created compute any n/a yes
compute_nsg_name Name of the NSG associated to the compute any n/a yes
fault_domain_name Describes the fault domain to be used by machine list(any)
[
"FAULT-DOMAIN-1",
"FAULT-DOMAIN-2",
"FAULT-DOMAIN-3"
]
no
fingerprint API Key Fingerprint for user_ocid derived from public API Key imported in OCI User config any n/a yes
instance_image_ocid Defines the OCID for the OS image to be used on artifact creation. Extract OCID from: https://docs.cloud.oracle.com/iaas/images/ or designated custom image OCID created by packer any n/a yes
instance_shape Defines the shape to be used on compute creation any n/a yes
instance_shape_config_memory_in_gbs (Updatable) The total amount of memory available to the instance, in gigabytes. string "" no
instance_shape_config_ocpus (Updatable) The total number of OCPUs available to the instance. string "" no
is_flex_shape Boolean that describes if the shape is flex or not bool false no
is_nsg_required Boolean that describes if an NSG is associated to the machine bool false no
label_zs Auxiliary variable to concatenate with compute number list(any)
[
"0",
""
]
no
linux_compute_instance_compartment_name Defines the compartment name where the infrastructure will be created any n/a yes
linux_compute_network_compartment_name Defines the compartment where the Network is currently located any n/a yes
network_subnet_name Defines the subnet display name where this resource will be created at any n/a yes
num_instances Amount of instances to create number 0 no
primary_vnic_display_name Defines the Primary VNIC Display Name string "primaryvnic" no
private_ip Describes the private IP required for machine any null no
private_key_path Private Key Absolute path location where terraform is executed any n/a yes
region Target region where artifacts are going to be created any n/a yes
ssh_private_is_path Describes if SSH Private Key is located on file or inside code bool false no
ssh_private_key Private key to log into machine any n/a yes
ssh_public_is_path Describes if SSH Public Key is located on file or inside code bool false no
ssh_public_key Defines SSH Public Key to be used in order to remotely connect to compute instance string n/a yes
tenancy_ocid OCID of tenancy any n/a yes
user_ocid User OCID in tenancy. any n/a yes
vcn_display_name VCN Display name to execute lookup any n/a yes

Outputs

Name Description
instance Compute Generated
instance_private_ip Compute Private IP
server_display_name Compute Display Name

Contributing

This project is open source. Please submit your contributions by forking this repository and submitting a pull request! Oracle appreciates any contributions that are made by the open source community.

License

Copyright (c) 2021 Oracle and/or its affiliates.

Licensed under the Universal Permissive License (UPL), Version 1.0.

See LICENSE for more details.

terraform-oci-cloudbricks-linux-compute's People

Contributors

djukickosta avatar dralquinta avatar matt-mcl avatar timclegg avatar ttscoff avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.