Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert: Fix converting to nested dynamic map #47

Commits on Mar 3, 2020

  1. convert: Fix converting to nested dynamic map

    When converting an object tree to a nested dynamic map (for example,
    `cty.Map(cty.Map(cty.DynamicPseudoType))` or deeper), it is necessary to
    unify the types of the child elements of the map.
    
    Previously, we would only apply this process to the innermost leaf
    object's attributes, which could result in local unification but
    globally incompatible types. This caused a panic when converting the
    single top-level object into a map with concrete type, as the types of
    the sub-trees were incompatible.
    
    This commit addresses this class of bugs in two ways: adding type
    unification for multi-level map and object structures, and fallback
    error handling to prevent panics for this class of failure.
    
    The additional type unification process has several steps:
    
    - First, we add a second unify & convert step at the end of the process,
      immediately before constructing the final map. This second unification
      ensures that not only sibling elements but also cousins are of the
      same type.
    
    - We also ensure that generated type information is preserved for empty
      collections, by returning an empty map of the detected type, instead
      of the dynamic type. This prevents a multi-step unification bouncing
      back and forth between concrete and dynamic element types.
    
    - Finally, we add a specific unification procedure for map-to-map
      conversions. This inspects and unifies the element types for the maps
      which are being converted. For example, a populated map(string) and an
      empty map(any) will be unified to a map(string) type.
    
    Tests are extended to cover reduced configurations from the three source
    Terraform bugs which prompted this work.
    alisdair committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    8be809f View commit details
    Browse the repository at this point in the history
  2. Update cty/convert/public_test.go

    Co-Authored-By: Kristin Laemmert <[email protected]>
    alisdair and mildwonkey authored Mar 3, 2020
    Configuration menu
    Copy the full SHA
    65f6e09 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    e1048fb View commit details
    Browse the repository at this point in the history