Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.
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
11 changes: 7 additions & 4 deletions workspacehelper/tfc_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (t *TerraformCloudClient) GetStateVersionDownloadURL(workspaceID string) (s

func convertValueToString(val cty.Value) string {
if val.IsNull() {
return ""
return "null"
}
ty := val.Type()
switch {
Expand Down Expand Up @@ -76,17 +76,19 @@ func convertValueToString(val cty.Value) string {
var b bytes.Buffer

i := 0
valLen := val.LengthInt()
for it := val.ElementIterator(); it.Next(); {
key, value := it.Element()
k := convertValueToString(key)
v := convertValueToString(value)
if k == "" || v == "" {
valLen--
continue
}
b.WriteString(k)
b.WriteString(":")
b.WriteString(v)
if i < (val.LengthInt() - 1) {
if i < (valLen - 1) {
b.WriteString(",")
}
i++
Expand All @@ -109,19 +111,20 @@ func convertValueToString(val cty.Value) string {

var b bytes.Buffer
i := 0
atysLen := len(atys)
for _, attr := range attrNames {
val := val.GetAttr(attr)
v := convertValueToString(val)
if v == "" {
atysLen--
continue
}

b.WriteString(`"`)
b.WriteString(attr)
b.WriteString(`"`)
b.WriteString(":")
b.WriteString(v)
if i < (len(atys) - 1) {
if i < (atysLen - 1) {
b.WriteString(",")
}
i++
Expand Down
4 changes: 2 additions & 2 deletions workspacehelper/tfc_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestShouldReturnStringFromObject(t *testing.T) {
}

func TestShouldReturnEmptyStringFromNullObject(t *testing.T) {
expected := ""
expected := "null"
value := cty.NullVal(cty.Map(cty.String))
formatted := convertValueToString(value)
assert.Equal(t, expected, formatted)
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestOutputsFromState(t *testing.T) {
}
}
}`,
want: []*v1alpha1.OutputStatus{},
want: []*v1alpha1.OutputStatus{{Key: "map1", Value: "[{\"null_map\":null}]"}},
},
{
name: "embedded JSON empty array returns no status",
Expand Down