@@ -37,7 +37,7 @@ func flattenAppV2(d *schema.ResourceData, in *AppV2) error {
3737 if err != nil {
3838 return fmt .Errorf ("failed to marshal chart values yaml: %v" , err )
3939 }
40- d .Set ("values " , valuesStr )
40+ d .Set ("deployment_values " , valuesStr )
4141 if global , ok := in .Spec .Values ["global" ].(map [string ]interface {}); ok && len (global ) > 0 {
4242 if cattle , ok := global ["cattle" ].(map [string ]interface {}); ok && len (cattle ) > 0 {
4343 if clusterID , ok := cattle ["clusterId" ].(string ); ok && len (clusterID ) > 0 {
@@ -65,39 +65,17 @@ func expandChartInstallV2(in *schema.ResourceData, chartInfo *types.ChartInfo) (
6565 if in == nil || chartInfo == nil || chartInfo .Chart == nil {
6666 return "" , nil , nil
6767 }
68- out := []types.ChartInstall {}
68+ out := make ( []types.ChartInstall , 0 )
6969 name := in .Get ("name" ).(string )
7070 namespace := in .Get ("namespace" ).(string )
71- globalInfo := map [string ]interface {}{
72- "systemDefaultRegistry" : in .Get ("system_default_registry" ).(string ),
73- "cattle" : map [string ]interface {}{
74- "clusterId" : in .Get ("cluster_id" ).(string ),
75- "clusterName" : in .Get ("cluster_name" ).(string ),
76- "systemDefaultRegistry" : in .Get ("system_default_registry" ).(string ),
77- },
78- }
71+ globalInfo := generateGlobalInfoMap (in )
7972 valuesData := v3.MapStringInterface {}
8073 if v , ok := in .Get ("values" ).(string ); ok {
81- values , err := ghodssyamlToMapInterface (v )
74+ values , err := unmarshalValuesContent (v )
8275 if err != nil {
83- return "" , nil , fmt .Errorf ("failed to unmarshal chart install values yaml: %#v" , err )
84- }
85- if values == nil {
86- values = map [string ]interface {}{}
87- }
88- if global , ok := values ["global" ].(map [string ]interface {}); ok && len (global ) > 0 {
89- values ["global" ].(map [string ]interface {})["systemDefaultRegistry" ] = globalInfo ["systemDefaultRegistry" ]
90- if _ , ok := global ["cattle" ].(map [string ]interface {}); ok && len (global ) > 0 {
91- values ["global" ].(map [string ]interface {})["cattle" ].(map [string ]interface {})["clusterId" ] = globalInfo ["cattle" ].(map [string ]interface {})["clusterId" ]
92- values ["global" ].(map [string ]interface {})["cattle" ].(map [string ]interface {})["clusterName" ] = globalInfo ["cattle" ].(map [string ]interface {})["clusterName" ]
93- values ["global" ].(map [string ]interface {})["cattle" ].(map [string ]interface {})["systemDefaultRegistry" ] = globalInfo ["cattle" ].(map [string ]interface {})["systemDefaultRegistry" ]
94-
95- } else {
96- values ["global" ].(map [string ]interface {})["cattle" ] = globalInfo ["cattle" ]
97- }
98- } else {
99- values ["global" ] = globalInfo
76+ return "" , nil , err
10077 }
78+ mergeGlobalMaps (values , globalInfo )
10179 valuesData = v3 .MapStringInterface (values )
10280 }
10381 if chartAnnotations , ok := chartInfo .Chart ["annotations" ].(map [string ]interface {}); ok && len (chartAnnotations ) > 0 {
@@ -147,6 +125,39 @@ func expandChartInstallV2(in *schema.ResourceData, chartInfo *types.ChartInfo) (
147125 return namespace , out , nil
148126}
149127
128+ func mergeGlobalMaps (values map [string ]interface {}, globalInfo map [string ]interface {}) {
129+ globalInfoCattle := globalInfo ["cattle" ].(map [string ]interface {})
130+
131+ if global , ok := values ["global" ].(map [string ]interface {}); ok && len (global ) > 0 {
132+ global ["systemDefaultRegistry" ] = globalInfo ["systemDefaultRegistry" ]
133+ if globalCattle , ok := global ["cattle" ].(map [string ]interface {}); ok && len (global ) > 0 {
134+ globalCattle ["clusterId" ] = globalInfoCattle ["clusterId" ]
135+ globalCattle ["clusterName" ] = globalInfoCattle ["clusterName" ]
136+ globalCattle ["systemDefaultRegistry" ] = globalInfoCattle ["systemDefaultRegistry" ]
137+
138+ } else {
139+ global ["cattle" ] = globalInfo ["cattle" ]
140+ }
141+ } else {
142+ values ["global" ] = globalInfo
143+ }
144+ }
145+
146+ func generateGlobalInfoMap (in * schema.ResourceData ) map [string ]interface {} {
147+ globalInfoCattle := map [string ]interface {}{
148+ "clusterId" : in .Get ("cluster_id" ).(string ),
149+ "clusterName" : in .Get ("cluster_name" ).(string ),
150+ "systemDefaultRegistry" : in .Get ("system_default_registry" ).(string ),
151+ }
152+
153+ globalInfo := map [string ]interface {}{
154+ "systemDefaultRegistry" : in .Get ("system_default_registry" ).(string ),
155+ "cattle" : globalInfoCattle ,
156+ }
157+
158+ return globalInfo
159+ }
160+
150161func expandChartInstallActionV2 (in * schema.ResourceData , chartInfo * types.ChartInfo ) (* types.ChartInstallAction , error ) {
151162 if in == nil || chartInfo == nil {
152163 return nil , nil
@@ -182,40 +193,19 @@ func expandChartUpgradeV2(in *schema.ResourceData, chartInfo *types.ChartInfo) (
182193 return "" , nil , nil
183194 }
184195
185- out := []types.ChartUpgrade {}
196+ out := make ( []types.ChartUpgrade , 0 )
186197 chartName := in .Get ("chart_name" ).(string )
187198 chartVersion := in .Get ("chart_version" ).(string )
188199 name := in .Get ("name" ).(string )
189200 namespace := in .Get ("namespace" ).(string )
190- globalInfo := map [string ]interface {}{
191- "systemDefaultRegistry" : in .Get ("system_default_registry" ).(string ),
192- "cattle" : map [string ]interface {}{
193- "clusterId" : in .Get ("cluster_id" ).(string ),
194- "clusterName" : in .Get ("cluster_name" ).(string ),
195- "systemDefaultRegistry" : in .Get ("system_default_registry" ).(string ),
196- },
197- }
201+ globalInfo := generateGlobalInfoMap (in )
198202 valuesData := v3.MapStringInterface {}
199203 if v , ok := in .Get ("values" ).(string ); ok {
200- values , err := ghodssyamlToMapInterface (v )
204+ values , err := unmarshalValuesContent (v )
201205 if err != nil {
202- return "" , nil , fmt .Errorf ("failed to unmarshal chart install values yaml: %#v" , err )
203- }
204- if values == nil {
205- values = map [string ]interface {}{}
206- }
207- if global , ok := values ["global" ].(map [string ]interface {}); ok && len (global ) > 0 {
208- values ["global" ].(map [string ]interface {})["systemDefaultRegistry" ] = globalInfo ["systemDefaultRegistry" ]
209- if _ , ok := global ["cattle" ].(map [string ]interface {}); ok && len (global ) > 0 {
210- values ["global" ].(map [string ]interface {})["cattle" ].(map [string ]interface {})["clusterId" ] = globalInfo ["cattle" ].(map [string ]interface {})["clusterId" ]
211- values ["global" ].(map [string ]interface {})["cattle" ].(map [string ]interface {})["clusterName" ] = globalInfo ["cattle" ].(map [string ]interface {})["clusterName" ]
212- values ["global" ].(map [string ]interface {})["cattle" ].(map [string ]interface {})["systemDefaultRegistry" ] = globalInfo ["cattle" ].(map [string ]interface {})["systemDefaultRegistry" ]
213- } else {
214- values ["global" ].(map [string ]interface {})["cattle" ] = globalInfo ["cattle" ]
215- }
216- } else {
217- values ["global" ] = globalInfo
206+ return "" , nil , err
218207 }
208+ mergeGlobalMaps (values , globalInfo )
219209 valuesData = v3 .MapStringInterface (values )
220210 }
221211 if chartAnnotations , ok := chartInfo .Chart ["annotations" ].(map [string ]interface {}); ok && len (chartAnnotations ) > 0 {
@@ -267,6 +257,18 @@ func expandChartUpgradeV2(in *schema.ResourceData, chartInfo *types.ChartInfo) (
267257 return namespace , out , nil
268258}
269259
260+ func unmarshalValuesContent (v string ) (map [string ]interface {}, error ) {
261+ values , err := ghodssyamlToMapInterface (v )
262+ if err != nil {
263+ return nil , fmt .Errorf ("[ERROR] failed to unmarshal chart install values YAML: %#v" , err )
264+ }
265+ if values == nil {
266+ values = map [string ]interface {}{}
267+ }
268+
269+ return values , nil
270+ }
271+
270272func expandChartUpgradeActionV2 (in * schema.ResourceData , chartInfo * types.ChartInfo ) (* types.ChartUpgradeAction , error ) {
271273 if in == nil || chartInfo == nil {
272274 return nil , nil
0 commit comments