Skip to content

Commit

Permalink
Merge pull request #14 from breml/from-to-json
Browse files Browse the repository at this point in the history
Update dependencies, add support for from/to jsonInJson
  • Loading branch information
breml authored Aug 9, 2024
2 parents b13c8ce + bbb60fe commit 6a1617b
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 649 deletions.
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/breml/tfreveal
go 1.22.3

require (
github.com/breml/jsondiffprinter v0.0.10
github.com/breml/jsondiffprinter v0.0.11
github.com/ghetzel/go-stockutil v1.11.4
github.com/hashicorp/terraform-json v0.22.1
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
Expand All @@ -20,24 +20,24 @@ require (
github.com/ghetzel/uuid v0.0.0-20171129191014-dec09d789f3d // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/jbenet/go-base58 v0.0.0-20150317085156-6237cf65f3a6 // indirect
github.com/jdkato/prose v1.2.1 // indirect
github.com/juliangruber/go-intersect v1.1.0 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/tidwall/gjson v1.17.1 // indirect
github.com/tidwall/gjson v1.17.3 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
github.com/zclconf/go-cty v1.14.4 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
github.com/zclconf/go-cty v1.15.0 // indirect
golang.org/x/text v0.17.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/neurosnap/sentences.v1 v1.0.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/client-go v0.24.1 // indirect
k8s.io/client-go v0.30.3 // indirect
)
609 changes: 20 additions & 589 deletions go.sum

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package main

import (
"bytes"
"io"
"os"
"path/filepath"
"sync"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -23,20 +25,29 @@ func TestMain0(t *testing.T) {
r, w, err := os.Pipe()
require.NoError(t, err)

var copyErr error
buf := bytes.NewBuffer(nil)
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
_, copyErr = io.Copy(buf, r)
}()

os.Stdout = w

err = main0([]string{"tfreveal", "--no-color", filepath.Join(filename, "plan.json")})
require.NoError(t, err)
err = w.Close()
require.NoError(t, err)

out, err := io.ReadAll(r)
require.NoError(t, err)

want, err := os.ReadFile(filepath.Join(filename, "output.golden"))
require.NoError(t, err)

require.Equal(t, string(want), string(out))
wg.Wait()
require.NoError(t, copyErr)

require.Equal(t, string(want), buf.String())
})
}
}
12 changes: 12 additions & 0 deletions testdata/advanced/after/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ resource "local_file" "foo" {
file_permission = "0660"
}

resource "local_file" "string2json" {
content = jsonencode({
"key": "some random json"
})
filename = "${path.module}/string2json"
}

resource "local_file" "json2string" {
content = "some random string"
filename = "${path.module}/json2string"
}

output "string" {
value = "some text 1"
}
12 changes: 12 additions & 0 deletions testdata/advanced/before/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ resource "local_file" "foo" {
filename = "${path.module}/foo.bar"
}

resource "local_file" "string2json" {
content = "some random string"
filename = "${path.module}/string2json"
}

resource "local_file" "json2string" {
content = jsonencode({
"key": "some random json"
})
filename = "${path.module}/json2string"
}

output "string" {
value = "some text"
}
44 changes: 39 additions & 5 deletions testdata/advanced/output.golden
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,43 @@ Changes to Resources:
# (5 unchanged attribute hidden)
}

# local_file.json2string must be replaced
-/+ local_file.json2string = {
~ content = jsonencode(
{
- key = "some random json"
}
) -> "some random string" # forces replacement
~ content_base64sha256 = "HYsNaOjaBgmFTRuYj4T4J4Ve7InaRVmfw2wgDbwr8Cs=" -> "(known after apply)"
~ content_base64sha512 = "COm1PXnJevPHVeZququDXk5+U5hDeA4dLmTnUpdeMhoF/3+isI46Hgkg5Dln9HCVN7Ythqjq4mrIP4t67bq3Ow==" -> "(known after apply)"
~ content_md5 = "31dd41a76bb193c928caf767ac8e8340" -> "(known after apply)"
~ content_sha1 = "72e1eb91ff698efdaa1a82b5977634a04cf2985d" -> "(known after apply)"
~ content_sha256 = "1d8b0d68e8da0609854d1b988f84f827855eec89da45599fc36c200dbc2bf02b" -> "(known after apply)"
~ content_sha512 = "08e9b53d79c97af3c755e66abaab835e4e7e539843780e1d2e64e752975e321a05ff7fa2b08e3a1e0920e43967f4709537b62d86a8eae26ac83f8b7aedbab73b" -> "(known after apply)"
~ id = "72e1eb91ff698efdaa1a82b5977634a04cf2985d" -> "(known after apply)"
# (6 unchanged attribute hidden)
}

# local_file.string2json must be replaced
-/+ local_file.string2json = {
~ content = "some random string" -> jsonencode(
{
+ key = "some random json"
}
) # forces replacement
~ content_base64sha256 = "Q0LgjQHySsRRvDu/9oZAhWO1wm04bQwYh5JE9eeXTX0=" -> "(known after apply)"
~ content_base64sha512 = "eaxV3784RhIgGecPVkfZ+wZlola4sUqDaG/V8Hr+Y5LKG7a3UJ5UkF9VRA4UYOGmtnlGI0hcm7nVJeq2u1AGFw==" -> "(known after apply)"
~ content_md5 = "76712b27e483bc0ba2ce8d2109210c22" -> "(known after apply)"
~ content_sha1 = "8d7219cf3e6259b90b70d5b5e2d39b27f946e4b8" -> "(known after apply)"
~ content_sha256 = "4342e08d01f24ac451bc3bbff686408563b5c26d386d0c18879244f5e7974d7d" -> "(known after apply)"
~ content_sha512 = "79ac55dfbf3846122019e70f5647d9fb0665a256b8b14a83686fd5f07afe6392ca1bb6b7509e54905f55440e1460e1a6b6794623485c9bb9d525eab6bb500617" -> "(known after apply)"
~ id = "8d7219cf3e6259b90b70d5b5e2d39b27f946e4b8" -> "(known after apply)"
# (6 unchanged attribute hidden)
}

# null_resource.cluster must be replaced
-/+ null_resource.cluster = {
~ id = "7713440656663291188" -> "(known after apply)"
~ id = "2582010537129087805" -> "(known after apply)"
triggers = { # forces replacement
~ secret = "secure" -> "still secure"
}
Expand All @@ -86,17 +120,17 @@ Changes to Resources:
}

- null_resource.cluster_old = {
- id = "342286906083046084"
- id = "6045924575212971352"
- triggers = {
- secret = "very very secure"
}
}

~ time_offset.example = {
~ day = 2 -> 3
~ day = 16 -> 17
~ offset_days = 7 -> 8
~ rfc3339 = "2024-06-02T15:18:04Z" -> "2024-06-03T15:18:04Z"
~ unix = 1717341484 -> 1717427884
~ rfc3339 = "2024-08-16T06:48:48Z" -> "2024-08-17T06:48:48Z"
~ unix = 1723790928 -> 1723877328
# (13 unchanged attribute hidden)
}

Expand Down
Loading

0 comments on commit 6a1617b

Please sign in to comment.