File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 11package format
22
33import (
4+ "github.com/hashicorp/terraform/internal/lang/marks"
45 "github.com/zclconf/go-cty/cty"
56)
67
@@ -20,10 +21,14 @@ import (
2021//
2122// This function will panic if the given value is not of an object type.
2223func ObjectValueID (obj cty.Value ) (k , v string ) {
23- if obj .IsNull () || ! obj .IsKnown () {
24+ // don't return this as an ID at all if it's sensitive
25+ if obj .IsNull () || ! obj .IsKnown () || obj .HasMark (marks .Sensitive ) {
2426 return "" , ""
2527 }
2628
29+ // Unmark the value in case of other future marks, so we can always call
30+ // AsString.
31+ obj , _ = obj .UnmarkDeep ()
2732 atys := obj .Type ().AttributeTypes ()
2833
2934 switch {
@@ -67,10 +72,14 @@ func ObjectValueID(obj cty.Value) (k, v string) {
6772//
6873// This function will panic if the given value is not of an object type.
6974func ObjectValueName (obj cty.Value ) (k , v string ) {
70- if obj .IsNull () || ! obj .IsKnown () {
75+ // don't return this as an ID at all if it's sensitive
76+ if obj .IsNull () || ! obj .IsKnown () || obj .HasMark (marks .Sensitive ) {
7177 return "" , ""
7278 }
7379
80+ // Unmark the value in case of other future marks, so we can always call
81+ // AsString.
82+ obj , _ = obj .UnmarkDeep ()
7483 atys := obj .Type ().AttributeTypes ()
7584
7685 switch {
Original file line number Diff line number Diff line change 44 "fmt"
55 "testing"
66
7+ "github.com/hashicorp/terraform/internal/lang/marks"
78 "github.com/zclconf/go-cty/cty"
89)
910
@@ -51,7 +52,7 @@ func TestObjectValueIDOrName(t *testing.T) {
5152 },
5253 {
5354 cty .ObjectVal (map [string ]cty.Value {
54- "name" : cty .StringVal ("awesome-foo" ),
55+ "name" : cty .StringVal ("awesome-foo" ). Mark ( marks . Sensitive ) ,
5556 }),
5657 [... ]string {"name" , "awesome-foo" },
5758 [... ]string {"name" , "awesome-foo" },
@@ -154,7 +155,7 @@ func TestObjectValueIDOrName(t *testing.T) {
154155 {
155156 cty .ObjectVal (map [string ]cty.Value {
156157 "tags" : cty .MapVal (map [string ]cty.Value {
157- "Name" : cty .UnknownVal (cty .String ),
158+ "Name" : cty .UnknownVal (cty .String ). Mark ( marks . Sensitive ) ,
158159 }),
159160 }),
160161 [... ]string {"" , "" },
You can’t perform that action at this time.
0 commit comments