Hello,
I have a configuration that deploys VMware vCloud environment (3 db servers + 2 app cells). right now the configuration is written out in the long format:
- variable definitions are declared at root and child
- single .tfvars with all values passed in
- within root module/main.tf => child is called all variables are passed as argument
This process works but looks very messy and repetitive code.
I am trying to make the root/main.tf look cleaner by using locals to prevent duplicate code within.
Question:
Are you able to do something like this to group variables and pass them into a child when calling a module?
[snipet - not full code]
# Locals to pass root variables to child modules
locals {
vcda_universal_options_config = {
vdatacenter_name = var.vdatacenter_name
vmware_datastore_initial_deployment = var.vmware_datastore_initial_deployment
vmware_compute_cluster_mgmtcl01 = var.vmware_compute_cluster_mgmtcl01
vmware_esxi_mgmtcl01_esxi01 = var.vmware_esxi_mgmtcl01_esxi01
vmware_ovf_fullpath_local = var.vmware_ovf_fullpath_local
vcda_ntp_server = var.vcda_ntp_server
vcda_domain_name = var.vcda_domain_name
vcda_domain_searchpath = var.vcda_domain_searchpath
vcda_dns_servers = var.vcda_dns_servers
vcda_nfs_mount_for_transfer = var.vcda_nfs_mount_for_transfer
vcda_installation_id = var.vcda_installation_id
vcda_unique_systemname = var.vcda_unique_systemname
}
vcda_dbservers_options_config = {
vcda_routes1 = var.vcda_dbservers_routes1
vcda_default_gateway = var.vcda_dbservers_default_gateway
}
vcda_db1_options_config = {
vmware_vcda_vmname = var.vmware_vcda_db1_vmname
vcda_eth0_ip = var.vcda_db1_eth0_ip
vcda_eth0_netmask = var.vcda_db1_eth0_netmask
vcda_eth1_ip = var.vcda_db1_eth1_ip
vcda_eth1_netmask = var.vcda_db1_eth1_netmask
}
}
# Declare modules
module "vcda_initial_db_master" {
source = "./modules/vcda_initial_db_master"
child_vars = [
local.vcda_universal_options_config,
local.vcda_dbservers_options_config,
local.vcda_db1_options_config
]
}
module "vcda_initial_db_secondary" {
source = "./modules/vcda_initial_db_secondary"
depends_on = [
module.timer_delay_for_db_master
]
child_vars = [
local.vcda_universal_options_config,
local.vcda_dbservers_options_config,
local.vcda_db2_options_config
]
}