diff --git a/terraform/eval_state_upgrade.go b/terraform/eval_state_upgrade.go index b7720d71b..e1940005e 100644 --- a/terraform/eval_state_upgrade.go +++ b/terraform/eval_state_upgrade.go @@ -19,26 +19,13 @@ import ( // If any errors occur during upgrade, error diagnostics are returned. In that // case it is not safe to proceed with using the original state object. func UpgradeResourceState(addr addrs.AbsResourceInstance, provider providers.Interface, src *states.ResourceInstanceObjectSrc, currentSchema *configschema.Block, currentVersion uint64) (*states.ResourceInstanceObjectSrc, tfdiags.Diagnostics) { - currentTy := currentSchema.ImpliedType() - - // If the state is currently in flatmap format and the current schema - // contains DynamicPseudoType attributes then we won't be able to convert - // it to JSON without the provider's help even if the schema version matches, - // since only the provider knows how to interpret the dynamic attribute - // value in flatmap format to convert it to JSON. - schemaHasDynamic := currentTy.HasDynamicTypes() - stateIsFlatmap := len(src.AttrsJSON) == 0 - forceProviderUpgrade := schemaHasDynamic && stateIsFlatmap - - if src.SchemaVersion == currentVersion && !forceProviderUpgrade { - // No upgrading required, then. - return src, nil - } if addr.Resource.Resource.Mode != addrs.ManagedResourceMode { // We only do state upgrading for managed resources. return src, nil } + stateIsFlatmap := len(src.AttrsJSON) == 0 + providerType := addr.Resource.Resource.DefaultProviderConfig().Type if src.SchemaVersion > currentVersion { log.Printf("[TRACE] UpgradeResourceState: can't downgrade state for %s from version %d to %d", addr, src.SchemaVersion, currentVersion) @@ -60,7 +47,11 @@ func UpgradeResourceState(addr addrs.AbsResourceInstance, provider providers.Int // v0.12, this also includes translating from legacy flatmap to new-style // representation, since only the provider has enough information to // understand a flatmap built against an older schema. - log.Printf("[TRACE] UpgradeResourceState: upgrading state for %s from version %d to %d using provider %q", addr, src.SchemaVersion, currentVersion, providerType) + if src.SchemaVersion != currentVersion { + log.Printf("[TRACE] UpgradeResourceState: upgrading state for %s from version %d to %d using provider %q", addr, src.SchemaVersion, currentVersion, providerType) + } else { + log.Printf("[TRACE] UpgradeResourceState: schema version of %s is still %d; calling provider %q for any other minor fixups", addr, currentVersion, providerType) + } req := providers.UpgradeResourceStateRequest{ TypeName: addr.Resource.Resource.Type,