Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/fatih/color v1.15.0
github.com/golang/mock v1.6.0
github.com/hashicorp/terraform-json v0.20.0
github.com/hashicorp/terraform-json v0.27.2
github.com/m1gwings/treedrawer v0.3.3-beta
github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249
github.com/olekukonko/tablewriter v0.0.5
Expand All @@ -15,12 +15,12 @@ require (
require (
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/zclconf/go-cty v1.14.1 // indirect
github.com/zclconf/go-cty v1.16.4 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.11.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/terraform-json v0.20.0 h1:cJcvn4gIOTi0SD7pIy+xiofV1zFA3hza+6K+fo52IX8=
github.com/hashicorp/terraform-json v0.20.0/go.mod h1:qdeBs11ovMzo5puhrRibdD6d2Dq6TyE/28JiU4tIQxk=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/terraform-json v0.27.2 h1:BwGuzM6iUPqf9JYM/Z4AF1OJ5VVJEEzoKST/tRDBJKU=
github.com/hashicorp/terraform-json v0.27.2/go.mod h1:GzPLJ1PLdUG5xL6xn1OXWIjteQRT2CNT9o/6A9mi9hE=
github.com/m1gwings/treedrawer v0.3.3-beta h1:VeeQ4I90+NL0G2Tga3H4EY4hbOyVP3ID4T93r21oLbQ=
github.com/m1gwings/treedrawer v0.3.3-beta/go.mod h1:Sebh5tCtjQWAG/B9xWct163vB9pCbBcA1ykaUErDUTY=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand All @@ -32,8 +32,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/zclconf/go-cty v1.14.1 h1:t9fyA35fwjjUMcmL5hLER+e/rEPqrbCK1/OSE4SI9KA=
github.com/zclconf/go-cty v1.14.1/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
github.com/zclconf/go-cty v1.16.4 h1:QGXaag7/7dCzb+odlGrgr+YmYZFaOCMW6DEpS+UD1eE=
github.com/zclconf/go-cty v1.16.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
Expand Down
11 changes: 9 additions & 2 deletions terraformstate/terraform_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func importedResources(resources ResourceChanges) ResourceChanges {
}

id := r.Change.Importing.ID
if id != "" {
identity := r.Change.Importing.Identity
if id != "" || identity != nil {
acc = append(acc, r)
}
}
Expand All @@ -93,7 +94,13 @@ func importedResources(resources ResourceChanges) ResourceChanges {
func FilterNoOpResources(ts *tfjson.Plan) {
acc := make(ResourceChanges, 0)
for _, r := range ts.ResourceChanges {
if len(r.Change.Actions) == 1 && r.Change.Actions[0] == "no-op" && (r.Change.Importing == nil || r.Change.Importing.ID == "") {
// ID-based importing
oldImporting := r.Change.Importing != nil && r.Change.Importing.ID != ""

// New identity-based importing introduced in terraform 1.12
newImporting := r.Change.Importing != nil && r.Change.Importing.Identity != nil

if r.Change.Actions.NoOp() && !oldImporting && !newImporting {
continue
}
acc = append(acc, r)
Expand Down
4 changes: 4 additions & 0 deletions terraformstate/terraform_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,22 @@ func TestResourceChangeColorAndSuffixImport(t *testing.T) {
}

func TestFilterNoOpResources(t *testing.T) {
identityImport := &ResourceChange{Address: "no-op5", Change: &Change{Actions: Actions{ActionNoop}, Importing: &Importing{Identity: struct{ Account string }{Account: "account ID"}}}}
resourceChanges := ResourceChanges{
&ResourceChange{Address: "no-op1", Change: &Change{Actions: Actions{ActionNoop}}},
&ResourceChange{Address: "no-op3", Change: &Change{Actions: Actions{ActionNoop}, Importing: nil}},
&ResourceChange{Address: "no-op2", Change: &Change{Actions: Actions{ActionNoop}, Importing: &Importing{ID: ""}}},
&ResourceChange{Address: "no-op4", Change: &Change{Actions: Actions{ActionNoop}, Importing: &Importing{Identity: nil}}},
&ResourceChange{Address: "create", Change: &Change{Actions: Actions{ActionCreate}}},
identityImport,
}
plan := tfjson.Plan{ResourceChanges: resourceChanges}

FilterNoOpResources(&plan)

expectedResourceChangesAfterFiltering := ResourceChanges{
&ResourceChange{Address: "create", Change: &Change{Actions: Actions{ActionCreate}}},
identityImport,
}
assert.Equal(t, expectedResourceChangesAfterFiltering, plan.ResourceChanges)
}