Skip to content

Commit

Permalink
Fix output values with null
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Rodionov <goruha@gmail.com>
  • Loading branch information
goruha committed Mar 25, 2024
1 parent 77d395a commit 656f6a6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion format/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func TestGeneratorFuncModule(t *testing.T) {
assert.Equal(expected, generator.module.Header)
assert.Equal("", generator.module.Footer)
assert.Equal(7, len(generator.module.Inputs))
assert.Equal(3, len(generator.module.Outputs))
assert.Equal(4, len(generator.module.Outputs))
})
}

Expand Down
12 changes: 8 additions & 4 deletions terraform/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,15 @@ func loadOutputs(tfmodule *tfconfig.Module, config *print.Config) ([]*Output, er
}

if config.OutputValues.Enabled {
output.Sensitive = values[output.Name].Sensitive
if values[output.Name].Sensitive {
output.Value = types.ValueOf(`<sensitive>`)
if value, ok := values[output.Name]; ok {
output.Sensitive = value.Sensitive
output.Value = types.ValueOf(value.Value)
} else {
output.Value = types.ValueOf(values[output.Name].Value)
output.Value = types.ValueOf("null")
}

if output.Sensitive {
output.Value = types.ValueOf(`<sensitive>`)
}
}
outputs = append(outputs, output)
Expand Down
16 changes: 8 additions & 8 deletions terraform/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ func TestLoadOutputs(t *testing.T) {
name: "load module outputs from path",
path: "full-example",
expected: expected{
outputs: 3,
outputs: 4,
},
},
{
Expand Down Expand Up @@ -665,7 +665,7 @@ func TestLoadOutputsValues(t *testing.T) {
path: "full-example",
outputPath: "output-values.json",
expected: expected{
outputs: 3,
outputs: 4,
},
wantErr: false,
},
Expand Down Expand Up @@ -896,7 +896,7 @@ func TestSortItems(t *testing.T) {
inputs: []string{"D", "B", "E", "A", "C", "F", "G"},
required: []string{"A", "F"},
optional: []string{"D", "B", "E", "C", "G"},
outputs: []string{"C", "A", "B"},
outputs: []string{"C", "A", "B", "D"},
providers: []string{"tls", "aws", "null"},
},
},
Expand All @@ -909,7 +909,7 @@ func TestSortItems(t *testing.T) {
inputs: []string{"D", "B", "E", "A", "C", "F", "G"},
required: []string{"A", "F"},
optional: []string{"D", "B", "E", "C", "G"},
outputs: []string{"C", "A", "B"},
outputs: []string{"C", "A", "B", "D"},
providers: []string{"tls", "aws", "null"},
},
},
Expand All @@ -922,7 +922,7 @@ func TestSortItems(t *testing.T) {
inputs: []string{"D", "B", "E", "A", "C", "F", "G"},
required: []string{"A", "F"},
optional: []string{"D", "B", "E", "C", "G"},
outputs: []string{"C", "A", "B"},
outputs: []string{"C", "A", "B", "D"},
providers: []string{"tls", "aws", "null"},
},
},
Expand All @@ -935,7 +935,7 @@ func TestSortItems(t *testing.T) {
inputs: []string{"A", "B", "C", "D", "E", "F", "G"},
required: []string{"A", "F"},
optional: []string{"B", "C", "D", "E", "G"},
outputs: []string{"A", "B", "C"},
outputs: []string{"A", "B", "C", "D"},
providers: []string{"aws", "null", "tls"},
},
},
Expand All @@ -948,7 +948,7 @@ func TestSortItems(t *testing.T) {
inputs: []string{"A", "F", "B", "C", "D", "E", "G"},
required: []string{"A", "F"},
optional: []string{"B", "C", "D", "E", "G"},
outputs: []string{"A", "B", "C"},
outputs: []string{"A", "B", "C", "D"},
providers: []string{"aws", "null", "tls"},
},
},
Expand All @@ -961,7 +961,7 @@ func TestSortItems(t *testing.T) {
inputs: []string{"A", "F", "G", "B", "C", "D", "E"},
required: []string{"A", "F"},
optional: []string{"G", "B", "C", "D", "E"},
outputs: []string{"A", "B", "C"},
outputs: []string{"A", "B", "C", "D"},
providers: []string{"aws", "null", "tls"},
},
},
Expand Down
5 changes: 5 additions & 0 deletions terraform/testdata/full-example/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ output "A" {
output "B" {
value = "b"
}

// D null result
output "D" {
value = null
}

0 comments on commit 656f6a6

Please sign in to comment.