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

StateUpgrade cross-tests #1736

Open
Tracked by #1796
t0yv0 opened this issue Mar 6, 2024 · 1 comment
Open
Tracked by #1796

StateUpgrade cross-tests #1736

t0yv0 opened this issue Mar 6, 2024 · 1 comment
Labels
kind/engineering Work that is not visible to an external user

Comments

@t0yv0
Copy link
Member

t0yv0 commented Mar 6, 2024

Build cross-tests for checking that Pulumi and TF handle state upgrades identically.

TF implements state upgraders feature in the SDKv2 that amounts to having providers specify code that modifies state written by previous versions of the provider.

  // Implementation of a single schema version state upgrade.
  type StateUpgrader struct {
          // Version is the version schema that this Upgrader will handle, converting
          // it to Version+1.
          Version int

          // Type describes the schema that this function can upgrade. Type is
          // required to decode the schema if the state was stored in a legacy
          // flatmap format.
          Type cty.Type

          // Upgrade takes the JSON encoded state and the provider meta value, and
          // upgrades the state one single schema version. The provided state is
          // deocded into the default json types using a map[string]interface{}. It
          // is up to the StateUpgradeFunc to ensure that the returned value can be
          // encoded using the new schema.
          Upgrade StateUpgradeFunc
  }

  type StateUpgradeFunc func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error)

In Go pseudo-code this could look like this:

  s1 := anySchema()
  var s2 func (StateUpgradeFunc) Schema 
  i1 := anyInput(s1)
  var i2 func (StateUpgradeFunc) Inputs

  spy1, spy2 := spyStateUpgradeFunc(), spyStateUpgradeFunc()

  pulumiUp(s1, i1)
  pulumiUp(s2(spy1.fn), i2(spy2.fn))

  tfApply(s1, i1)
  tfApply(s2(spy1.fn), i2(spy2.fn))

  assert.Equalt(t, spy1.args, spy2.args)

Having significant coverage against a range of schemas would help refactor the code with confidence.

@VenelinMartinov
Copy link
Contributor

Partially addressed by #2040

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/engineering Work that is not visible to an external user
Projects
None yet
Development

No branches or pull requests

3 participants