@@ -89,15 +89,17 @@ func (is *infrastructureStack) From(stack *gqlclient.InfrastructureStackFragment
89
89
is .ClusterId = types .StringValue (stack .Cluster .ID )
90
90
is .Repository .From (stack .Repository , stack .Git )
91
91
is .Configuration .From (stack .Configuration )
92
- is .Files = infrastructureStackFilesFrom (stack .Files , d )
93
- is .Environment = infrastructureStackEnvironmentsFrom (stack .Environment , ctx , d )
92
+ is .Files = infrastructureStackFilesFrom (stack .Files , is . Files , d )
93
+ is .Environment = infrastructureStackEnvironmentsFrom (stack .Environment , is . Environment , ctx , d )
94
94
is .Bindings .From (stack .ReadBindings , stack .WriteBindings , ctx , d )
95
95
is .JobSpec .From (stack .JobSpec , ctx , d )
96
96
}
97
97
98
- func infrastructureStackFilesFrom (files []* gqlclient.StackFileFragment , d diag.Diagnostics ) basetypes.MapValue {
99
- if files == nil {
100
- return types .MapNull (types .StringType )
98
+ func infrastructureStackFilesFrom (files []* gqlclient.StackFileFragment , config types.Map , d diag.Diagnostics ) types.Map {
99
+ if len (files ) == 0 {
100
+ // Rewriting config to state to avoid inconsistent result errors.
101
+ // This could happen, for example, when sending "nil" to API and "[]" is returned as a result.
102
+ return config
101
103
}
102
104
103
105
resultMap := make (map [string ]attr.Value , len (files ))
@@ -111,6 +113,29 @@ func infrastructureStackFilesFrom(files []*gqlclient.StackFileFragment, d diag.D
111
113
return result
112
114
}
113
115
116
+ func infrastructureStackEnvironmentsFrom (envs []* gqlclient.StackEnvironmentFragment , config types.Set , ctx context.Context , d diag.Diagnostics ) types.Set {
117
+ if len (envs ) == 0 {
118
+ // Rewriting config to state to avoid inconsistent result errors.
119
+ // This could happen, for example, when sending "nil" to API and "[]" is returned as a result.
120
+ return config
121
+ }
122
+
123
+ values := make ([]attr.Value , len (envs ))
124
+ for i , file := range envs {
125
+ objValue , diags := types .ObjectValueFrom (ctx , InfrastructureStackEnvironmentAttrTypes , InfrastructureStackEnvironment {
126
+ Name : types .StringValue (file .Name ),
127
+ Value : types .StringValue (file .Value ),
128
+ Secret : types .BoolPointerValue (file .Secret ),
129
+ })
130
+ values [i ] = objValue
131
+ d .Append (diags ... )
132
+ }
133
+
134
+ setValue , diags := types .SetValue (basetypes.ObjectType {AttrTypes : InfrastructureStackEnvironmentAttrTypes }, values )
135
+ d .Append (diags ... )
136
+ return setValue
137
+ }
138
+
114
139
type InfrastructureStackRepository struct {
115
140
Id types.String `tfsdk:"id"`
116
141
Ref types.String `tfsdk:"ref"`
@@ -180,27 +205,6 @@ var InfrastructureStackEnvironmentAttrTypes = map[string]attr.Type{
180
205
"secret" : types .BoolType ,
181
206
}
182
207
183
- func infrastructureStackEnvironmentsFrom (envs []* gqlclient.StackEnvironmentFragment , ctx context.Context , d diag.Diagnostics ) types.Set {
184
- if envs == nil {
185
- return types .SetNull (basetypes.ObjectType {AttrTypes : InfrastructureStackEnvironmentAttrTypes })
186
- }
187
-
188
- values := make ([]attr.Value , len (envs ))
189
- for i , file := range envs {
190
- objValue , diags := types .ObjectValueFrom (ctx , InfrastructureStackEnvironmentAttrTypes , InfrastructureStackEnvironment {
191
- Name : types .StringValue (file .Name ),
192
- Value : types .StringValue (file .Value ),
193
- Secret : types .BoolPointerValue (file .Secret ),
194
- })
195
- values [i ] = objValue
196
- d .Append (diags ... )
197
- }
198
-
199
- setValue , diags := types .SetValue (basetypes.ObjectType {AttrTypes : InfrastructureStackEnvironmentAttrTypes }, values )
200
- d .Append (diags ... )
201
- return setValue
202
- }
203
-
204
208
type InfrastructureStackBindings struct {
205
209
Read []* InfrastructureStackPolicyBinding `tfsdk:"read"`
206
210
Write []* InfrastructureStackPolicyBinding `tfsdk:"write"`
@@ -279,15 +283,17 @@ func (isjs *InfrastructureStackJobSpec) From(spec *gqlclient.JobGateSpecFragment
279
283
280
284
isjs .Namespace = types .StringValue (spec .Namespace )
281
285
isjs .Raw = types .StringPointerValue (spec .Raw )
282
- isjs .Containers = infrastructureStackJobSpecContainersFrom (spec .Containers , ctx , d )
283
- isjs .Labels = common .MapFrom (spec .Labels , ctx , d )
284
- isjs .Annotations = common .MapFrom (spec .Annotations , ctx , d )
286
+ isjs .Containers = infrastructureStackJobSpecContainersFrom (spec .Containers , isjs . Containers , ctx , d )
287
+ isjs .Labels = common .MapFromWithConfig (spec . Labels , isjs .Labels , ctx , d )
288
+ isjs .Annotations = common .MapFromWithConfig (spec . Annotations , isjs .Annotations , ctx , d )
285
289
isjs .ServiceAccount = types .StringPointerValue (spec .ServiceAccount )
286
290
}
287
291
288
- func infrastructureStackJobSpecContainersFrom (containers []* gqlclient.ContainerSpecFragment , ctx context.Context , d diag.Diagnostics ) types.Set {
289
- if containers == nil {
290
- return types .SetNull (basetypes.ObjectType {AttrTypes : InfrastructureStackContainerSpecAttrTypes })
292
+ func infrastructureStackJobSpecContainersFrom (containers []* gqlclient.ContainerSpecFragment , config types.Set , ctx context.Context , d diag.Diagnostics ) types.Set {
293
+ if len (containers ) == 0 {
294
+ // Rewriting config to state to avoid inconsistent result errors.
295
+ // This could happen, for example, when sending "nil" to API and "[]" is returned as a result.
296
+ return config
291
297
}
292
298
293
299
values := make ([]attr.Value , len (containers ))
0 commit comments