Invicton-Labs / terraform-null-deepmerge

This module performs a deep map merge of standard Terraform maps/objects
MIT License
40 stars 16 forks source link

error returned when list elements contain different fields #5

Open chkp-amirtal opened 2 years ago

chkp-amirtal commented 2 years ago

example case:

module "deepmerge" {
  source  = "Invicton-Labs/deepmerge/null"
  version = "0.1.4"

  maps = [
    yamldecode(<<YAML
top:
  - name: NAME_1
    param: value1
    param2: 
      test: test
  - name: NAME_2
    param: value2
  - name: NAME_3
    param: value3
  - name: NAME_4
    param: value4
YAML
    ),
    {},
  ]
}

resource "null_resource" "test" {
  triggers = {
    a = yamlencode(module.deepmerge.merged)
  }
}

running plan return an error:

❯ terraform plan

Error: Invalid function argument

  on .terraform/modules/deepmerge/depth.tf line 43, in locals:
  43:           for key in keys(item["value"]) :
    |----------------
    | item["value"] is tuple with 4 elements

Invalid value for "inputMap" parameter: must have map or object type.

Error: Invalid function argument

  on .terraform/modules/deepmerge/depth.tf line 55, in locals:
  55:           for key in keys(item["value"]) :
    |----------------
    | item["value"] is tuple with 4 elements

Invalid value for "inputMap" parameter: must have map or object type.

to correct the error is is required to match all missing fields where needed, i.e.:

module "deepmerge" {
  source  = "Invicton-Labs/deepmerge/null"
  version = "0.1.4"

  maps = [
    yamldecode(<<YAML
top:
  - name: NAME_1
    param: value1
    param2: 
      test: test
  - name: NAME_2
    param: value2
    param2: {}
  - name: NAME_3
    param: value3
    param2: {}
  - name: NAME_4
    param: value4
    param2: {}
YAML
    ),
    {},
  ]
}

running plan will return correct results. but this yaml might not always be usable by the backend system. different items may require or support a different set of fields.