terraform-aws-modules / terraform-aws-dms

Terraform module to create AWS DMS (Database Migration Service) resources πŸ‡ΊπŸ‡¦
https://registry.terraform.io/modules/terraform-aws-modules/dms/aws
Apache License 2.0
60 stars 93 forks source link

Invalid function argument error when using merge method #64

Closed yuekui closed 1 week ago

yuekui commented 2 months ago

Description

To conditionally create an endpoint, we plan to use a merge method combined with a ternary expression. However, this approach may lead to an 'Invalid function argument' error because the lookup function might return a null value, which differs from the expected default type [].

Versions

Reproduction Code [Required]

locals {
  is_additional_task_needed = true
}

module "dms_aurora_postgresql_aurora_mysql" {
  # Endpoints
  endpoints = merge({
    postgresql-destination = {
      ...
    },local.is_additional_task_needed ? {
    mysql-source = {
      database_name = "foo"
      ...
    } } : {}
  )

Expected behavior

Endpoints should be created successfully

Actual behavior

Invalid function argument errors were raised when trying to lookup settings of each value

Terminal Output Screenshot(s)

image

Additional context

I've created a PR and added the conditional endpoints in example

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

yuekui commented 1 month ago

Hi @bryantbiggs , it would be great if you could review this when you have a chance. Thanks!

github-actions[bot] commented 1 week ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

yuekui commented 1 week ago

Just re-opened the PR, waiting for review

bryantbiggs commented 1 week ago

this looks like a dynamic workspace use issue, not a module issue. if you want to do this sort of dynamic "if this, then that", then you should use map comprehension instead of a conditional on the map object