diff --git a/terraform/.terraform.lock.hcl b/terraform/.terraform.lock.hcl new file mode 100644 index 0000000..57720c6 --- /dev/null +++ b/terraform/.terraform.lock.hcl @@ -0,0 +1,149 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/helm" { + version = "2.6.0" + constraints = "~> 2.6.0" + hashes = [ + "h1:BPCVkd80+iJiI6z2M1R1+0rI0h6Q2vNGdQG3uNsTtts=", + "h1:QZcB0CGaRloxrq1JjHF4ZLauaoJ8fHF2MsXFezR0COw=", + "h1:i+fbwv8Vk8n5kQc+spEtzvCNF4yo2exzSAZhL0ipFuo=", + "h1:rGVucCeYAqklKupwoLVG5VPQTIkUhO7WGcw3WuHYrm8=", + "h1:tjCJvA66J9SPd4Y8K034/E3jIBjPJYPqsmdWewNvuaI=", + "zh:0ac248c28acc1a4fd11bd26a85e48ab78dd6abf0f7ac842bf1cd7edd05ac6cf8", + "zh:3d32c8deae3740d8c5310136cc11c8afeffc350fbf88afaca0c34a223a5246f5", + "zh:4055a27489733d19ca7fa2dfce14d323fe99ae9dede7d0fea21ee6db0b9ca74b", + "zh:58a8ed39653fd4c874a2ecb128eccfa24c94266a00e349fd7fb13e22ad81f381", + "zh:6c81508044913f25083de132d0ff81d083732aba07c506cc2db05aa0cefcde2c", + "zh:7db5d18093047bfc4fe597f79610c0a281b21db0d61b0bacb3800585e976f814", + "zh:8269207b7422db99e7be80a5352d111966c3dfc7eb98511f11c8ff7b2e813456", + "zh:b1d7ababfb2374e72532308ff442cc906b79256b66b3fe7a98d42c68c4ddf9c5", + "zh:ca63e226cbdc964a5d63ef21189f059ce45c3fa4a5e972204d6916a9177d2b44", + "zh:d205a72d60e8cc362943d66f5bcdd6b6aaaa9aab2b89fd83bf6f1978ac0b1e4c", + "zh:db47dc579a0e68e5bfe3a61f2e950e6e2af82b1f388d1069de014a937962b56a", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} + +provider "registry.terraform.io/hashicorp/kubernetes" { + version = "2.12.1" + constraints = "~> 2.12.1" + hashes = [ + "h1:5Ah5IKrQyHeaxPxCYYIJ6+SXTMTlbv6KUHshD0BRI1I=", + "h1:6ZgqegUao9WcfVzYg7taxCQOQldTmMVw0HqjG5S46OY=", + "h1:BLBcNgY3p4QnRKisknoCHJpa9+Zn423t17lpsSyeCIg=", + "h1:YdDA370JByM9HT5GdLpt34z3BvcVW4BnVXqdgB/vZ6I=", + "h1:iAS9NYD0DjjmKpge74+y6nRltWkF+jkEpavWOEgq4jY=", + "zh:1ecb2adff52754fb4680c7cfe6143d1d8c264b00bb0c44f07f5583b1c7f978b8", + "zh:1fbd155088cd5818ad5874e4d59ccf1801e4e1961ac0711442b963315f1967ab", + "zh:29e927c7c8f112ee0e8ab70e71b498f2f2ae6f47df1a14e6fd0fdb6f14b57c00", + "zh:42c2f421da6b5b7c997e42aa04ca1457fceb13dd66099a057057a0812b680836", + "zh:522a7bccd5cd7acbb4ec3ef077d47f4888df7e59ff9f3d598b717ad3ee4fe9c9", + "zh:b45d8dc5dcbc5e30ae570d0c2e198505f47d09098dfd5f004871be8262e6ec1e", + "zh:c3ea0943f2050001c7d6a7115b9b990f148b082ebfc4ff3c2ff3463a8affcc4a", + "zh:f111833a64e06659d2e21864de39b7b7dec462615294d02f04c777956742a930", + "zh:f182dba5707b90b0952d5984c23f7a2da3baa62b4d71e78df7759f16cc88d957", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + "zh:f76655a68680887daceabd947b2f68e2103f5bbec49a2bc29530f82ab8e3bca3", + "zh:fadb77352caa570bd3259dfb59c31db614d55bc96df0ff15a3c0cd2e685678b9", + ] +} + +provider "registry.terraform.io/hashicorp/local" { + version = "2.2.3" + constraints = "~> 2.2.3" + hashes = [ + "h1:3bH88Z7tlWvcoubm6hQUBk3s9bSIJC8bVHQz749B87E=", + "h1:FvRIEgCmAezgZUqb2F+PZ9WnSSnR5zbEM2ZI+GLmbMk=", + "h1:KmHz81iYgw9Xn2L3Carc2uAzvFZ1XsE7Js3qlVeC77k=", + "h1:Q3jfOfv6aoLDw/clZGDOaUqUtQjEgeK6Qi8HHMlFO7A=", + "h1:aWp5iSUxBGgPv1UnV5yag9Pb0N+U1I0sZb38AXBFO8A=", + "zh:04f0978bb3e052707b8e82e46780c371ac1c66b689b4a23bbc2f58865ab7d5c0", + "zh:6484f1b3e9e3771eb7cc8e8bab8b35f939a55d550b3f4fb2ab141a24269ee6aa", + "zh:78a56d59a013cb0f7eb1c92815d6eb5cf07f8b5f0ae20b96d049e73db915b238", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:8aa9950f4c4db37239bcb62e19910c49e47043f6c8587e5b0396619923657797", + "zh:996beea85f9084a725ff0e6473a4594deb5266727c5f56e9c1c7c62ded6addbb", + "zh:9a7ef7a21f48fabfd145b2e2a4240ca57517ad155017e86a30860d7c0c109de3", + "zh:a63e70ac052aa25120113bcddd50c1f3cfe61f681a93a50cea5595a4b2cc3e1c", + "zh:a6e8d46f94108e049ad85dbed60354236dc0b9b5ec8eabe01c4580280a43d3b8", + "zh:bb112ce7efbfcfa0e65ed97fa245ef348e0fd5bfa5a7e4ab2091a9bd469f0a9e", + "zh:d7bec0da5c094c6955efed100f3fe22fca8866859f87c025be1760feb174d6d9", + "zh:fb9f271b72094d07cef8154cd3d50e9aa818a0ea39130bc193132ad7b23076fd", + ] +} + +provider "registry.terraform.io/hashicorp/random" { + version = "3.3.2" + constraints = "~> 3.3.2" + hashes = [ + "h1:BgC3HcQhraeo8opJqoLm07Jcs4otOu2XrY2ppVeRMpg=", + "h1:Fu0IKMy46WsO5Y6KfuH9IFkkuxZjE/gIcgtB7GWkTtc=", + "h1:H5V+7iXol/EHB2+BUMzGlpIiCOdV74H8YjzCxnSAWcg=", + "h1:YChjos7Hrvr2KgTc9GzQ+de/QE2VLAeRJgxFemnCltU=", + "h1:rGCyrtzi+H9apmpwzMSJ4xNra7veNM7y6JRkBhO68wM=", + "zh:038293aebfede983e45ee55c328e3fde82ae2e5719c9bd233c324cfacc437f9c", + "zh:07eaeab03a723d83ac1cc218f3a59fceb7bbf301b38e89a26807d1c93c81cef8", + "zh:427611a4ce9d856b1c73bea986d841a969e4c2799c8ac7c18798d0cc42b78d32", + "zh:49718d2da653c06a70ba81fd055e2b99dfd52dcb86820a6aeea620df22cd3b30", + "zh:5574828d90b19ab762604c6306337e6cd430e65868e13ef6ddb4e25ddb9ad4c0", + "zh:7222e16f7833199dabf1bc5401c56d708ec052b2a5870988bc89ff85b68a5388", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:b1b2d7d934784d2aee98b0f8f07a8ccfc0410de63493ae2bf2222c165becf938", + "zh:b8f85b6a20bd264fcd0814866f415f0a368d1123cd7879c8ebbf905d370babc8", + "zh:c3813133acc02bbebddf046d9942e8ba5c35fc99191e3eb057957dafc2929912", + "zh:e7a41dbc919d1de800689a81c240c27eec6b9395564630764ebb323ea82ac8a9", + "zh:ee6d23208449a8eaa6c4f203e33f5176fa795b4b9ecf32903dffe6e2574732c2", + ] +} + +provider "registry.terraform.io/hashicorp/tls" { + version = "4.0.1" + constraints = "~> 4.0.1" + hashes = [ + "h1:2FRq1ouYZYwK6VpukGeox81bniVDbObUE2/SZanw1Dw=", + "h1:NUd1WMN8YPDlMrBbDuiuGDpPlAM6JtDd75qbN+6tw4Q=", + "h1:oyckFNWXgZtgUanWHbNyz3txRgXYkDpCsTLSv5JSD1I=", + "h1:suLkTTvsuB5kqV5gc12PyGT4zY0J9G0RTyWMlZDwSVY=", + "h1:try2jk3QqLgGJH0V11y3uXt3EYRZG3dIKQXgNF0aP5w=", + "zh:1aa2e4c07ddf87f7bda65a4a0f3b45c3edfbe983768d49a105f7ab9f2e4f8320", + "zh:1b7993daaf659dec421043ccf2dea021972ebacf47e5da3387e1ef35a0ffecbe", + "zh:1c40b056af93fe792fd468a96f317a6ce918849799906cf619a1b8cf01e79ccb", + "zh:3874421e4c975e987ade5bdece6d1eacd41065841c82856cc12fde405ea2fe38", + "zh:4f27e1a90d779ac4bbdbd3db735b4777a90aefc8005905a8ed450bb517c323db", + "zh:b4eb5438dc4bfbed7223c0044b775a210d52b631a9f37d884d567a3eacc31b92", + "zh:b9808ee16fa06b7113a72c8d74f1cb322d0e7364fc34ba4bfdd0424ef7fd93d8", + "zh:bc5b1913fe841a0d40f28ff70d76e1c22fa3f469ae28011422d12c6001dcb954", + "zh:bdba092ae2939cb7e28380c5fd4a33ee96bead1abadbf9ec95d559cea8c04c3c", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + "zh:f80791f95f0ea5b332913e533c79ed4820e8c9243c508d8c7d6240b212160aaa", + "zh:fe34ecc33c990f045ca5e3828e8aeb8ee86c9072e098e0ac0e4b47cbcb01edc0", + ] +} + +provider "registry.terraform.io/oracle/oci" { + version = "4.88.1" + constraints = ">= 4.88.1" + hashes = [ + "h1:4378PUKQgToGn5AI+iwfnYeyKDe+Ue6O7TZRPlNYLiY=", + "h1:OGnVqFUckqpMqo8XZ6uE56xhi+EILKq8Lf2p/SrqETc=", + "h1:cCXcCKIKNY3c01oMlpjX5opG3xJ5/L2OKkPMQpBtI5s=", + "h1:m56AltEFI+r4dTZ8aEY9ApojYogCSOWpY238KhFaUMw=", + "h1:ygTETaxIw+a4MQZyFaDJ6R6Bj4cF0or5KspU54g4sNk=", + "zh:10d080d13b01d6e243945a151bf01a22f7e289df5abaaf9700dd51e6258c8752", + "zh:19604d3aa97b94e8f131bb6bea0dba767ea12937db7c1092cc1d9cf22a6c92c5", + "zh:1bb12b5253b824d0374852a2ddf61b08ef05a4b1a955fdc0716091eae3cd6801", + "zh:21a06b3def972c96dcda8936d50834dba2846e267cec82cd68c2a811fb03a692", + "zh:28ae7c8b28ead8a0a8c6d95bd724a00ad7dac9eca4023eb4c8d4d5ff82dc3046", + "zh:35a48fa91da25fc9be4db89844dfcb1e69827bc8d2e3162256f37b1329d859fd", + "zh:470b99ab0d52e05b3d27e0a6d4389408818ed21a08ec09db63f44e5b5302eeeb", + "zh:66a642486d94c0cd0ccd5bb5b280baa4159fe8977e327b22d127cf321a21c3c6", + "zh:6ad9d78c862404b8b75b173afb47170edbc6a033c85317f69934d4141526facf", + "zh:6b4343b7fece4264b5a8cfd796e31e17e41b00181d854066a34af6aaf3b6318a", + "zh:6f151341c35d294a0f79970cda6ddb96c93be4bc557cbea8f3b413a66150c5ed", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:b8c6fae7f66efc1a7a438269889763e42b323181e983e3936562207fa51187b5", + "zh:d85c4c0af11f3e317ffd886fdafd359e41ae577191b63e66b58c1e9ae80d9ed3", + "zh:ecaac469a4cbd089ce9cf4f23ed7a9454eef05e512447a472fb54de2438f65f8", + ] +} diff --git a/terraform/LICENSE b/terraform/LICENSE new file mode 100644 index 0000000..5e6d632 --- /dev/null +++ b/terraform/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. + +The Universal Permissive License (UPL), Version 1.0 + +Subject to the condition set forth below, permission is hereby granted to any person obtaining a copy of this +software, associated documentation and/or data (collectively the "Software"), free of charge and under any and +all copyright rights in the Software, and any and all patent rights owned or freely licensable by each licensor +hereunder covering either (i) the unmodified Software as contributed to or provided by such licensor, or +(ii) the Larger Works (as defined below), to deal in both + +(a) the Software, and +(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if one is included with the Software +(each a “Larger Work” to which the Software is contributed by such licensors), + +without restriction, including without limitation the rights to copy, create derivative works of, display, +perform, and distribute the Software and make, use, sell, offer for sale, import, export, have made, and have +sold the Software and the Larger Work(s), and to sublicense the foregoing rights on either these or other terms. + +This license is subject to the following condition: +The above copyright notice and either this complete permission notice or at a minimum a reference to the UPL must +be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO +THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. diff --git a/terraform/README.md b/terraform/README.md new file mode 100644 index 0000000..1e0ca6a --- /dev/null +++ b/terraform/README.md @@ -0,0 +1 @@ +# diff --git a/terraform/VERSION b/terraform/VERSION new file mode 100644 index 0000000..f477849 --- /dev/null +++ b/terraform/VERSION @@ -0,0 +1 @@ +0.2.2 \ No newline at end of file diff --git a/terraform/datasources.tf b/terraform/datasources.tf new file mode 100644 index 0000000..b0037ac --- /dev/null +++ b/terraform/datasources.tf @@ -0,0 +1,19 @@ +# Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +# + +# Gets home and current regions +data "oci_identity_tenancy" "tenant_details" { + tenancy_id = var.tenancy_ocid + + provider = oci.current_region +} + +data "oci_identity_regions" "home_region" { + filter { + name = "key" + values = [data.oci_identity_tenancy.tenant_details.home_region_key] + } + + provider = oci.current_region +} \ No newline at end of file diff --git a/terraform/module-cluster-tools.tf b/terraform/module-cluster-tools.tf new file mode 100644 index 0000000..6dfdaef --- /dev/null +++ b/terraform/module-cluster-tools.tf @@ -0,0 +1,76 @@ +# Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +# + +module "cluster-tools" { + source = "./modules/cluster-tools" + + # Oracle Cloud Infrastructure Tenancy and Compartment OCID + tenancy_ocid = var.tenancy_ocid + compartment_ocid = var.compartment_ocid + region = var.region + + # Cluster Tools + ## Ingress + ingress_nginx_enabled = var.ingress_nginx_enabled + ingress_load_balancer_shape = var.ingress_load_balancer_shape + ingress_load_balancer_shape_flex_min = var.ingress_load_balancer_shape_flex_min + ingress_load_balancer_shape_flex_max = var.ingress_load_balancer_shape_flex_max + + ## Cert Manager + cert_manager_enabled = var.cert_manager_enabled + + ## Metrics Server + metrics_server_enabled = var.metrics_server_enabled + + ## Prometheus + prometheus_enabled = var.prometheus_enabled + + ## Grafana + grafana_enabled = var.grafana_enabled + + depends_on = [module.oke] +} + +# Kubernetes Cluster Tools +## Ingress/LoadBalancer +variable "ingress_nginx_enabled" { + default = true + description = "Enable Ingress Nginx for Kubernetes Services (This option provision a Load Balancer)" +} +variable "ingress_load_balancer_shape" { + default = "flexible" # Flexible, 10Mbps, 100Mbps, 400Mbps or 8000Mps + description = "Shape that will be included on the Ingress annotation for the OCI Load Balancer creation" +} +variable "ingress_load_balancer_shape_flex_min" { + default = "10" + description = "Enter the minimum size of the flexible shape." +} +variable "ingress_load_balancer_shape_flex_max" { + default = "100" # From 10 to 8000. Cannot be lower than flex_min + description = "Enter the maximum size of the flexible shape (Should be bigger than minimum size). The maximum service limit is set by your tenancy limits." +} + +## Cert Manager +variable "cert_manager_enabled" { + default = false + description = "Enable x509 Certificate Management" +} + +## Metrics Server +variable "metrics_server_enabled" { + default = true + description = "Enable Metrics Server for Metrics, HPA, VPA and Cluster Autoscaler" +} + +## Prometheus +variable "prometheus_enabled" { + default = true + description = "Enable Prometheus" +} + +## Grafana +variable "grafana_enabled" { + default = false + description = "Enable Grafana Dashboards. Includes example dashboards and Prometheus, OCI Logging and OCI Metrics datasources" +} diff --git a/terraform/module-oke.tf b/terraform/module-oke.tf new file mode 100644 index 0000000..94e895b --- /dev/null +++ b/terraform/module-oke.tf @@ -0,0 +1,273 @@ +# Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +# + +module "oke" { + source = "./modules/oke" + + providers = { + oci = oci + oci.home_region = oci.home_region + } + + # Oracle Cloud Infrastructure Tenancy and Compartment OCID + tenancy_ocid = var.tenancy_ocid + compartment_ocid = var.compartment_ocid + region = var.region + + # OKE Cluster + app_name = var.app_name + app_deployment_environment = var.app_deployment_environment + app_deployment_type = var.app_deployment_type + + ## create_new_oke_cluster + create_new_oke_cluster = var.create_new_oke_cluster + existent_oke_cluster_id = var.existent_oke_cluster_id + create_new_compartment_for_oke = var.create_new_compartment_for_oke + oke_compartment_description = var.oke_compartment_description + + ## Cluster Workers visibility + cluster_workers_visibility = var.cluster_workers_visibility + + ## Cluster API Endpoint visibility + cluster_endpoint_visibility = var.cluster_endpoint_visibility + + ## Create Dynamic group and Policies for Autoscaler and OCI Metrics and Logging + create_dynamic_group_for_nodes_in_compartment = var.create_dynamic_group_for_nodes_in_compartment + create_compartment_policies = var.create_compartment_policies + + ## Encryption (OCI Vault/Key Management/KMS) + use_encryption_from_oci_vault = var.use_encryption_from_oci_vault + create_new_encryption_key = var.create_new_encryption_key + existent_encryption_key_id = var.existent_encryption_key_id + + ## Enable Cluster Autoscaler + cluster_autoscaler_enabled = var.cluster_autoscaler_enabled + cluster_autoscaler_min_nodes = var.cluster_autoscaler_min_nodes + cluster_autoscaler_max_nodes = var.cluster_autoscaler_max_nodes + existent_oke_nodepool_id_for_autoscaler = var.existent_oke_nodepool_id_for_autoscaler + + ## OKE Worker Nodes (Compute) + num_pool_workers = var.num_pool_workers + node_pool_shape = var.node_pool_instance_shape.instanceShape + node_pool_node_shape_config_ocpus = var.node_pool_instance_shape.ocpus + node_pool_node_shape_config_memory_in_gbs = var.node_pool_instance_shape.memory + generate_public_ssh_key = var.generate_public_ssh_key + public_ssh_key = var.public_ssh_key + + # count = var.oke_provision ? 1 : 0 +} + +# OKE Variables +# variable "oke_provision" { +# default = false +# description = "Provision OCI Container Engine - OKE" +# } +## OKE Cluster Details +variable "app_name" { + default = "K8s App" + description = "Application name. Will be used as prefix to identify resources, such as OKE, VCN, ATP, and others" +} +variable "app_deployment_environment" { + default = "generic" # e.g.: Development, QA, Stage, ... + description = "Deployment environment for the freeform tags" +} +variable "app_deployment_type" { + default = "generic" # e.g.: App Type 1, App Type 2, Red, Purple, ... + description = "Deployment type for the freeform tags" +} +variable "create_new_oke_cluster" { + default = true + description = "Creates a new OKE cluster, node pool and network resources" +} +variable "existent_oke_cluster_id" { + default = "" + description = "Using existent OKE Cluster. Only the application and services will be provisioned. If select cluster autoscaler feature, you need to get the node pool id and enter when required" +} +variable "create_new_compartment_for_oke" { + default = false + description = "Creates new compartment for OKE Nodes and OCI Services deployed. NOTE: The creation of the compartment increases the deployment time by at least 3 minutes, and can increase by 15 minutes when destroying" +} +variable "oke_compartment_description" { + default = "Compartment for OKE, Nodes and Services" +} + +## OKE Visibility (Workers and Endpoint) + +variable "cluster_workers_visibility" { + default = "Private" + description = "The Kubernetes worker nodes that are created will be hosted in public or private subnet(s)" + + validation { + condition = var.cluster_workers_visibility == "Private" || var.cluster_workers_visibility == "Public" + error_message = "Sorry, but cluster visibility can only be Private or Public." + } +} + +# NOTE: Private Endpoint is only supported when using OCI Resource Manager for deployment. +variable "cluster_endpoint_visibility" { + default = "Public" + description = "The Kubernetes cluster that is created will be hosted on a public subnet with a public IP address auto-assigned or on a private subnet. If Private, additional configuration will be necessary to run kubectl commands" + + validation { + condition = var.cluster_endpoint_visibility == "Private" || var.cluster_endpoint_visibility == "Public" + error_message = "Sorry, but cluster endpoint visibility can only be Private or Public." + } +} + +## OKE Encryption details +variable "use_encryption_from_oci_vault" { + default = false + description = "By default, Oracle manages the keys that encrypts Kubernetes Secrets at Rest in Etcd, but you can choose a key from a vault that you have access to, if you want greater control over the key's lifecycle and how it's used" +} +variable "create_new_encryption_key" { + default = false + description = "Creates new vault and key on OCI Vault/Key Management/KMS and assign to boot volume of the worker nodes" +} +variable "existent_encryption_key_id" { + default = "" + description = "Use an existent master encryption key to encrypt boot volume and object storage bucket. NOTE: If the key resides in a different compartment or in a different tenancy, make sure you have the proper policies to access, or the provision of the worker nodes will fail" +} +variable "create_vault_policies_for_group" { + default = false + description = "Creates policies to allow the user applying the stack to manage vault and keys. If you are on the Administrators group or already have the policies for a compartment, this policy is not needed. If you do not have access to allow the policy, ask your administrator to include it for you" +} +variable "user_admin_group_for_vault_policy" { + default = "Administrators" + description = "User Identity Group to allow manage vault and keys. The user running the Terraform scripts or Applying the ORM Stack need to be on this group" +} + +## OKE Autoscaler +variable "cluster_autoscaler_enabled" { + default = true + description = "Enables OKE cluster autoscaler. Node pools will auto scale based on the resources usage" +} +variable "cluster_autoscaler_min_nodes" { + default = 3 + description = "Minimum number of nodes on the node pool to be scheduled by the Kubernetes" +} +variable "cluster_autoscaler_max_nodes" { + default = 10 + description = "Maximum number of nodes on the node pool to be scheduled by the Kubernetes" +} +variable "existent_oke_nodepool_id_for_autoscaler" { + default = "" + description = "Nodepool Id of the existent OKE to use with Cluster Autoscaler" +} + +## OKE Node Pool Details +variable "node_pool_name" { + default = "pool1" + description = "Name of the node pool" +} +variable "k8s_version" { + default = "Latest" + description = "Kubernetes version installed on your master and worker nodes. If not version select, will use the latest available." +} +variable "num_pool_workers" { + default = 3 + description = "The number of worker nodes in the node pool. If select Cluster Autoscaler, will assume the minimum number of nodes configured" +} + +# ocpus and memory are only used if flex shape is selected +variable "node_pool_instance_shape" { + type = map(any) + default = { + "instanceShape" = "VM.Standard.E4.Flex" + "ocpus" = 2 + "memory" = 16 + } + description = "A shape is a template that determines the number of OCPUs, amount of memory, and other resources allocated to a newly created instance for the Worker Node. Select at least 2 OCPUs and 16GB of memory if using Flex shapes" +} +# variable "node_pool_node_shape_config_ocpus" { +# default = "1" # Only used if flex shape is selected +# description = "You can customize the number of OCPUs to a flexible shape" +# } +# variable "node_pool_node_shape_config_memory_in_gbs" { +# default = "16" # Only used if flex shape is selected +# description = "You can customize the amount of memory allocated to a flexible shape" +# } +variable "node_pool_boot_volume_size_in_gbs" { + default = "60" + description = "Specify a custom boot volume size (in GB)" +} +variable "image_operating_system" { + default = "Oracle Linux" + description = "The OS/image installed on all nodes in the node pool." +} +variable "image_operating_system_version" { + default = "8" + description = "The OS/image version installed on all nodes in the node pool." +} +variable "generate_public_ssh_key" { + default = true +} +variable "public_ssh_key" { + default = "" + description = "In order to access your private nodes with a public SSH key you will need to set up a bastion host (a.k.a. jump box). If using public nodes, bastion is not needed. Left blank to not import keys." +} + +# Create Dynamic Group and Policies +variable "create_dynamic_group_for_nodes_in_compartment" { + default = false # TODO: true + description = "Creates dynamic group of Nodes in the compartment. Note: You need to have proper rights on the Tenancy. If you only have rights in a compartment, uncheck and ask you administrator to create the Dynamic Group for you" +} +variable "existent_dynamic_group_for_nodes_in_compartment" { + default = "" + description = "Enter previous created Dynamic Group for the policies" +} +variable "create_compartment_policies" { + default = false # TODO: true + description = "Creates policies that will reside on the compartment. e.g.: Policies to support Cluster Autoscaler, OCI Logging datasource on Grafana" +} + +# OKE Outputs + +output "comments" { + value = module.oke.comments +} +output "deploy_id" { + value = module.oke.deploy_id +} +output "deployed_oke_kubernetes_version" { + value = module.oke.deployed_oke_kubernetes_version +} +output "deployed_to_region" { + value = module.oke.deployed_to_region +} +output "kubeconfig" { + value = module.oke.kubeconfig +} +output "kubeconfig_for_kubectl" { + value = module.oke.kubeconfig_for_kubectl + description = "If using Terraform locally, this command set KUBECONFIG environment variable to run kubectl locally" +} +output "dev" { + value = module.oke.dev +} +### Important Security Notice ### +# The private key generated by this resource will be stored unencrypted in your Terraform state file. +# Use of this resource for production deployments is not recommended. +# Instead, generate a private key file outside of Terraform and distribute it securely to the system where Terraform will be run. +output "generated_private_key_pem" { + value = module.oke.generated_private_key_pem + sensitive = true +} + +# output "oke_debug_oke_private_endpoint" { +# value = module.oke.oke_debug_oke_private_endpoint +# } +# output "oke_debug_orm_private_endpoint_reachable_ip" { +# value = module.oke.oke_debug_orm_private_endpoint_reachable_ip +# } +# output "oke_debug_oke_endpoints" { +# value = module.oke.oke_debug_oke_endpoints +# } + +output "debug_k8s_version_calculated" { + value = module.oke.debug_k8s_version_calculated +} + +output "debug_k8s_version_var" { + value = module.oke.debug_k8s_version_var +} \ No newline at end of file diff --git a/terraform/modules/cluster-tools/cert-manager.tf b/terraform/modules/cluster-tools/cert-manager.tf new file mode 100644 index 0000000..00cb769 --- /dev/null +++ b/terraform/modules/cluster-tools/cert-manager.tf @@ -0,0 +1,33 @@ +# Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +# + +# Cert Manager variables +variable "cert_manager_enabled" { + default = true + description = "Enable x509 Certificate Management" +} + +# Cert Manager Helm chart +## https://github.com/jetstack/cert-manager/blob/master/README.md +## https://artifacthub.io/packages/helm/cert-manager/cert-manager +resource "helm_release" "cert_manager" { + name = "cert-manager" + repository = local.helm_repository.jetstack + chart = "cert-manager" + version = local.helm_repository.jetstack_version + namespace = kubernetes_namespace.cluster_tools.id + wait = true # wait to allow the webhook be properly configured + + set { + name = "installCRDs" + value = true + } + + set { + name = "webhook.timeoutSeconds" + value = "30" + } + + count = var.cert_manager_enabled ? 1 : 0 +} \ No newline at end of file diff --git a/terraform/modules/cluster-tools/cluster-tools.tf b/terraform/modules/cluster-tools/cluster-tools.tf new file mode 100644 index 0000000..12b74b1 --- /dev/null +++ b/terraform/modules/cluster-tools/cluster-tools.tf @@ -0,0 +1,31 @@ +# Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +# + +# Create namespace cluster-tools for supporting services +resource "kubernetes_namespace" "cluster_tools" { + metadata { + name = "cluster-tools" + } +} + +locals { + # Helm repos + helm_repository = { + ingress_nginx = "https://kubernetes.github.io/ingress-nginx" + ingress_nginx_version = "4.2.0" + jetstack = "https://charts.jetstack.io" # cert-manager + jetstack_version = "1.8.2" # cert-manager + grafana = "https://grafana.github.io/helm-charts" + grafana_version = "6.32.5" + prometheus = "https://prometheus-community.github.io/helm-charts" + prometheus_version = "15.10.5" + metrics_server = "https://kubernetes-sigs.github.io/metrics-server" + metrics_server_version = "3.8.2" + } +} + +# OCI Provider +variable "tenancy_ocid" {} +variable "compartment_ocid" {} +variable "region" {} \ No newline at end of file diff --git a/terraform/modules/cluster-tools/grafana.tf b/terraform/modules/cluster-tools/grafana.tf new file mode 100644 index 0000000..8d14ff3 --- /dev/null +++ b/terraform/modules/cluster-tools/grafana.tf @@ -0,0 +1,150 @@ +# Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +# + +# Grafana variables +variable "grafana_enabled" { + default = true + description = "Enable Grafana Dashboards. Includes example dashboards and Prometheus, OCI Logging and OCI Metrics datasources" +} + +# Grafana Helm chart +## https://github.com/grafana/helm-charts/blob/main/charts/grafana/README.md +## https://artifacthub.io/packages/helm/grafana/grafana +resource "helm_release" "grafana" { + name = "grafana" + repository = local.helm_repository.grafana + chart = "grafana" + version = local.helm_repository.grafana_version + namespace = kubernetes_namespace.cluster_tools.id + wait = false + + set { + name = "grafana\\.ini.server.root_url" + value = "%(protocol)s://%(domain)s:%(http_port)s/grafana" + type = "string" + } + + set { + name = "grafana\\.ini.server.serve_from_sub_path" + value = "true" + } + + values = [ + <