Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command/jsonstate: remove redundant remarking of resource instance #29049

Merged
merged 2 commits into from
Jun 29, 2021
Merged
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
8 changes: 2 additions & 6 deletions internal/command/jsonstate/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,7 @@ func marshalResources(resources map[string]*states.Resource, module addrs.Module

current.AttributeValues = marshalAttributeValues(riObj.Value)

// Mark the resource instance value with any marks stored in AttrSensitivePaths so we can build the SensitiveValues object
markedVal := riObj.Value.MarkWithPaths(ri.Current.AttrSensitivePaths)
s := SensitiveAsBool(markedVal)
s := SensitiveAsBool(riObj.Value)
v, err := ctyjson.Marshal(s, s.Type())
if err != nil {
return nil, err
Expand Down Expand Up @@ -371,9 +369,7 @@ func marshalResources(resources map[string]*states.Resource, module addrs.Module

deposed.AttributeValues = marshalAttributeValues(riObj.Value)

// Mark the resource instance value with any marks stored in AttrSensitivePaths so we can build the SensitiveValues object
markedVal := riObj.Value.MarkWithPaths(rios.AttrSensitivePaths)
s := SensitiveAsBool(markedVal)
s := SensitiveAsBool(riObj.Value)
v, err := ctyjson.Marshal(s, s.Type())
if err != nil {
return nil, err
Expand Down
96 changes: 96 additions & 0 deletions internal/command/jsonstate/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,52 @@ func TestMarshalResources(t *testing.T) {
},
false,
},
"resource with marks": {
map[string]*states.Resource{
"test_thing.bar": {
Addr: addrs.AbsResource{
Resource: addrs.Resource{
Mode: addrs.ManagedResourceMode,
Type: "test_thing",
Name: "bar",
},
},
Instances: map[addrs.InstanceKey]*states.ResourceInstance{
addrs.NoKey: {
Current: &states.ResourceInstanceObjectSrc{
Status: states.ObjectReady,
AttrsJSON: []byte(`{"foozles":"confuzles"}`),
AttrSensitivePaths: []cty.PathValueMarks{{
Path: cty.Path{cty.GetAttrStep{Name: "foozles"}},
Marks: cty.NewValueMarks(marks.Sensitive)},
},
},
},
},
ProviderConfig: addrs.AbsProviderConfig{
Provider: addrs.NewDefaultProvider("test"),
Module: addrs.RootModule,
},
},
},
testSchemas(),
[]resource{
{
Address: "test_thing.bar",
Mode: "managed",
Type: "test_thing",
Name: "bar",
Index: addrs.InstanceKey(nil),
ProviderName: "registry.terraform.io/hashicorp/test",
AttributeValues: attributeValues{
"foozles": json.RawMessage(`"confuzles"`),
"woozles": json.RawMessage(`null`),
},
SensitiveValues: json.RawMessage(`{"foozles":true}`),
},
},
false,
},
"single resource wrong schema": {
map[string]*states.Resource{
"test_thing.baz": {
Expand Down Expand Up @@ -418,6 +464,51 @@ func TestMarshalResources(t *testing.T) {
},
false,
},
"resource with marked map attr": {
map[string]*states.Resource{
"test_map_attr.bar": {
Addr: addrs.AbsResource{
Resource: addrs.Resource{
Mode: addrs.ManagedResourceMode,
Type: "test_map_attr",
Name: "bar",
},
},
Instances: map[addrs.InstanceKey]*states.ResourceInstance{
addrs.NoKey: {
Current: &states.ResourceInstanceObjectSrc{
Status: states.ObjectReady,
AttrsJSON: []byte(`{"data":{"woozles":"confuzles"}}`),
AttrSensitivePaths: []cty.PathValueMarks{{
Path: cty.Path{cty.GetAttrStep{Name: "data"}},
Marks: cty.NewValueMarks(marks.Sensitive)},
},
},
},
},
ProviderConfig: addrs.AbsProviderConfig{
Provider: addrs.NewDefaultProvider("test"),
Module: addrs.RootModule,
},
},
},
testSchemas(),
[]resource{
{
Address: "test_map_attr.bar",
Mode: "managed",
Type: "test_map_attr",
Name: "bar",
Index: addrs.InstanceKey(nil),
ProviderName: "registry.terraform.io/hashicorp/test",
AttributeValues: attributeValues{
"data": json.RawMessage(`{"woozles":"confuzles"}`),
},
SensitiveValues: json.RawMessage(`{"data":true}`),
},
},
false,
},
}

for name, test := range tests {
Expand Down Expand Up @@ -654,6 +745,11 @@ func testSchemas() *terraform.Schemas {
"bar": {Type: cty.String, Optional: true},
},
},
"test_map_attr": {
Attributes: map[string]*configschema.Attribute{
"data": {Type: cty.Map(cty.String), Optional: true, Computed: true, Sensitive: true},
},
},
},
},
},
Expand Down