Skip to content

Commit

Permalink
introduce flexshape
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Oehrli committed Feb 18, 2021
1 parent c878221 commit 3e8bc75
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 69 deletions.
23 changes: 14 additions & 9 deletions compute.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@ resource "oci_core_instance" "compute" {

metadata = {
ssh_authorized_keys = var.ssh_public_key != "" ? var.ssh_public_key : file(var.ssh_public_key_path)
user_data = var.host_bootstrap != "" ? var.host_bootstrap : base64encode(templatefile(local.host_bootstrap_template, {
yum_upgrade = var.yum_upgrade
authorized_keys = base64gzip(file(local.ssh_public_key_path))
etc_hosts = base64gzip(file(local.hosts_file))
bootstrap_windows_host = local.bootstrap_windows_host
bootstrap_linux_host = local.bootstrap_linux_host
}))
user_data = var.host_bootstrap != "" ? var.host_bootstrap : base64encode(templatefile(local.host_bootstrap_template, {
yum_upgrade = var.yum_upgrade
authorized_keys = base64gzip(file(local.ssh_public_key_path))
etc_hosts = base64gzip(file(local.hosts_file))
bootstrap_windows_host = local.bootstrap_windows_host
bootstrap_linux_host = local.bootstrap_linux_host
}))
}


shape_config {
memory_in_gbs = var.host_memory_in_gbs
ocpus = var.host_ocpus
}

source_details {
source_type = "image"
source_id = local.host_image_id
Expand All @@ -57,4 +62,4 @@ resource "oci_core_instance" "compute" {
create = "60m"
}
}
# --- EOF -------------------------------------------------------------------
# --- EOF -------------------------------------------------------------------
217 changes: 167 additions & 50 deletions examples/linux/additional_linux_host.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,91 +18,206 @@
# ---------------------------------------------------------------------------
# - Variables
# ---------------------------------------------------------------------------
variable "linux_host_enabled" {
# ---------------------------------------------------------------------------
# Trivadis AG, Infrastructure Managed Services
# Saegereistrasse 29, 8152 Glattbrugg, Switzerland
# ---------------------------------------------------------------------------
# Name.......: variables.tf
# Author.....: Stefan Oehrli (oes) [email protected]
# Editor.....: Stefan Oehrli
# Date.......: 2020.10.12
# Revision...:
# Purpose....: Variable file for the terraform module tvdlab compute.
# Notes......: --
# Reference..: --
# License....: Apache License Version 2.0, January 2004 as shown
# at http://www.apache.org/licenses/
# ---------------------------------------------------------------------------

# provider identity parameters ----------------------------------------------
variable "tenancy_ocid" {
description = "tenancy id where to create the resources"
type = string
}

variable "region" {
# List of regions: https://docs.cloud.oracle.com/iaas/Content/General/Concepts/regions.htm#ServiceAvailabilityAcrossRegions
description = "The OCI region where resources will be created"
type = string
}

# general oci parameters ----------------------------------------------------
variable "compartment_id" {
description = "OCID of the compartment where to create all resources"
type = string
}

variable "label_prefix" {
description = "A string that will be prepended to all resources"
type = string
default = "none"
}

variable "resource_name" {
description = "user-friendly string to name all resource. If undefined it will be derived from compartment name. "
type = string
default = ""
}

variable "ad_index" {
description = "The index of the availability domain. This is used to identify the availability_domain place the compute instances."
default = 1
type = number
}

variable "tags" {
description = "A simple key-value pairs to tag the resources created"
type = map(any)
default = {}
}

# Host Parameter ----------------------------------------------------
variable "host_enabled" {
description = "whether to create the compute instance or not."
default = false
default = true
type = bool
}

variable "linux_host_name" {
variable "host_name" {
description = "Name portion of host"
default = "linux"
default = "host"
type = string
}

variable "linux_host_public_ip" {
variable "host_public_ip" {
description = "whether to assigne a public IP or not."
default = false
type = bool
}

variable "linux_host_private_ip" {
variable "host_private_ip" {
description = "Private IP for host."
default = "10.0.1.7"
default = "10.0.1.6"
type = string
}

variable "linux_host_image_id" {
variable "host_image_id" {
description = "Provide a custom image id for the host or leave as OEL (Oracle Enterprise Linux)."
default = "OEL"
type = string
}

variable "linux_host_os" {
description = "Base OS for Linux based OS."
variable "host_os" {
description = "Base OS for the host."
default = "Oracle Linux"
type = string
}

variable "linux_host_os_version" {
description = "Define the default OS version for Oracle Linux."
variable "host_os_version" {
description = "Define Base OS version for the host."
default = "7.8"
type = string
}

variable "linux_host_shape" {
description = "The shape of compute instance."
default = "VM.Standard2.2"
variable "hosts_file" {
description = "path to a custom /etc/hosts which has to be appended"
default = ""
type = string
}

variable "yum_upgrade" {
description = "Enable YUM upgrade during bootstrap / cloud-init"
default = true
type = bool
}

variable "host_shape" {
description = "The shape of admin instance."
default = "VM.Standard.E3.Flex"
type = string
}

variable "linux_host_boot_volume_size" {
variable "host_ocpus" {
description = "The ocpus for the shape."
default = 1
type = number
}

variable "host_memory_in_gbs" {
description = "The memory in gbs for the shape."
default = 8
type = number
}

variable "host_boot_volume_size" {
description = "Size of the boot volume."
default = 150
type = number
}

variable "linux_volume_enabled" {
variable "host_volume_enabled" {
description = "whether to create an additional volume or not."
default = false
type = bool
}

variable "linux_volume_attachment_type" {
variable "host_volume_attachment_type" {
description = "The type of volume."
default = "paravirtualized"
type = string
}

variable "linux_volume_size" {
variable "host_volume_size" {
description = "Size of the additional volume."
default = 256
type = number
}

variable "linux_host_state" {
variable "host_state" {
description = "Whether the host should be either RUNNING or STOPPED state. "
default = "RUNNING"
}

variable "linux_host_bootstrap" {
variable "host_bootstrap" {
description = "Bootstrap script."
default = ""
type = string
}

variable "host_subnet" {
description = "List of subnets for the host hosts"
type = list(string)
}

variable "ssh_public_key" {
description = "the content of the ssh public key used to access the host. set this or the ssh_public_key_path"
default = ""
type = string
}

variable "ssh_public_key_path" {
description = "path to the ssh public key used to access the host. set this or the ssh_public_key"
default = ""
type = string
}

# Trivadis LAB specific parameter -------------------------------------------
variable "tvd_participants" {
description = "The number of VCN to create"
type = number
default = 1
}

variable "tvd_domain" {
description = "The domain name of the LAB environment"
type = string
default = "trivadislabs.com"
}
# --- EOF -------------------------------------------------------------------


locals {
linux_host_state = var.tvd_training_state == "" ? var.linux_host_state : var.tvd_training_state
linux_host_state = var.tvd_training_state == "" ? var.linux_host_state : var.tvd_training_state
}

# ---------------------------------------------------------------------------
Expand All @@ -118,56 +233,58 @@ module "tvdlab-linux-host" {
version = ">= 1.0.0"

# - Mandatory Parameters --------------------------------------------------
tenancy_ocid = var.tenancy_ocid
region = var.region
compartment_id = local.compartment_id
tenancy_ocid = var.tenancy_ocid
region = var.region
compartment_id = local.compartment_id
# either ssh_public_key or ssh_public_key_path must be specified
ssh_public_key = var.ssh_public_key
ssh_public_key_path = var.ssh_public_key_path
host_subnet = module.tvdlab-base.private_subnet_id
ssh_public_key = var.ssh_public_key
ssh_public_key_path = var.ssh_public_key_path
host_subnet = module.tvdlab-base.private_subnet_id

# - Optional Parameters ---------------------------------------------------
# general oci parameters
ad_index = var.ad_index
label_prefix = var.label_prefix
tags = var.tags
ad_index = var.ad_index
label_prefix = var.label_prefix
tags = var.tags

# Lab Configuration
resource_name = var.resource_name
tvd_domain = var.tvd_domain
tvd_participants = var.tvd_participants
resource_name = var.resource_name
tvd_domain = var.tvd_domain
tvd_participants = var.tvd_participants

# host parameters
host_enabled = var.linux_host_enabled
host_name = var.linux_host_name
host_image_id = var.linux_host_image_id
host_shape = var.linux_host_shape
host_bootstrap = var.linux_host_bootstrap
host_state = local.linux_host_state
host_public_ip = var.linux_host_public_ip
host_private_ip = var.linux_host_private_ip
host_os = var.linux_host_os
host_os_version = var.linux_host_os_version
host_boot_volume_size = var.linux_host_boot_volume_size
host_volume_enabled = var.linux_volume_enabled
host_enabled = var.linux_host_enabled
host_name = var.linux_host_name
host_image_id = var.linux_host_image_id
host_shape = var.linux_host_shape
host_ocpus = var.host_ocpus
host_memory_in_gbs = var.host_memory_in_gbs
host_bootstrap = var.linux_host_bootstrap
host_state = local.linux_host_state
host_public_ip = var.linux_host_public_ip
host_private_ip = var.linux_host_private_ip
host_os = var.linux_host_os
host_os_version = var.linux_host_os_version
host_boot_volume_size = var.linux_host_boot_volume_size
host_volume_enabled = var.linux_volume_enabled
host_volume_attachment_type = var.linux_volume_attachment_type
host_volume_size = var.linux_volume_size
host_volume_size = var.linux_volume_size
}
# ---------------------------------------------------------------------------
# - Outputs
# ---------------------------------------------------------------------------
output "linux_host_id" {
description = "OCID of the server instances."
value = module.tvdlab-db2.host_id
value = module.tvdlab-db2.host_id
}

output "linux_host_name" {
description = "The hostname for VNIC's primary private IP of the server instances."
value = module.tvdlab-db2.host_name
value = module.tvdlab-db2.host_name
}

output "linux_host_private_ip" {
description = "The private IP address of the server instances."
value = module.tvdlab-db2.host_private_ip
value = module.tvdlab-db2.host_private_ip
}
# --- EOF -------------------------------------------------------------------
6 changes: 3 additions & 3 deletions examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ module "tvdlab-compute" {

# - Optional Parameters ---------------------------------------------------
# general oci parameters
ad_index = var.ad_index
label_prefix = var.label_prefix
tags = var.tags
ad_index = var.ad_index
label_prefix = var.label_prefix
tags = var.tags

# Lab Configuration
resource_name = var.resource_name
Expand Down
2 changes: 1 addition & 1 deletion locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ locals {
host_image_id = var.host_image_id == "CENTOS" || var.host_image_id == "OEL" || var.host_image_id == "WIN" ? data.oci_core_images.oracle_images.images.0.id : var.host_image_id
hosts_file = var.hosts_file == "" ? "${path.module}/etc/hosts.template" : var.hosts_file
ssh_public_key_path = var.ssh_public_key_path == "" ? "${path.module}/etc/authorized_keys.template" : var.ssh_public_key_path
host_bootstrap_template = var.host_os == "Windows" ? "${path.module}/cloudinit/windows_host.yaml" : "${path.module}/cloudinit/linux_host.yaml"
host_bootstrap_template = var.host_os == "Windows" ? "${path.module}/cloudinit/windows_host.yaml" : "${path.module}/cloudinit/linux_host.yaml"
bootstrap_windows_host = base64gzip(file("${path.module}/scripts/bootstrap_windows_host.template.ps1"))
bootstrap_linux_host = base64gzip(file("${path.module}/scripts/bootstrap_linux_host.template.sh"))
}
Expand Down
Loading

0 comments on commit 3e8bc75

Please sign in to comment.