From d022b2ab9cb8a0857d6aa9255fa24c707cf200a9 Mon Sep 17 00:00:00 2001 From: dahorak Date: Fri, 8 Dec 2023 15:13:53 +0100 Subject: [PATCH] vSphere AI depl: create api and ingress records (#9021) - update terroform scripts for deployment on vSphere via Assisted Installer to create API and Ingress DNS records Signed-off-by: Daniel Horak --- terraform/ai/vsphere/main.tf | 27 +++++++++++++++++++ terraform/ai/vsphere/terraform.tfvars.example | 9 +++++++ terraform/ai/vsphere/variables.tf | 18 +++++++++++++ 3 files changed, 54 insertions(+) diff --git a/terraform/ai/vsphere/main.tf b/terraform/ai/vsphere/main.tf index 55a3ad77d58..63dbb9920f2 100644 --- a/terraform/ai/vsphere/main.tf +++ b/terraform/ai/vsphere/main.tf @@ -3,6 +3,7 @@ locals { control_planes = [for idx in range(var.control_plane_count) : "${var.cluster_id}-control-plane-${idx}"] compute_nodes = [for idx in range(var.compute_count) : "${var.cluster_id}-compute-${idx}"] guest_id = "rhel8_64Guest" + dns_zone_id = one(data.aws_route53_zone.dns_zone[*].zone_id) } // configure connection to vSphere @@ -37,6 +38,32 @@ data "vsphere_network" "network" { distributed_virtual_switch_uuid = "" } +// get DNS zone for creating API and Ingress A records +data "aws_route53_zone" "dns_zone" { + count = var.base_domain != null ? 1 : 0 + name = var.base_domain +} + +// create DNS A record for API (only if api_ip is defined) +resource "aws_route53_record" "api_a_record" { + count = var.api_ip != null ? 1 : 0 + type = "A" + ttl = "60" + zone_id = local.dns_zone_id + name = "api.${var.cluster_id}.${var.base_domain}" + records = [var.api_ip] +} + +// create DNS A record for Ingress (only if ingress_ip is defined) +resource "aws_route53_record" "ingress_a_record" { + count = var.ingress_ip != null ? 1 : 0 + type = "A" + ttl = "60" + zone_id = local.dns_zone_id + name = "*.apps.${var.cluster_id}.${var.base_domain}" + records = [var.ingress_ip] +} + // create Resource Pool for VMs resource "vsphere_resource_pool" "resource_pool" { name = var.cluster_id diff --git a/terraform/ai/vsphere/terraform.tfvars.example b/terraform/ai/vsphere/terraform.tfvars.example index 788e38bb7ee..cfd9d2024bf 100644 --- a/terraform/ai/vsphere/terraform.tfvars.example +++ b/terraform/ai/vsphere/terraform.tfvars.example @@ -56,3 +56,12 @@ compute_data_disks_count = "2" // The size of data disks for Compute VMs, in GB. // Default 256 GB. compute_data_disks_size = "256" + +// Base DNS domain, where should be the cluster records created +// base_domain = "example.com" + +// API IP address, if not defined no DNS record is created +// api_ip = "192.0.2.2" + +// Ingress IP address, if not defined no DNS record is created +// ingress_ip = "192.0.2.3" diff --git a/terraform/ai/vsphere/variables.tf b/terraform/ai/vsphere/variables.tf index 435916c884f..467ad6ef117 100644 --- a/terraform/ai/vsphere/variables.tf +++ b/terraform/ai/vsphere/variables.tf @@ -58,6 +58,24 @@ variable "system_disk_size" { default = "120" } +variable "base_domain" { + type = string + default = null + description = "Base DNS domain, where should be the cluster records created" +} + +variable "api_ip" { + type = string + default = null + description = "API IP address, if not defined DNS record is not created" +} + +variable "ingress_ip" { + type = string + default = null + description = "Ingress IP address, if not defined DNS record is not created" +} + /////////// // control-plane machine variables ///////////