Skip to content

Commit dd1a819

Browse files
authored
Reflect 0.15 sensitivity fields in plan & config (#32)
1 parent 6e41686 commit dd1a819

File tree

4 files changed

+168
-0
lines changed

4 files changed

+168
-0
lines changed

config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ type ConfigVariable struct {
147147

148148
// The defined text description of the variable.
149149
Description string `json:"description,omitempty"`
150+
151+
// Whether the variable is marked as sensitive
152+
Sensitive bool `json:"sensitive,omitempty"`
150153
}
151154

152155
// ConfigProvisioner describes a provisioner declared in a resource

plan.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ type Change struct {
150150
// If the value cannot be found in this map, then its value should
151151
// be available within After, so long as the operation supports it.
152152
AfterUnknown interface{} `json:"after_unknown,omitempty"`
153+
154+
// BeforeSensitive and AfterSensitive are object values with similar
155+
// structure to Before and After, but with all sensitive leaf values
156+
// replaced with true, and all non-sensitive leaf values omitted. These
157+
// objects should be combined with Before and After to prevent accidental
158+
// display of sensitive values in user interfaces.
159+
BeforeSensitive interface{} `json:"before_sensitive,omitempty"`
160+
AfterSensitive interface{} `json:"after_sensitive,omitempty"`
153161
}
154162

155163
// PlanVariable is a top-level variable in the Terraform plan.

plan_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"encoding/json"
55
"os"
66
"testing"
7+
8+
"github.com/google/go-cmp/cmp"
79
)
810

911
func TestPlanValidate(t *testing.T) {
@@ -22,3 +24,41 @@ func TestPlanValidate(t *testing.T) {
2224
t.Fatal(err)
2325
}
2426
}
27+
28+
func TestPlan_015(t *testing.T) {
29+
f, err := os.Open("testdata/basic/plan-0.15.json")
30+
if err != nil {
31+
t.Fatal(err)
32+
}
33+
defer f.Close()
34+
35+
var plan *Plan
36+
if err := json.NewDecoder(f).Decode(&plan); err != nil {
37+
t.Fatal(err)
38+
}
39+
40+
if err := plan.Validate(); err != nil {
41+
t.Fatal(err)
42+
}
43+
44+
expectedChange := &Change{
45+
Actions: Actions{"create"},
46+
After: map[string]interface{}{"ami": "boop"},
47+
AfterUnknown: map[string]interface{}{"id": true},
48+
BeforeSensitive: false,
49+
AfterSensitive: map[string]interface{}{"ami": true},
50+
}
51+
if diff := cmp.Diff(expectedChange, plan.ResourceChanges[0].Change); diff != "" {
52+
t.Fatalf("unexpected change: %s", diff)
53+
}
54+
55+
expectedVariable := map[string]*ConfigVariable{
56+
"test_var": {
57+
Default: "boop",
58+
Sensitive: true,
59+
},
60+
}
61+
if diff := cmp.Diff(expectedVariable, plan.Config.RootModule.Variables); diff != "" {
62+
t.Fatalf("unexpected variables: %s", diff)
63+
}
64+
}

testdata/basic/plan-0.15.json

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
"format_version": "0.1",
3+
"variables": {
4+
"test_var": {
5+
"value": "boop"
6+
}
7+
},
8+
"planned_values": {
9+
"outputs": {
10+
"test": {
11+
"sensitive": true,
12+
"value": "boop"
13+
}
14+
},
15+
"root_module": {
16+
"resources": [
17+
{
18+
"address": "test_instance.test",
19+
"mode": "managed",
20+
"type": "test_instance",
21+
"name": "test",
22+
"provider_name": "registry.terraform.io/hashicorp/test",
23+
"schema_version": 0,
24+
"values": {
25+
"ami": "boop"
26+
}
27+
}
28+
]
29+
}
30+
},
31+
"resource_changes": [
32+
{
33+
"address": "test_instance.test",
34+
"mode": "managed",
35+
"type": "test_instance",
36+
"provider_name": "registry.terraform.io/hashicorp/test",
37+
"name": "test",
38+
"change": {
39+
"actions": [
40+
"create"
41+
],
42+
"before": null,
43+
"after": {
44+
"ami": "boop"
45+
},
46+
"after_unknown": {
47+
"id": true
48+
},
49+
"after_sensitive": {
50+
"ami": true
51+
},
52+
"before_sensitive": false
53+
}
54+
}
55+
],
56+
"output_changes": {
57+
"test": {
58+
"actions": [
59+
"create"
60+
],
61+
"before": null,
62+
"after": "boop",
63+
"after_unknown": false,
64+
"before_sensitive": true,
65+
"after_sensitive": true
66+
}
67+
},
68+
"prior_state": {
69+
"format_version": "0.1",
70+
"values": {
71+
"outputs": {
72+
"test": {
73+
"sensitive": true,
74+
"value": "boop"
75+
}
76+
},
77+
"root_module": {}
78+
}
79+
},
80+
"configuration": {
81+
"root_module": {
82+
"outputs": {
83+
"test": {
84+
"expression": {
85+
"references": [
86+
"test_instance.test"
87+
]
88+
},
89+
"sensitive": true
90+
}
91+
},
92+
"resources": [
93+
{
94+
"address": "test_instance.test",
95+
"mode": "managed",
96+
"type": "test_instance",
97+
"name": "test",
98+
"provider_config_key": "test",
99+
"schema_version": 0,
100+
"expressions": {
101+
"ami": {
102+
"references": [
103+
"var.test_var"
104+
]
105+
}
106+
}
107+
}
108+
],
109+
"variables": {
110+
"test_var": {
111+
"default": "boop",
112+
"sensitive": true
113+
}
114+
}
115+
}
116+
}
117+
}

0 commit comments

Comments
 (0)