terraform-aws-documentdb-cluster icon indicating copy to clipboard operation
terraform-aws-documentdb-cluster copied to clipboard

TFVARS not actually work in the example

Open ssamantasinghar opened this issue 1 year ago • 0 comments

Describe the Feature

I tried going through the example tfvars and the tfvars dont seem to be mapped to any resource defined in the main.tf. So I tried the example .tfvars file and tried to generate a plan but it was still asking me to provide various inputs like availability_zones, VPC CIDR block etc. My question is if someone wants to use your module for creating multiple clusters then how is that going to work?

Expected Behavior

example tfvars cluster = { cluster1 = { cluster_identifier = "cluster1" region = "us-east-1" availability_zones = ["us-east-1a", "us-east-1b"] namespace = "eg" stage = "test" name = "documentdb-cluster" vpc_cidr_block = "X.X.32.0/20" instance_class = "db.t4g.medium" cluster_size = 1 db_port = 27017 master_username = "admin1" master_password = "password1" retention_period = 5 preferred_backup_window = "07:00-09:00" cluster_family = "docdb5.0" engine_version = "5.0.0" engine = "docdb" storage_encrypted = true storage_type = "standard" skip_final_snapshot = true apply_immediately = true ssm_parameter_enabled = false }, } example docdb.tf ` module "documentdb_cluster" { source = "/path/to/module/docdb" for_each = (var.documentdb_cluster != null || var.documentdb_cluster != {}) ? var.documentdb_cluster : {} cluster_identifier = each.value.cluster_identifier cluster_size = each.value.cluster_size master_username = each.value.master_username master_password = each.value.master_password instance_class = each.value.instance_class db_port = each.value.db_port vpc_id = module.vpc.vpc_id subnet_ids = module.subnets.private_subnet_ids zone_id = each.value.zone_id apply_immediately = each.value.apply_immediately auto_minor_version_upgrade = each.value.auto_minor_version_upgrade allowed_security_groups = each.value.allowed_security_groups allowed_cidr_blocks = each.value.allowed_cidr_blocks snapshot_identifier = each.value.snapshot_identifier retention_period = each.value.retention_period preferred_backup_window = each.value.preferred_backup_window preferred_maintenance_window = each.value.preferred_maintenance_window cluster_parameters = each.value.cluster_parameters cluster_family = each.value.cluster_family engine = each.value.engine engine_version = each.value.engine_version storage_encrypted = each.value.storage_encrypted storage_type = each.value.storage_type kms_key_id = each.value.kms_key_id skip_final_snapshot = each.value.skip_final_snapshot enabled_cloudwatch_logs_exports = each.value.enabled_cloudwatch_logs_exports cluster_dns_name = each.value.cluster_dns_name reader_dns_name = each.value.reader_dns_name ssm_parameter_enabled = each.value.ssm_parameter_enabled

context = module.this.context } `

Use Case

This model will enable users to use the modules to be able to create multiple clusters managing all there inputs through single tfvars file

Describe Ideal Solution

example tfvars cluster = { cluster1 = { cluster_identifier = "cluster1" region = "us-east-1" availability_zones = ["us-east-1a", "us-east-1b"] namespace = "eg" stage = "test" name = "documentdb-cluster" vpc_cidr_block = "X.X.32.0/20" instance_class = "db.t4g.medium" cluster_size = 1 db_port = 27017 master_username = "admin1" master_password = "password1" retention_period = 5 preferred_backup_window = "07:00-09:00" cluster_family = "docdb5.0" engine_version = "5.0.0" engine = "docdb" storage_encrypted = true storage_type = "standard" skip_final_snapshot = true apply_immediately = true ssm_parameter_enabled = false }, } example docdb.tf ` module "documentdb_cluster" { source = "/path/to/module/docdb" for_each = (var.documentdb_cluster != null || var.documentdb_cluster != {}) ? var.documentdb_cluster : {} cluster_identifier = each.value.cluster_identifier cluster_size = each.value.cluster_size master_username = each.value.master_username master_password = each.value.master_password instance_class = each.value.instance_class db_port = each.value.db_port vpc_id = module.vpc.vpc_id subnet_ids = module.subnets.private_subnet_ids zone_id = each.value.zone_id apply_immediately = each.value.apply_immediately auto_minor_version_upgrade = each.value.auto_minor_version_upgrade allowed_security_groups = each.value.allowed_security_groups allowed_cidr_blocks = each.value.allowed_cidr_blocks snapshot_identifier = each.value.snapshot_identifier retention_period = each.value.retention_period preferred_backup_window = each.value.preferred_backup_window preferred_maintenance_window = each.value.preferred_maintenance_window cluster_parameters = each.value.cluster_parameters cluster_family = each.value.cluster_family engine = each.value.engine engine_version = each.value.engine_version storage_encrypted = each.value.storage_encrypted storage_type = each.value.storage_type kms_key_id = each.value.kms_key_id skip_final_snapshot = each.value.skip_final_snapshot enabled_cloudwatch_logs_exports = each.value.enabled_cloudwatch_logs_exports cluster_dns_name = each.value.cluster_dns_name reader_dns_name = each.value.reader_dns_name ssm_parameter_enabled = each.value.ssm_parameter_enabled

context = module.this.context } `

Alternatives Considered

No response

Additional Context

No response

ssamantasinghar avatar Aug 17 '24 14:08 ssamantasinghar