Skip to content

Instantly share code, notes, and snippets.

@vancluever
Created May 24, 2017 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vancluever/3697c2255374aa15a1e49d066cf5c30e to your computer and use it in GitHub Desktop.
Save vancluever/3697c2255374aa15a1e49d066cf5c30e to your computer and use it in GitHub Desktop.
Terraform ResourceDiff notes

Why we don't want to use diff in ResourceDiff

  • scheamMap.diff needs d (and a bunch of other stuff)
  • writers don't generally need this stuff
  • relationship should be
  • scheaMap -> resource helper -> reader/writer

Challenges

  • Storing computed values in a pseudo-diff correctly
  • newValueWriter - A map[string]struct{Value interface{} Computed bool}
  • OR
  type newValueWriter struct{
    MapValueWriter
    ComputedKeys map[string]struct{} (or map[string]bool)
  }
  • Override ReadField with the following:
    result, err := w.MapValueWriter.ReadField(addr)
    if err != nil {
      return result, err
    }
    if _, ok := m.ComputedKeys[strings.Join(addr, ".")]; ok {
      result.Computed = true
    }
    return result, nil
  • Old values - go in a regular MapFieldWriter

Prototype Changes

  • SetDiff:
  • Wipe current diff
  • Set old and new values appropriately, including computed
  • Allow same values? Maybe.
  • SetNew/SetNewComputed
  • No change
  • ForceNew
  • Fixed to use schema
  • ClearAll
  • Clear whole diff
  • Clear
  • Main diff clearing logic (also used by SetDiff)
  • Get(Ok), HasChange, GetChange
  • Fixed to use readers
  • Id
  • Fixed to use readers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment