states/statefile: staticcheck
This commit is contained in:
parent
c2f8b06594
commit
c6cea8efc3
|
@ -165,10 +165,3 @@ type instanceStateV1 struct {
|
||||||
// external client code.
|
// external client code.
|
||||||
Meta map[string]string `json:"meta,omitempty"`
|
Meta map[string]string `json:"meta,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ephemeralStateV1 struct {
|
|
||||||
// ConnInfo is used for the providers to export information which is
|
|
||||||
// used to connect to the resource for provisioning. For example,
|
|
||||||
// this could contain SSH or WinRM credentials.
|
|
||||||
ConnInfo map[string]string `json:"-"`
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package statefile
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/tfdiags"
|
"github.com/hashicorp/terraform/tfdiags"
|
||||||
)
|
)
|
||||||
|
@ -95,8 +94,6 @@ type outputStateV2 struct {
|
||||||
// Value contains the value of the output, in the structure described
|
// Value contains the value of the output, in the structure described
|
||||||
// by the Type field.
|
// by the Type field.
|
||||||
Value interface{} `json:"value"`
|
Value interface{} `json:"value"`
|
||||||
|
|
||||||
mu sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type moduleStateV2 struct {
|
type moduleStateV2 struct {
|
||||||
|
@ -178,8 +175,6 @@ type resourceStateV2 struct {
|
||||||
// e.g. "aws_instance" goes with the "aws" provider.
|
// e.g. "aws_instance" goes with the "aws" provider.
|
||||||
// If the resource block contained a "provider" key, that value will be set here.
|
// If the resource block contained a "provider" key, that value will be set here.
|
||||||
Provider string `json:"provider"`
|
Provider string `json:"provider"`
|
||||||
|
|
||||||
mu sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type instanceStateV2 struct {
|
type instanceStateV2 struct {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package statefile
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -336,35 +335,6 @@ func upgradeInstanceObjectV3ToV4(rsOld *resourceStateV2, isOld *instanceStateV2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies := make([]string, 0, len(rsOld.Dependencies))
|
|
||||||
for _, v := range rsOld.Dependencies {
|
|
||||||
depStr, err := parseLegacyDependency(v)
|
|
||||||
if err != nil {
|
|
||||||
// We just drop invalid dependencies on the floor here, because
|
|
||||||
// they tend to get left behind in Terraform 0.11 when resources
|
|
||||||
// are renamed or moved between modules and there's no automatic
|
|
||||||
// way to fix them here. In practice it shouldn't hurt to miss
|
|
||||||
// a few dependency edges in the state because a subsequent plan
|
|
||||||
// will run a refresh walk first and re-synchronize the
|
|
||||||
// dependencies with the configuration.
|
|
||||||
//
|
|
||||||
// There is one rough edges where this can cause an incorrect
|
|
||||||
// result, though: If the first command the user runs after
|
|
||||||
// upgrading to Terraform 0.12 uses -refresh=false and thus
|
|
||||||
// prevents the dependency reorganization from occurring _and_
|
|
||||||
// that initial plan discovered "orphaned" resources (not present
|
|
||||||
// in configuration any longer) then when the plan is applied the
|
|
||||||
// destroy ordering will be incorrect for the instances of those
|
|
||||||
// resources. We expect that is a rare enough situation that it
|
|
||||||
// isn't a big deal, and even when it _does_ occur it's common for
|
|
||||||
// the apply to succeed anyway unless many separate resources with
|
|
||||||
// complex inter-dependencies are all orphaned at once.
|
|
||||||
log.Printf("statefile: ignoring invalid dependency address %q while upgrading from state version 3 to version 4: %s", v, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
dependencies = append(dependencies, depStr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &instanceObjectStateV4{
|
return &instanceObjectStateV4{
|
||||||
IndexKey: instKeyRaw,
|
IndexKey: instKeyRaw,
|
||||||
Status: status,
|
Status: status,
|
||||||
|
@ -473,28 +443,3 @@ func simplifyImpliedValueType(ty cty.Type) cty.Type {
|
||||||
return ty
|
return ty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseLegacyDependency(s string) (string, error) {
|
|
||||||
parts := strings.Split(s, ".")
|
|
||||||
ret := parts[0]
|
|
||||||
for _, part := range parts[1:] {
|
|
||||||
if part == "*" {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if i, err := strconv.Atoi(part); err == nil {
|
|
||||||
ret = ret + fmt.Sprintf("[%d]", i)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
ret = ret + "." + part
|
|
||||||
}
|
|
||||||
|
|
||||||
// The result must parse as a reference, or else we'll create an invalid
|
|
||||||
// state file.
|
|
||||||
var diags tfdiags.Diagnostics
|
|
||||||
_, diags = addrs.ParseRefStr(ret)
|
|
||||||
if diags.HasErrors() {
|
|
||||||
return "", diags.Err()
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret, nil
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue