8
8
"fmt"
9
9
"sort"
10
10
11
+ "github.com/hashicorp/terraform/internal/command/jsonstate"
11
12
"github.com/hashicorp/terraform/internal/lang/marks"
12
13
"github.com/hashicorp/terraform/internal/plans"
13
14
"github.com/hashicorp/terraform/internal/providers"
@@ -25,7 +26,8 @@ type ActionInvocation struct {
25
26
Name string `json:"name,omitempty"`
26
27
27
28
// ConfigValues is the JSON representation of the values in the config block of the action
28
- ConfigValues map [string ]json.RawMessage `json:"config_values,omitempty"`
29
+ ConfigValues map [string ]json.RawMessage `json:"config_values,omitempty"`
30
+ ConfigSensitive json.RawMessage `json:"config_sensitive,omitempty"`
29
31
30
32
// ProviderName allows the property "type" to be interpreted unambiguously
31
33
// in the unusual situation where a provider offers a type whose
@@ -85,7 +87,7 @@ func marshalConfigValues(value cty.Value) map[string]json.RawMessage {
85
87
}
86
88
87
89
ret := make (map [string ]json.RawMessage )
88
- it := value .ElementIterator ()
90
+ it := v .ElementIterator ()
89
91
for it .Next () {
90
92
k , v := it .Element ()
91
93
vJSON , _ := ctyjson .Marshal (v , v .Type ())
@@ -99,7 +101,7 @@ func MarshalActionInvocations(actions []*plans.ActionInvocationInstanceSrc, sche
99
101
for _ , action := range actions {
100
102
ai , err := MarshalActionInvocation (action , schemas )
101
103
if err != nil {
102
- return nil , err
104
+ return ret , fmt . Errorf ( "failed to decode action %s: %w" , action . Addr , err )
103
105
}
104
106
ret = append (ret , ai )
105
107
}
@@ -113,7 +115,6 @@ func MarshalActionInvocation(action *plans.ActionInvocationInstanceSrc, schemas
113
115
Name : action .Addr .Action .Action .Name ,
114
116
ProviderName : action .ProviderAddr .Provider .String (),
115
117
}
116
-
117
118
schema := schemas .ActionTypeConfig (
118
119
action .ProviderAddr .Provider ,
119
120
action .Addr .Action .Action .Type ,
@@ -140,12 +141,8 @@ func MarshalActionInvocation(action *plans.ActionInvocationInstanceSrc, schemas
140
141
}
141
142
142
143
if actionDec .ConfigValue != cty .NilVal {
143
- // TODO: Support sensitive and ephemeral values in action invocations.
144
144
_ , pvms := actionDec .ConfigValue .UnmarkDeepWithPaths ()
145
145
sensitivePaths , otherMarks := marks .PathsWithMark (pvms , marks .Sensitive )
146
- if len (sensitivePaths ) > 0 {
147
- return ai , fmt .Errorf ("action %s has sensitive config values, which are not supported in action invocations" , action .Addr )
148
- }
149
146
ephemeralPaths , otherMarks := marks .PathsWithMark (otherMarks , marks .Ephemeral )
150
147
if len (ephemeralPaths ) > 0 {
151
148
return ai , fmt .Errorf ("action %s has ephemeral config values, which are not supported in action invocations" , action .Addr )
@@ -154,12 +151,18 @@ func MarshalActionInvocation(action *plans.ActionInvocationInstanceSrc, schemas
154
151
return ai , fmt .Errorf ("action %s has config values with unsupported marks: %v" , action .Addr , otherMarks )
155
152
}
156
153
157
- if actionDec .ConfigValue .IsWhollyKnown () {
158
- ai .ConfigValues = marshalConfigValues (actionDec .ConfigValue )
159
- } else {
160
- knowns := omitUnknowns (actionDec .ConfigValue )
161
- ai .ConfigValues = marshalConfigValues (knowns )
154
+ configValue := actionDec .ConfigValue
155
+ if ! configValue .IsWhollyKnown () {
156
+ configValue = omitUnknowns (actionDec .ConfigValue )
162
157
}
158
+ cs := jsonstate .SensitiveAsBool (marks .MarkPaths (configValue , marks .Sensitive , sensitivePaths ))
159
+ configSensitive , err := ctyjson .Marshal (cs , cs .Type ())
160
+ if err != nil {
161
+ return ai , err
162
+ }
163
+
164
+ ai .ConfigValues = marshalConfigValues (configValue )
165
+ ai .ConfigSensitive = configSensitive
163
166
}
164
167
return ai , nil
165
168
}
0 commit comments