Skip to content

Commit 656f6a6

Browse files
committed
Fix output values with null
Signed-off-by: Igor Rodionov <goruha@gmail.com>
1 parent 77d395a commit 656f6a6

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

format/generator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func TestGeneratorFuncModule(t *testing.T) {
191191
assert.Equal(expected, generator.module.Header)
192192
assert.Equal("", generator.module.Footer)
193193
assert.Equal(7, len(generator.module.Inputs))
194-
assert.Equal(3, len(generator.module.Outputs))
194+
assert.Equal(4, len(generator.module.Outputs))
195195
})
196196
}
197197

terraform/load.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,15 @@ func loadOutputs(tfmodule *tfconfig.Module, config *print.Config) ([]*Output, er
294294
}
295295

296296
if config.OutputValues.Enabled {
297-
output.Sensitive = values[output.Name].Sensitive
298-
if values[output.Name].Sensitive {
299-
output.Value = types.ValueOf(`<sensitive>`)
297+
if value, ok := values[output.Name]; ok {
298+
output.Sensitive = value.Sensitive
299+
output.Value = types.ValueOf(value.Value)
300300
} else {
301-
output.Value = types.ValueOf(values[output.Name].Value)
301+
output.Value = types.ValueOf("null")
302+
}
303+
304+
if output.Sensitive {
305+
output.Value = types.ValueOf(`<sensitive>`)
302306
}
303307
}
304308
outputs = append(outputs, output)

terraform/load_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ func TestLoadOutputs(t *testing.T) {
589589
name: "load module outputs from path",
590590
path: "full-example",
591591
expected: expected{
592-
outputs: 3,
592+
outputs: 4,
593593
},
594594
},
595595
{
@@ -665,7 +665,7 @@ func TestLoadOutputsValues(t *testing.T) {
665665
path: "full-example",
666666
outputPath: "output-values.json",
667667
expected: expected{
668-
outputs: 3,
668+
outputs: 4,
669669
},
670670
wantErr: false,
671671
},
@@ -896,7 +896,7 @@ func TestSortItems(t *testing.T) {
896896
inputs: []string{"D", "B", "E", "A", "C", "F", "G"},
897897
required: []string{"A", "F"},
898898
optional: []string{"D", "B", "E", "C", "G"},
899-
outputs: []string{"C", "A", "B"},
899+
outputs: []string{"C", "A", "B", "D"},
900900
providers: []string{"tls", "aws", "null"},
901901
},
902902
},
@@ -909,7 +909,7 @@ func TestSortItems(t *testing.T) {
909909
inputs: []string{"D", "B", "E", "A", "C", "F", "G"},
910910
required: []string{"A", "F"},
911911
optional: []string{"D", "B", "E", "C", "G"},
912-
outputs: []string{"C", "A", "B"},
912+
outputs: []string{"C", "A", "B", "D"},
913913
providers: []string{"tls", "aws", "null"},
914914
},
915915
},
@@ -922,7 +922,7 @@ func TestSortItems(t *testing.T) {
922922
inputs: []string{"D", "B", "E", "A", "C", "F", "G"},
923923
required: []string{"A", "F"},
924924
optional: []string{"D", "B", "E", "C", "G"},
925-
outputs: []string{"C", "A", "B"},
925+
outputs: []string{"C", "A", "B", "D"},
926926
providers: []string{"tls", "aws", "null"},
927927
},
928928
},
@@ -935,7 +935,7 @@ func TestSortItems(t *testing.T) {
935935
inputs: []string{"A", "B", "C", "D", "E", "F", "G"},
936936
required: []string{"A", "F"},
937937
optional: []string{"B", "C", "D", "E", "G"},
938-
outputs: []string{"A", "B", "C"},
938+
outputs: []string{"A", "B", "C", "D"},
939939
providers: []string{"aws", "null", "tls"},
940940
},
941941
},
@@ -948,7 +948,7 @@ func TestSortItems(t *testing.T) {
948948
inputs: []string{"A", "F", "B", "C", "D", "E", "G"},
949949
required: []string{"A", "F"},
950950
optional: []string{"B", "C", "D", "E", "G"},
951-
outputs: []string{"A", "B", "C"},
951+
outputs: []string{"A", "B", "C", "D"},
952952
providers: []string{"aws", "null", "tls"},
953953
},
954954
},
@@ -961,7 +961,7 @@ func TestSortItems(t *testing.T) {
961961
inputs: []string{"A", "F", "G", "B", "C", "D", "E"},
962962
required: []string{"A", "F"},
963963
optional: []string{"G", "B", "C", "D", "E"},
964-
outputs: []string{"A", "B", "C"},
964+
outputs: []string{"A", "B", "C", "D"},
965965
providers: []string{"aws", "null", "tls"},
966966
},
967967
},

terraform/testdata/full-example/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ output "A" {
1212
output "B" {
1313
value = "b"
1414
}
15+
16+
// D null result
17+
output "D" {
18+
value = null
19+
}

0 commit comments

Comments
 (0)