Skip to content

Commit

Permalink
states/statefile: staticcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
jbardin committed Dec 2, 2020
1 parent c2f8b06 commit c6cea8e
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 67 deletions.
7 changes: 0 additions & 7 deletions states/statefile/version1.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,3 @@ type instanceStateV1 struct {
// external client code.
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:"-"`
}
5 changes: 0 additions & 5 deletions states/statefile/version2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package statefile
import (
"encoding/json"
"fmt"
"sync"

"github.com/hashicorp/terraform/tfdiags"
)
Expand Down Expand Up @@ -95,8 +94,6 @@ type outputStateV2 struct {
// Value contains the value of the output, in the structure described
// by the Type field.
Value interface{} `json:"value"`

mu sync.Mutex
}

type moduleStateV2 struct {
Expand Down Expand Up @@ -178,8 +175,6 @@ type resourceStateV2 struct {
// e.g. "aws_instance" goes with the "aws" provider.
// If the resource block contained a "provider" key, that value will be set here.
Provider string `json:"provider"`

mu sync.Mutex
}

type instanceStateV2 struct {
Expand Down
55 changes: 0 additions & 55 deletions states/statefile/version3_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package statefile
import (
"encoding/json"
"fmt"
"log"
"strconv"
"strings"

Expand Down Expand Up @@ -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{
IndexKey: instKeyRaw,
Status: status,
Expand Down Expand Up @@ -473,28 +443,3 @@ func simplifyImpliedValueType(ty cty.Type) cty.Type {
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
}

0 comments on commit c6cea8e

Please sign in to comment.