Skip to content

Commit

Permalink
Add variable validation and update to use 0.9.0 of CDP modules (#55)
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Enright <jenright@cloudera.com>
  • Loading branch information
jimright authored Dec 17, 2024
1 parent fa4cddd commit 5088b23
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
16 changes: 15 additions & 1 deletion aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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" {
Expand Down Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions azure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
16 changes: 15 additions & 1 deletion azure/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
6 changes: 3 additions & 3 deletions gcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ terraform {
}
google = {
source = "hashicorp/google"
version = "4.84.0"
version = ">= 6.12.0"
}
tls = {
source = "hashicorp/tls"
Expand All @@ -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
Expand All @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions gcp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit 5088b23

Please sign in to comment.