Skip to content

Commit

Permalink
added dynamic IP placement, addressed suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
caroldelwing committed Mar 1, 2024
1 parent dd7651d commit 33ec70e
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 147 deletions.
80 changes: 42 additions & 38 deletions terraform/vmware-cluster-deployment-tf/README.md

Large diffs are not rendered by default.

32 changes: 17 additions & 15 deletions terraform/vmware-cluster-deployment-tf/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ resource "spectrocloud_cluster_vsphere" "cluster" {
depends_on = [spectrocloud_cluster_profile.profile]

cloud_config {
ssh_key = local.ssh_public_key
datacenter = var.datacenter_name
folder = var.folder_name
static_ip = true

ssh_key = local.ssh_public_key
datacenter = var.datacenter_name
folder = var.folder_name
static_ip = false # If true, the cluster will use static IP placement. If false, the cluster will use DDNS.
network_search_domain = var.search_domain
}

cluster_profile {
Expand Down Expand Up @@ -41,11 +41,12 @@ resource "spectrocloud_cluster_vsphere" "cluster" {
}

placement {
cluster = var.vsphere_cluster
datastore = var.datastore_name
network = var.network_name
resource_pool = var.resource_pool_name
static_ip_pool_id = resource.spectrocloud_privatecloudgateway_ippool.ippool.id
cluster = var.vsphere_cluster
datastore = var.datastore_name
network = var.network_name
resource_pool = var.resource_pool_name
# Required for static IP placement.
#static_ip_pool_id = resource.spectrocloud_privatecloudgateway_ippool.ippool.id
}

additional_labels = {
Expand All @@ -70,11 +71,12 @@ resource "spectrocloud_cluster_vsphere" "cluster" {
}

placement {
cluster = var.vsphere_cluster
datastore = var.datastore_name
network = var.network_name
resource_pool = var.resource_pool_name
static_ip_pool_id = resource.spectrocloud_privatecloudgateway_ippool.ippool.id
cluster = var.vsphere_cluster
datastore = var.datastore_name
network = var.network_name
resource_pool = var.resource_pool_name
# Required for static IP placement.
#static_ip_pool_id = resource.spectrocloud_privatecloudgateway_ippool.ippool.id
}

additional_labels = {
Expand Down
21 changes: 13 additions & 8 deletions terraform/vmware-cluster-deployment-tf/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ data "spectrocloud_registry" "public_registry" {
name = "Public Repo"
}

data "spectrocloud_registry" "community_registry" {
name = "Palette Registry"
}

####################################
# Core Infrastructure Layers
# The following core infrastructure layers are configured for deployment to Vsphere.
Expand Down Expand Up @@ -47,11 +51,11 @@ data "spectrocloud_pack" "metallb" {
# Add-On Layers
####################################

#data "spectrocloud_pack" "hellouniverse" {
# name =
# version =
# registry_uid = data.spectrocloud_registry.public_registry.id
#}
data "spectrocloud_pack" "hellouniverse" {
name = "hello-universe"
version = "1.1.1"
registry_uid = data.spectrocloud_registry.community_registry.id
}

####################################
# Data resources for the cluster
Expand All @@ -64,6 +68,7 @@ data "spectrocloud_cloudaccount_vsphere" "account" {
####################################
# Data resources for the PCG
####################################
data "spectrocloud_private_cloud_gateway" "pcg" {
name = var.pcg_name
}
# Required for static IP placement.
# data "spectrocloud_private_cloud_gateway" "pcg" {
# name = var.pcg_name
# }
118 changes: 71 additions & 47 deletions terraform/vmware-cluster-deployment-tf/inputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ variable "cluster_profile_description" {
}

# ToDo
# Provide a range of IP addresses for your Metallb Load Balancer. This range must be included in the PCG's static IP pool.
# Provide a range of IP addresses for your Metallb Load Balancer. This range must be included in the PCG's static IP pool if using static IP placement.
variable "metallb_ip" {
type = string
description = "The IP address range for your MetalLB Load Balancer."
Expand Down Expand Up @@ -46,13 +46,30 @@ variable "tags" {
# Input resources for the cluster - Cloud config
#################################################

# ToDo
# Export the variable below as an environment variable named "TF_VAR_ssh_key".
# The value should include the public key for accessing the cluster nodes. If not provided, a new key pair will be generated.
# ToDo
# Provide the path to the public key that will be added to the cluster nodes. If not provided, a new key pair will be generated.
variable "ssh_key" {
type = string
default = ""
description = "Export the public key that will be used to access the cluster nodes as an environment variable named TF_VAR_ssh_key. If not provided, a new key pair will be generated."
description = "The path to the public key that will be added to the cluster nodes. If not provided, a new key pair will be generated."

validation {
condition = var.ssh_key == "" ? true : fileexists(var.ssh_key)
error_message = "The provided SSH key file does not exist. Please, provide a valid path."
}

}

# ToDo
# Provide the path to the private key that will be used to access the cluster nodes. If not provided, a new key pair will be generated.
variable "ssh_key_private" {
type = string
description = "The path to the private key that will be used to access the cluster nodes. If not provided, a new key pair will be generated."

validation {
condition = var.ssh_key_private == "" ? true : fileexists(var.ssh_key_private)
error_message = "The provided SSH key file does not exist. Please, provide a valid path."
}

}

# ToDo
Expand All @@ -69,6 +86,13 @@ variable "folder_name" {
description = "The name of the folder in vSphere."
}

# ToDo
# Provide the name of the network search domain.
variable "search_domain" {
type = string
description = "The name of network search domain."
}

#################################################
# Input resources for the cluster - Placement
#################################################
Expand Down Expand Up @@ -101,49 +125,49 @@ variable "resource_pool_name" {
description = "The name of the vSphere resource pool."
}

#################################################
# Input resources for the Static IP Pool
#################################################

# ToDo
# Provide the IP address of the vSphere network gateway.
variable "network_gateway" {
type = string
description = "The IP address of the vSphere network gateway."
}

# ToDo
# Provide the prefix of your vSphere network.
# Valid values are network CIDR subnet masks from the range 0-32. Example: 18.
variable "network_prefix" {
type = number
description = "The prefix of your vSphere network."
}

# ToDo
# Provide the name of the PCG that will be used to create the static IP pool.
# Provide the name of the PCG that will be used to deploy the Palette cluster.
variable "pcg_name" {
type = string
description = "The name of the IP Pool PCG."
}

# ToDo
# Provide the first IP address of your PCG IP pool range.
variable "ip_range_start" {
type = string
description = "The first IP address of your PCG IP pool range."
description = "The name of the PCG."
}

# ToDo
# Provide the second IP address of your PCG IP pool range.
variable "ip_range_end" {
type = string
description = "The last IP address of your PCG IP pool range."
}

# ToDo
# Provide a comma-separated list of DNS name server IP addresses.
variable "nameserver_addr" {
type = set(string)
description = "The DNS nameserver IP addresses of your network."
}
#################################################
# Input resources for the Static IP Pool
#################################################
# Required for static IP placement.
# # ToDo
# # Provide the IP address of the vSphere network gateway.
# variable "network_gateway" {
# type = string
# description = "The IP address of the vSphere network gateway."
# }

# # ToDo
# # Provide the prefix of your vSphere network.
# # Valid values are network CIDR subnet masks from the range 0-32. Example: 18.
# variable "network_prefix" {
# type = number
# description = "The prefix of your vSphere network."
# }

# # ToDo
# # Provide the first IP address of your PCG IP pool range.
# variable "ip_range_start" {
# type = string
# description = "The first IP address of your PCG IP pool range."
# }

# # ToDo
# # Provide the second IP address of your PCG IP pool range.
# variable "ip_range_end" {
# type = string
# description = "The last IP address of your PCG IP pool range."
# }

# # ToDo
# # Provide a comma-separated list of DNS name server IP addresses.
# variable "nameserver_addr" {
# type = set(string)
# description = "The DNS nameserver IP addresses of your network."
# }
21 changes: 11 additions & 10 deletions terraform/vmware-cluster-deployment-tf/ippool.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Copyright (c) Spectro Cloud
# SPDX-License-Identifier: Apache-2.0

resource "spectrocloud_privatecloudgateway_ippool" "ippool" {
gateway = var.network_gateway
name = "${var.cluster_name}-ippool"
network_type = "range"
prefix = var.network_prefix
private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.pcg.id
ip_start_range = var.ip_range_start
ip_end_range = var.ip_range_end
nameserver_addresses = var.nameserver_addr
}
# Required for static IP placement.
# resource "spectrocloud_privatecloudgateway_ippool" "ippool" {
# gateway = var.network_gateway
# name = "${var.cluster_name}-ippool"
# network_type = "range"
# prefix = var.network_prefix
# private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.pcg.id
# ip_start_range = var.ip_range_start
# ip_end_range = var.ip_range_end
# nameserver_addresses = var.nameserver_addr
# }
16 changes: 10 additions & 6 deletions terraform/vmware-cluster-deployment-tf/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ We recommend waiting a few minutes before clicking on the service URL to prevent
}

output "ssh_key_location" {
description = "Location of the private SSH key file"
value = length(tls_private_key.tutorial_ssh_key) > 0 ? "This is the location of your private SSH key file: ${local_sensitive_file.private_key_file[0].filename}." : null
description = "Location of the generated private SSH key file"
value = length(tls_private_key.tutorial_ssh_key) > 0 ? "This is the location of the generated private SSH key file: ${local_sensitive_file.private_key_file[0].filename}." : null
}

output "ssh_public_key_location" {
description = "Location of the public SSH key file"
value = length(tls_private_key.tutorial_ssh_key) > 0 ? "This is the location of your public SSH key file: ${local_file.public_key_file[0].filename}." : null
description = "Location of the generated public SSH key file"
value = length(tls_private_key.tutorial_ssh_key) > 0 ? "This is the location of the generated public SSH key file: ${local_file.public_key_file[0].filename}." : null
}

output "ssh_connection_command" {
description = "Command to use the SSH key to connect to a VM"
value = length(tls_private_key.tutorial_ssh_key) > 0 ? "To access your nodes, use the following command, replacing <username> with your username and <hostname> with your hostname: ssh -i ${local_sensitive_file.private_key_file[0].filename} <username>@<hostname>" : null
description = "Command to use the generated private SSH key to access the nodes."
value = length(tls_private_key.tutorial_ssh_key) > 0 ? "To access your nodes, use the following command, replacing <username> with the username and <hostname> with the IP address of your node: ssh -i ${local_sensitive_file.private_key_file[0].filename} <username>@<hostname>" : null
}

output "ssh_connection_command_user" {
description = "Command to use the user's private SSH key to access the nodes."
value = var.ssh_key != "" ? "To access your nodes, use the following command, replacing <username> with the username and <hostname> with the IP address of your node: ssh -i ${var.ssh_key_private} <username>@<hostname>" : null
}

9 changes: 8 additions & 1 deletion terraform/vmware-cluster-deployment-tf/profile.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@ resource "spectrocloud_cluster_profile" "profile" {
# Add-on layer
############################

# Add-on pack hellouniverse
pack {
name = "hello-universe"
tag = "1.1.x"
uid = data.spectrocloud_pack.hellouniverse.id
values = data.spectrocloud_pack.hellouniverse.values
}


}
20 changes: 6 additions & 14 deletions terraform/vmware-cluster-deployment-tf/ssh-key.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

resource "tls_private_key" "tutorial_ssh_key" {
count = var.ssh_key == "" ? 1 : 0
count = var.ssh_key == "" && var.ssh_key_private == "" ? 1 : 0
algorithm = "RSA"
rsa_bits = "4096"
}
Expand All @@ -12,22 +12,14 @@ locals {
}

resource "local_sensitive_file" "private_key_file" {
count = length(tls_private_key.tutorial_ssh_key) > 0 ? 1 : 0
content = tls_private_key.tutorial_ssh_key[0].private_key_openssh
filename = "${path.module}/tutorial_ssh_key"
count = length(tls_private_key.tutorial_ssh_key) > 0 ? 1 : 0
content = tls_private_key.tutorial_ssh_key[0].private_key_openssh
filename = "${path.module}/tutorial_ssh_key"
file_permission = "0600"
}

resource "local_file" "public_key_file" {
count = length(tls_private_key.tutorial_ssh_key) > 0 ? 1 : 0
content = tls_private_key.tutorial_ssh_key[0].public_key_openssh
filename = "${path.module}/tutorial_ssh_key.pub"
}

resource "terraform_data" "chmod" {
count = length(tls_private_key.tutorial_ssh_key) > 0 ? 1 : 0
provisioner "local-exec" {
command = "chmod 600 ${local_sensitive_file.private_key_file[0].filename}"
}
}


}
20 changes: 12 additions & 8 deletions terraform/vmware-cluster-deployment-tf/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@
# SPDX-License-Identifier: Apache-2.0

# Static IP Pool Variables
network_gateway = "REPLACE ME" # Provide the IP address of the vSphere network gateway.
network_prefix = "REPLACE ME" # Provide the prefix of your vSphere network. Valid values are network CIDR subnet masks from the range 0-32. Example: 18.
pcg_name = "REPLACE ME" # Provide the name of the PCG that will be used to create the static IP pool.
ip_range_start = "REPLACE ME" # Provide the first IP address of your PCG IP pool range.
ip_range_end = "REPLACE ME" # Provide the second IP address of your PCG IP pool range.
nameserver_addr = ["REPLACE ME"] # Provide a comma-separated list of DNS name server IP addresses.
# Required for static IP placement only.
# network_gateway = "REPLACE ME" # Provide the IP address of the vSphere network gateway.
# network_prefix = "REPLACE ME" # Provide the prefix of your vSphere network. Valid values are network CIDR subnet masks from the range 0-32. Example: 18.
# ip_range_start = "REPLACE ME" # Provide the first IP address of your PCG IP pool range.
# ip_range_end = "REPLACE ME" # Provide the second IP address of your PCG IP pool range.
# nameserver_addr = ["REPLACE ME"] # Provide a comma-separated list of DNS name server IP addresses.


# Cluster Profile Variables
metallb_ip = "REPLACE ME" # Provide a range of IP addresses for your Metallb Load Balancer. This range must be included in the PCG's static IP pool range.
metallb_ip = "REPLACE ME" # Provide a range of IP addresses for your Metallb Load Balancer. This range must be included in the PCG's static IP pool range if using static IP placement.


# Cluster Variables
pcg_name = "REPLACE ME" # Provide the name of the PCG that will be used to deploy the Palette cluster.
datacenter_name = "REPLACE ME" # Provide the name of the datacenter in vSphere.
folder_name = "REPLACE ME" # Provide the name of the folder in vSphere.
search_domain = "REPLACE ME" # Provide the name of the network search domain.
vsphere_cluster = "REPLACE ME" # Provide the cluster name for the machine pool as it appears in vSphere.
datastore_name = "REPLACE ME" # Provide the datastore name for the machine pool as it appears in vSphere.
network_name = "REPLACE ME" # Provide the network name for the machine pool as it appears in vSphere.
resource_pool_name = "REPLACE ME" # Provide the resource pool name for the machine pool as it appears in vSphere.
resource_pool_name = "REPLACE ME" # Provide the resource pool name for the machine pool as it appears in vSphere.
ssh_key = "" # Provide the path to your public SSH key. If not provided, a new key pair will be created.
ssh_key_private = "" # Provide the path to your private SSH key. If not provided, a new key pair will be created.

0 comments on commit 33ec70e

Please sign in to comment.