From 5088b23865bb5e92897870e2dee1626602692e4d Mon Sep 17 00:00:00 2001 From: Jim Enright Date: Tue, 17 Dec 2024 10:22:01 +0000 Subject: [PATCH] Add variable validation and update to use 0.9.0 of CDP modules (#55) Signed-off-by: Jim Enright --- README.md | 3 +++ aws/main.tf | 4 ++-- aws/variables.tf | 16 +++++++++++++++- azure/main.tf | 4 ++-- azure/variables.tf | 16 +++++++++++++++- gcp/main.tf | 6 +++--- gcp/variables.tf | 15 +++++++++++++++ 7 files changed, 55 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 51c748a..ef06102 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,9 @@ Change to required cloud provider directory and create a `terraform.tfvars` file Reference the `terraform.tfvars.template` in each cloud provider directory and the sample contents with indicators of values to change shown below. +> [!IMPORTANT] +> Ensure the value of the `env_prefix` variable is 12 characters or less in length and consist only of lowercase letters, numbers, and hyphens. + ```bash # Change into cloud provider directory, e.g. for aws cd aws diff --git a/aws/main.tf b/aws/main.tf index 1fcaa2b..7c4057b 100644 --- a/aws/main.tf +++ b/aws/main.tf @@ -47,7 +47,7 @@ provider "aws" { } module "cdp_aws_prereqs" { - source = "git::https://github.com/cloudera-labs/terraform-cdp-modules.git//modules/terraform-cdp-aws-pre-reqs?ref=v0.8.4" + source = "git::https://github.com/cloudera-labs/terraform-cdp-modules.git//modules/terraform-cdp-aws-pre-reqs?ref=v0.9.0" env_prefix = var.env_prefix aws_region = var.aws_region @@ -90,7 +90,7 @@ module "cdp_aws_prereqs" { } module "cdp_deploy" { - source = "git::https://github.com/cloudera-labs/terraform-cdp-modules.git//modules/terraform-cdp-deploy?ref=v0.8.4" + source = "git::https://github.com/cloudera-labs/terraform-cdp-modules.git//modules/terraform-cdp-deploy?ref=v0.9.0" env_prefix = var.env_prefix infra_type = "aws" diff --git a/aws/variables.tf b/aws/variables.tf index 7153e01..d7a3acd 100644 --- a/aws/variables.tf +++ b/aws/variables.tf @@ -21,6 +21,15 @@ variable "aws_region" { variable "env_prefix" { type = string description = "Shorthand name for the environment. Used in resource descriptions" + + validation { + condition = length(var.env_prefix) <= 12 + error_message = "The length of env_prefix must be 12 characters or less." + } + validation { + condition = (var.env_prefix == null ? true : can(regex("^[a-z0-9-]{1,12}$", var.env_prefix))) + error_message = "env_prefix can consist only of lowercase letters, numbers, and hyphens (-)." + } } variable "aws_key_pair" { @@ -43,6 +52,11 @@ variable "deployment_template" { type = string description = "Deployment Pattern to use for Cloud resources and CDP" + + validation { + condition = contains(["public", "semi-private", "private"], var.deployment_template) + error_message = "Valid values for var: deployment_template are (public, semi-private, private)." + } } variable "environment_async_creation" { @@ -159,4 +173,4 @@ variable "private_network_extensions" { description = "Enable creation of resources for connectivity to CDP Control Plane (public subnet and NAT Gateway) for Private Deployment. Only relevant for private deployment template" default = true -} \ No newline at end of file +} diff --git a/azure/main.tf b/azure/main.tf index 14d30df..ec30610 100644 --- a/azure/main.tf +++ b/azure/main.tf @@ -56,7 +56,7 @@ provider "azuread" { } module "cdp_azure_prereqs" { - source = "git::https://github.com/cloudera-labs/terraform-cdp-modules.git//modules/terraform-cdp-azure-pre-reqs?ref=v0.8.4" + source = "git::https://github.com/cloudera-labs/terraform-cdp-modules.git//modules/terraform-cdp-azure-pre-reqs?ref=v0.9.0" env_prefix = var.env_prefix azure_region = var.azure_region @@ -78,7 +78,7 @@ module "cdp_azure_prereqs" { } module "cdp_deploy" { - source = "git::https://github.com/cloudera-labs/terraform-cdp-modules.git//modules/terraform-cdp-deploy?ref=v0.8.4" + source = "git::https://github.com/cloudera-labs/terraform-cdp-modules.git//modules/terraform-cdp-deploy?ref=v0.9.0" env_prefix = var.env_prefix infra_type = "azure" diff --git a/azure/variables.tf b/azure/variables.tf index ad60cd2..84d0fa3 100644 --- a/azure/variables.tf +++ b/azure/variables.tf @@ -16,6 +16,15 @@ variable "env_prefix" { type = string description = "Shorthand name for the environment. Used in resource descriptions" + + validation { + condition = length(var.env_prefix) <= 12 + error_message = "The length of env_prefix must be 12 characters or less." + } + validation { + condition = (var.env_prefix == null ? true : can(regex("^[a-z0-9-]{1,12}$", var.env_prefix))) + error_message = "env_prefix can consist only of lowercase letters, numbers, and hyphens (-)." + } } variable "azure_region" { @@ -43,6 +52,11 @@ variable "deployment_template" { type = string description = "Deployment Pattern to use for Cloud resources and CDP" + + validation { + condition = contains(["public", "semi-private", "private"], var.deployment_template) + error_message = "Valid values for var: deployment_template are (public, semi-private, private)." + } } # Disable multiaz deployment as not all Azure regions support it @@ -174,4 +188,4 @@ variable "cdp_delegated_subnet_names" { description = "List of subnet names delegated for Flexible Servers. Required if create_vnet is false." default = null -} \ No newline at end of file +} diff --git a/gcp/main.tf b/gcp/main.tf index b22ba36..85a11b2 100755 --- a/gcp/main.tf +++ b/gcp/main.tf @@ -21,7 +21,7 @@ terraform { } google = { source = "hashicorp/google" - version = "4.84.0" + version = ">= 6.12.0" } tls = { source = "hashicorp/tls" @@ -45,7 +45,7 @@ provider "google" { module "cdp_gcp_prereqs" { - source = "git::https://github.com/cloudera-labs/terraform-cdp-modules.git//modules/terraform-cdp-gcp-pre-reqs?ref=v0.8.4" + source = "git::https://github.com/cloudera-labs/terraform-cdp-modules.git//modules/terraform-cdp-gcp-pre-reqs?ref=v0.9.0" env_prefix = var.env_prefix gcp_region = var.gcp_region @@ -62,7 +62,7 @@ module "cdp_gcp_prereqs" { } module "cdp_deploy" { - source = "git::https://github.com/cloudera-labs/terraform-cdp-modules.git//modules/terraform-cdp-deploy?ref=v0.8.4" + source = "git::https://github.com/cloudera-labs/terraform-cdp-modules.git//modules/terraform-cdp-deploy?ref=v0.9.0" env_prefix = var.env_prefix infra_type = "gcp" diff --git a/gcp/variables.tf b/gcp/variables.tf index cf8988f..e6caa3d 100755 --- a/gcp/variables.tf +++ b/gcp/variables.tf @@ -16,6 +16,16 @@ variable "env_prefix" { type = string description = "Shorthand name for the environment. Used in resource descriptions" + + validation { + condition = length(var.env_prefix) <= 12 + error_message = "The length of env_prefix must be 12 characters or less." + } + validation { + condition = (var.env_prefix == null ? true : can(regex("^[a-z0-9-]{1,12}$", var.env_prefix))) + error_message = "env_prefix can consist only of lowercase letters, numbers, and hyphens (-)." + } + } variable "gcp_project" { @@ -50,6 +60,11 @@ variable "deployment_template" { type = string description = "Deployment Pattern to use for Cloud resources and CDP" + + validation { + condition = contains(["public", "semi-private", "private"], var.deployment_template) + error_message = "Valid values for var: deployment_template are (public, semi-private, private)." + } } variable "environment_async_creation" {