Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dineshba/tf-summarize
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.3.10
Choose a base ref
...
head repository: dineshba/tf-summarize
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.3.11
Choose a head ref
  • 5 commits
  • 6 files changed
  • 3 contributors

Commits on Aug 28, 2024

  1. Sort results (#75)

    * Update terraform_state_test.go
    
    * Update build.yml
    
    * Sort results
    
    * Add tests  (#2)
    
    * Update terraform_state_test.go
    
    * Update terraform_state_test.go
    
    * Add tests to GetAllOutputChanges and GetAllResourceChanges
    
    * Update terraform_state_test.go
    lcssanches authored Aug 28, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    be5c60e View commit details
  2. Copy the full SHA
    a9ed1c4 View commit details

Commits on Sep 22, 2024

  1. Copy the full SHA
    e1c495e View commit details

Commits on Oct 2, 2024

  1. Copy the full SHA
    8ce1883 View commit details
  2. Fix gorelease yaml file

    dineshba committed Oct 2, 2024
    Copy the full SHA
    03c3508 View commit details
Showing with 93 additions and 10 deletions.
  1. +3 −5 .github/workflows/build.yml
  2. +3 −3 .github/workflows/release.yml
  3. +1 −1 .goreleaser.yml
  4. +1 −1 README.md
  5. +17 −0 terraformstate/terraform_state.go
  6. +68 −0 terraformstate/terraform_state_test.go
8 changes: 3 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -21,11 +21,9 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: "1.21"

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest

- name: Linter
uses: docker://morphy/revive-action:v2

- name: Test
run: go test -v ./...
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -46,11 +46,11 @@ jobs:

-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --rm-dist
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Visit https://goreleaser.com for documentation on how to customize this
# behavior.
version: 2
before:
hooks:
# this is just an example and not a requirement for provider building/publishing
@@ -84,5 +85,4 @@ release:
# If you want to manually examine the release before its live, uncomment this line:
draft: false
changelog:
skip: false
use: github
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -162,7 +162,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: kishaningithub/setup-tf-summarize@v1
17 changes: 17 additions & 0 deletions terraformstate/terraform_state.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package terraformstate
import (
"encoding/json"
"fmt"
"sort"

tfjson "github.com/hashicorp/terraform-json"
)
@@ -107,6 +108,18 @@ func GetAllResourceChanges(plan tfjson.Plan) map[string]ResourceChanges {
recreatedResources := recreatedResources(plan.ResourceChanges)
importedResources := importedResources(plan.ResourceChanges)

sortResources := func(resources ResourceChanges) {
sort.Slice(resources, func(i, j int) bool {
return resources[i].Address < resources[j].Address
})
}

sortResources(addedResources)
sortResources(deletedResources)
sortResources(updatedResources)
sortResources(recreatedResources)
sortResources(importedResources)

return map[string]ResourceChanges{
"import": importedResources,
"add": addedResources,
@@ -123,6 +136,10 @@ func GetAllOutputChanges(plan tfjson.Plan) map[string][]string {
deletedResources := filterOutputs(plan.OutputChanges, "delete")
updatedResources := filterOutputs(plan.OutputChanges, "update")

sort.Strings(addedResources)
sort.Strings(deletedResources)
sort.Strings(updatedResources)

return map[string][]string{
"add": addedResources,
"delete": deletedResources,
68 changes: 68 additions & 0 deletions terraformstate/terraform_state_test.go
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ func TestResourceChangeColor(t *testing.T) {

assert.Equal(t, color, expectedColor)
}

CreateDelete := &ResourceChange{Change: &Change{Actions: []Action{ActionCreate, ActionDelete}}}
color, _ := GetColorPrefixAndSuffixText(CreateDelete)
assert.Equal(t, color, ColorMagenta)
@@ -31,6 +32,73 @@ func TestResourceChangeColor(t *testing.T) {
assert.Equal(t, color, ColorMagenta)
}

func TestGetAllResourceChanges(t *testing.T) {
resourceChanges := ResourceChanges{
&ResourceChange{Address: "create2", Change: &Change{Actions: Actions{ActionCreate}}},
&ResourceChange{Address: "create1", Change: &Change{Actions: Actions{ActionCreate}}},
&ResourceChange{Address: "delete2", Change: &Change{Actions: Actions{ActionDelete}}},
&ResourceChange{Address: "delete1", Change: &Change{Actions: Actions{ActionDelete}}},
&ResourceChange{Address: "update2", Change: &Change{Actions: Actions{ActionUpdate}}},
&ResourceChange{Address: "update1", Change: &Change{Actions: Actions{ActionUpdate}}},
&ResourceChange{Address: "import2", Change: &Change{Importing: &Importing{ID: "id1"}}},
&ResourceChange{Address: "import1", Change: &Change{Importing: &Importing{ID: "id2"}}},
&ResourceChange{Address: "recreate2", Change: &Change{Actions: Actions{ActionDelete, ActionCreate}}},
&ResourceChange{Address: "recreate1", Change: &Change{Actions: Actions{ActionDelete, ActionCreate}}},
}
plan := tfjson.Plan{ResourceChanges: resourceChanges}

result := GetAllResourceChanges(plan)

expectedResourceChanges := map[string]ResourceChanges{
"add": {
&ResourceChange{Address: "create1", Change: &Change{Actions: Actions{ActionCreate}}},
&ResourceChange{Address: "create2", Change: &Change{Actions: Actions{ActionCreate}}},
},
"delete": {
&ResourceChange{Address: "delete1", Change: &Change{Actions: Actions{ActionDelete}}},
&ResourceChange{Address: "delete2", Change: &Change{Actions: Actions{ActionDelete}}},
},
"update": {
&ResourceChange{Address: "update1", Change: &Change{Actions: Actions{ActionUpdate}}},
&ResourceChange{Address: "update2", Change: &Change{Actions: Actions{ActionUpdate}}},
},
"recreate": {
&ResourceChange{Address: "recreate1", Change: &Change{Actions: Actions{ActionDelete, ActionCreate}}},
&ResourceChange{Address: "recreate2", Change: &Change{Actions: Actions{ActionDelete, ActionCreate}}},
},
"import": {
&ResourceChange{Address: "import1", Change: &Change{Importing: &Importing{ID: "id2"}}},
&ResourceChange{Address: "import2", Change: &Change{Importing: &Importing{ID: "id1"}}},
},
}

assert.Equal(t, expectedResourceChanges, result)
}

func TestGetAllOutputChanges(t *testing.T) {

outputChanges := map[string]*Change{
"create2": {Actions: Actions{ActionCreate}},
"create1": {Actions: Actions{ActionCreate}},
"delete2": {Actions: Actions{ActionDelete}},
"delete1": {Actions: Actions{ActionDelete}},
"update2": {Actions: Actions{ActionUpdate}},
"update1": {Actions: Actions{ActionUpdate}},
}

plan := tfjson.Plan{OutputChanges: outputChanges}

result := GetAllOutputChanges(plan)

expectedResourceChanges := map[string][]string{
"add": {"create1", "create2"},
"delete": {"delete1", "delete2"},
"update": {"update1", "update2"},
}

assert.Equal(t, expectedResourceChanges, result)
}

func TestResourceChangeSuffix(t *testing.T) {
ExpectedSuffix := map[Action]string{
ActionCreate: "(+)",