From 3e8bc753b1a29c4960251181ae2a22c7efac655d Mon Sep 17 00:00:00 2001 From: Stefan Oehrli Date: Thu, 18 Feb 2021 22:21:14 +0100 Subject: [PATCH] introduce flexshape --- compute.tf | 23 ++- examples/linux/additional_linux_host.tf | 217 ++++++++++++++++++------ examples/main.tf | 6 +- locals.tf | 2 +- outputs.tf | 8 +- variables.tf | 16 +- 6 files changed, 203 insertions(+), 69 deletions(-) diff --git a/compute.tf b/compute.tf index b46da32..c1c47f7 100644 --- a/compute.tf +++ b/compute.tf @@ -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 @@ -57,4 +62,4 @@ resource "oci_core_instance" "compute" { create = "60m" } } -# --- EOF ------------------------------------------------------------------- \ No newline at end of file +# --- EOF ------------------------------------------------------------------- diff --git a/examples/linux/additional_linux_host.tf b/examples/linux/additional_linux_host.tf index 9f920e7..95c6776 100644 --- a/examples/linux/additional_linux_host.tf +++ b/examples/linux/additional_linux_host.tf @@ -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) stefan.oehrli@trivadis.com +# 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 } # --------------------------------------------------------------------------- @@ -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 ------------------------------------------------------------------- diff --git a/examples/main.tf b/examples/main.tf index 5a7dc5d..0f94507 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -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 diff --git a/locals.tf b/locals.tf index e5edc53..4809514 100644 --- a/locals.tf +++ b/locals.tf @@ -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")) } diff --git a/outputs.tf b/outputs.tf index e253f5d..98f053e 100644 --- a/outputs.tf +++ b/outputs.tf @@ -17,22 +17,22 @@ # display public IPs output "host_id" { description = "OCID of the server instances." - value = oci_core_instance.compute.*.id + value = oci_core_instance.compute.*.id } output "host_name" { description = "The hostname for VNIC's primary private IP of the server instances." - value = oci_core_instance.compute.*.hostname_label + value = oci_core_instance.compute.*.hostname_label } output "host_public_ip" { description = "The public IP address of the server instances." - value = oci_core_instance.compute.*.public_ip + value = oci_core_instance.compute.*.public_ip } output "host_private_ip" { description = "The private IP address of the server instances." - value = oci_core_instance.compute.*.private_ip + value = oci_core_instance.compute.*.private_ip } # --- EOF ------------------------------------------------------------------- \ No newline at end of file diff --git a/variables.tf b/variables.tf index 31d499c..73ca7c6 100644 --- a/variables.tf +++ b/variables.tf @@ -112,11 +112,23 @@ variable "yum_upgrade" { } variable "host_shape" { - description = "The shape of compute instance." - default = "VM.Standard2.2" + description = "The shape of admin instance." + default = "VM.Standard.E3.Flex" type = string } +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