From 05250552fc9fc18a5f6883fdac73bdc6a876a9aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87etin=20ARDAL?= Date: Mon, 15 Feb 2021 12:26:53 +0100 Subject: [PATCH 1/2] prepare next PR - update CHANGELOG for new feature - add repo housekeeping options (pre-commit hooks, gitattributes) --- .gitattributes | 3 +++ .pre-commit-config.yaml | 16 ++++++++++++++++ CHANGELOG.md | 9 +++++++++ 3 files changed, 28 insertions(+) create mode 100644 .gitattributes create mode 100644 .pre-commit-config.yaml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..42aae75 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +*.txt text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=4 +*.md text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=4 +*.tf text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..b02f2ec --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,16 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.4.0 # Get the latest from: https://github.com/pre-commit/pre-commit-hooks/releases + hooks: + - id: trailing-whitespace + args: [--markdown-linebreak-ext=md] +- repo: https://github.com/gruntwork-io/pre-commit + rev: v0.1.12 # Get the latest from: https://github.com/gruntwork-io/pre-commit/releases + hooks: + - id: terraform-validate + # - id: terraform-fmt #* this version of tf-fmt detect problem and fails. You have to run tf fmt yourself +- repo: https://github.com/antonbabenko/pre-commit-terraform + rev: v1.45.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases + hooks: + - id: terraform_docs + - id: terraform_fmt #* this version of tf-fmt actually runs fmt and fix files \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f9d00cf..a96c85e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,15 @@ Given a version number MAJOR.MINOR.PATCH: ## [UNRELEASED] +Features: + +- add Flex instance shape support + +Repo maintenance: + +- add .gitattributes for consistent line ending and tab +- add pre-commit configuration file + ## 2.0.4 - 2021-02-13 ### Changed From 58cfc57825e07b9819e1b0c58bf78a8851751385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87etin=20ARDAL?= Date: Tue, 16 Feb 2021 22:34:04 +0100 Subject: [PATCH 2/2] Add support for Flex instance shape Add new output: instances_summary Fix outputs (Issue #31) --- CHANGELOG.md | 9 ++- README.md | 3 + examples/instance_default/README.md | 9 +-- examples/instance_default/instance_default.tf | 62 +++++++++++++++++-- examples/instance_default/outputs.tf | 28 ++++----- main.tf | 29 +++++++++ outputs.tf | 27 ++++++-- variables.tf | 12 ++++ 8 files changed, 145 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a96c85e..414406e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,14 @@ Given a version number MAJOR.MINOR.PATCH: ## [UNRELEASED] -Features: +Added: -- add Flex instance shape support +- support Flex instance shape +- new output : instances_summary + +Fixed: + +- Outputs produces unnecessarily multidimensional objects (Issue #31) Repo maintenance: diff --git a/README.md b/README.md index 9a036f4..702406f 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ module "instance" { | hostname\_label | The hostname for the VNIC's primary private IP. | `string` | `""` | no | | instance\_count | Number of instances to launch. | `number` | `1` | no | | instance\_display\_name | (Optional) (Updatable) A user-friendly name for the instance. Does not have to be unique, and it's changeable. | `string` | `""` | no | +| instance\_flex\_memory\_in\_gbs | (Optional) (Updatable) The total amount of memory available to the instance, in gigabytes. | `number` | `null` | no | +| instance\_flex\_ocpus | (Optional) (Updatable) The total number of OCPUs available to the instance. | `number` | `null` | no | | instance\_timeout | Timeout setting for creating instance. | `string` | `"25m"` | no | | ipxe\_script | (Optional) The iPXE script which to continue the boot process on the instance. | `string` | `null` | no | | preserve\_boot\_volume | Specifies whether to delete or preserve the boot volume when terminating an instance. | `bool` | `false` | no | @@ -82,6 +84,7 @@ module "instance" { | instance\_id | ocid of created instances. | | instance\_password | Passwords to login to Windows instance. | | instance\_username | Usernames to login to Windows instance. | +| instances\_summary | Private and Public IPs for each instance. | | private\_ip | Private IPs of created instances. | | public\_ip | Public IPs of created instances. | diff --git a/examples/instance_default/README.md b/examples/instance_default/README.md index a1db9e7..6ca7de6 100644 --- a/examples/instance_default/README.md +++ b/examples/instance_default/README.md @@ -1,3 +1,4 @@ + ## Create Compute Instance This example creates a compute instance and a set of block volumes. @@ -30,8 +31,8 @@ block_storage_sizes_in_gbs = [60, 70] Then apply the example using the following commands: -``` -$ terraform init -$ terraform plan -$ terraform apply +```shell +> terraform init +> terraform plan +> terraform apply ``` diff --git a/examples/instance_default/instance_default.tf b/examples/instance_default/instance_default.tf index defb19f..9247228 100644 --- a/examples/instance_default/instance_default.tf +++ b/examples/instance_default/instance_default.tf @@ -45,7 +45,8 @@ variable "block_storage_sizes_in_gbs" { } variable "shape" { - type = string + type = string + default = null } variable "assign_public_ip" { @@ -64,16 +65,67 @@ provider "oci" { region = var.region } -module "instance" { +# * This module will create a Flex Compute Instance, using default values: 1 OCPU, 16 GB memory. +module "instance_flex" { source = "../../" - instance_count = var.instance_count + instance_count = 1 + shape = "VM.Standard.E3.Flex" ad_number = 1 compartment_ocid = var.compartment_ocid - instance_display_name = var.instance_display_name + instance_display_name = "instance_flex" + source_ocid = var.source_ocid + subnet_ocids = var.subnet_ocids + ssh_authorized_keys = var.ssh_authorized_keys + block_storage_sizes_in_gbs = var.block_storage_sizes_in_gbs + assign_public_ip = var.assign_public_ip +} + +# * This module will create a Flex Compute Instance, using values provided by the module: 1 OCPU, 1 GB memory. +module "instance_flex_custom" { + source = "../../" + instance_count = 2 + shape = "VM.Standard.E3.Flex" + instance_flex_memory_in_gbs = 1 + instance_flex_ocpus = 1 + ad_number = 1 + compartment_ocid = var.compartment_ocid + instance_display_name = "instance_flex_custom" + source_ocid = var.source_ocid + subnet_ocids = var.subnet_ocids + ssh_authorized_keys = var.ssh_authorized_keys + block_storage_sizes_in_gbs = var.block_storage_sizes_in_gbs + assign_public_ip = var.assign_public_ip +} + +# * This module will create a shape-based Compute Instance. OCPU and memory values are defined by the shape. +module "instance_nonflex" { + source = "../../" + instance_count = 1 + shape = "VM.Standard2.1" + ad_number = 2 + compartment_ocid = var.compartment_ocid + instance_display_name = "instance_nonflex" source_ocid = var.source_ocid subnet_ocids = var.subnet_ocids ssh_authorized_keys = var.ssh_authorized_keys block_storage_sizes_in_gbs = var.block_storage_sizes_in_gbs - shape = var.shape assign_public_ip = var.assign_public_ip } + +# * This module will create a shape-based Compute instance. OCPU and memory values are defined by the shape. +# * `instance_flex_memory_in_gbs` and ìnstance_flex_ocpus` values are ignored. +module "instance_nonflex_custom" { + source = "../../" + instance_count = 1 + shape = "VM.Standard2.1" + instance_flex_memory_in_gbs = 8 + instance_flex_ocpus = 1 + ad_number = 2 + compartment_ocid = var.compartment_ocid + instance_display_name = "instance_nonflex_custom" + source_ocid = var.source_ocid + subnet_ocids = var.subnet_ocids + ssh_authorized_keys = var.ssh_authorized_keys + block_storage_sizes_in_gbs = var.block_storage_sizes_in_gbs + assign_public_ip = var.assign_public_ip +} diff --git a/examples/instance_default/outputs.tf b/examples/instance_default/outputs.tf index e66968e..ea8c121 100644 --- a/examples/instance_default/outputs.tf +++ b/examples/instance_default/outputs.tf @@ -1,27 +1,21 @@ // Copyright (c) 2018, 2021 Oracle and/or its affiliates. -output "instance_id" { +output "instance_flex" { description = "ocid of created instances. " - value = module.instance.instance_id + value = module.instance_flex.instances_summary } -output "private_ip" { - description = "Private IPs of created instances. " - value = module.instance.private_ip -} - -output "public_ip" { - description = "Public IPs of created instances. " - value = module.instance.public_ip +output "instance_flex_custom" { + description = "ocid of created instances. " + value = module.instance_flex_custom.instances_summary } -output "instance_username" { - description = "Usernames to login to Windows instance. " - value = module.instance.instance_username +output "instance_nonflex" { + description = "ocid of created instances. " + value = module.instance_nonflex.instances_summary } -output "instance_password" { - description = "Passwords to login to Windows instance. " - sensitive = true - value = module.instance.instance_password +output "instance_nonflex_custom" { + description = "ocid of created instances. " + value = module.instance_nonflex_custom.instances_summary } diff --git a/main.tf b/main.tf index 82c0a94..2fe6bfc 100644 --- a/main.tf +++ b/main.tf @@ -29,6 +29,29 @@ data "oci_core_subnet" "this" { subnet_id = element(var.subnet_ocids, count.index) } +############ +# Shapes +############ + +// Create a data source for compute shapes. +// Filter on AD1 to remove duplicates. This should give all the shapes supported on the region. +// This will not check quota and limits for AD requested at resource creation +data "oci_core_shapes" "ad1" { + compartment_id = var.compartment_ocid + availability_domain = local.ADs[0] +} + +locals { + shapes_config = { + // Iterate through data.oci_core_shapes.ad1.shapes and create a map { name = { memory_in_gbs = "xx"; ocpus = "xx" } } + for i in data.oci_core_shapes.ad1.shapes : i.name => { + "memory_in_gbs" = i.memory_in_gbs + "ocpus" = i.ocpus + } + } + shape_is_flex = length(regexall("^*.Flex", var.shape)) > 0 +} + ############ # Instance ############ @@ -42,6 +65,12 @@ resource "oci_core_instance" "this" { ipxe_script = var.ipxe_script preserve_boot_volume = var.preserve_boot_volume shape = var.shape + shape_config { + // If shape name contains ".Flex" and instance_flex inputs are not null, use instance_flex inputs values for shape_config block + // Else use values from data.oci_core_shapes.ad1 for var.shape + memory_in_gbs = local.shape_is_flex == true && var.instance_flex_memory_in_gbs != null ? var.instance_flex_memory_in_gbs : local.shapes_config[var.shape]["memory_in_gbs"] + ocpus = local.shape_is_flex == true && var.instance_flex_ocpus != null ? var.instance_flex_ocpus : local.shapes_config[var.shape]["ocpus"] + } create_vnic_details { assign_public_ip = var.assign_public_ip diff --git a/outputs.tf b/outputs.tf index cdaf196..8568744 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,28 +1,43 @@ // Copyright (c) 2018, 2021, Oracle and/or its affiliates. +locals { + instances_details = [ + // display name, Primary VNIC Public/Private IP for each instance + for i in oci_core_instance.this : <