Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

[RM-5823] Fix type mismatch when constructing cty value #176

Merged
merged 1 commit into from
Aug 20, 2021

Conversation

jaspervdj-luminal
Copy link
Member

The TF loader uses two representations of the document:

  1. The native Go fashion, e.g. []interface{} for arrays,
    map[string]interface{} for objects, etc.
  2. A more typed version, using the cty library.

When dealing with variables, we must sometimes convert from (1) to (2). cty
requires lists to be homogenous. This is usually not a problem since the types
in the schemas enforce this; however, in some cases we don't have these schemas,
and this list ends up looking heterogenous:

[
    {
      rule_no    = 100
      cidr_block = "0.0.0.0/0"
    },
    {
      rule_no         = 101
      ipv6_cidr_block = "::/0"
    },
]

We work around this by using a tuple instead of a list which allows for
different types.

The TF loader uses two representations of the document:

1.  The native Go fashion, e.g. `[]interface{}` for arrays,
    `map[string]interface{}` for objects, etc.
2.  A more typed version, using the `cty` library.

When dealing with variables, we must sometimes convert from (1) to (2). `cty`
requires lists to be homogenous.  This is usually not a problem since the types
in the schemas enforce this; however, in some cases we don't have these schemas,
and this list ends up looking heterogenous:

    [
        {
          rule_no    = 100
          cidr_block = "0.0.0.0/0"
        },
        {
          rule_no         = 101
          ipv6_cidr_block = "::/0"
        },
    ]

We work around this by using a tuple instead of a list which allows for
different types.
@jaspervdj-luminal jaspervdj-luminal merged commit 6333225 into master Aug 20, 2021
@jaspervdj-luminal jaspervdj-luminal deleted the feature/RM-5823/list-tuple branch August 20, 2021 17:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants