@@ -226,64 +226,33 @@ func (p *Property) resolveValue() (*Property, bool) {
226226}
227227
228228func (p * Property ) GetStringProperty (path string , defaultValue ... string ) iacTypes.StringValue {
229- defVal := ""
230- if len (defaultValue ) > 0 {
231- defVal = defaultValue [0 ]
232- }
233-
234229 if p .IsUnresolved () {
235230 return iacTypes .StringUnresolvable (p .Metadata ())
236231 }
237-
238- prop := p .GetProperty (path )
239- if prop .IsNotString () {
240- return p .StringDefault (defVal )
241- }
242- return prop .AsStringValue ()
232+ return p .GetProperty (path ).AsStringValue (firstOrZero (defaultValue ))
243233}
244234
245235func (p * Property ) StringDefault (defaultValue string ) iacTypes.StringValue {
246236 return iacTypes .StringDefault (defaultValue , p .Metadata ())
247237}
248238
249239func (p * Property ) GetBoolProperty (path string , defaultValue ... bool ) iacTypes.BoolValue {
250- defVal := false
251- if len (defaultValue ) > 0 {
252- defVal = defaultValue [0 ]
253- }
254-
255240 if p .IsUnresolved () {
256241 return iacTypes .BoolUnresolvable (p .Metadata ())
257242 }
258243
259244 prop := p .GetProperty (path )
260-
261245 if prop .isFunction () {
262246 prop , _ = prop .resolveValue ()
263247 }
264-
265- if prop .IsNotBool () {
266- return p .inferBool (prop , defVal )
267- }
268- return prop .AsBoolValue ()
248+ return prop .AsBoolValue (firstOrZero (defaultValue ))
269249}
270250
271251func (p * Property ) GetIntProperty (path string , defaultValue ... int ) iacTypes.IntValue {
272- defVal := 0
273- if len (defaultValue ) > 0 {
274- defVal = defaultValue [0 ]
275- }
276-
277252 if p .IsUnresolved () {
278253 return iacTypes .IntUnresolvable (p .Metadata ())
279254 }
280-
281- prop := p .GetProperty (path )
282-
283- if prop .IsNotInt () {
284- return p .IntDefault (defVal )
285- }
286- return prop .AsIntValue ()
255+ return p .GetProperty (path ).AsIntValue (firstOrZero (defaultValue ))
287256}
288257
289258func (p * Property ) BoolDefault (defaultValue bool ) iacTypes.BoolValue {
@@ -294,6 +263,10 @@ func (p *Property) IntDefault(defaultValue int) iacTypes.IntValue {
294263 return iacTypes .IntDefault (defaultValue , p .Metadata ())
295264}
296265
266+ func (p * Property ) nullProperty () * Property {
267+ return & Property {rng : p .rng , parentRange : p .parentRange , logicalId : p .logicalId }
268+ }
269+
297270func (p * Property ) GetProperty (path string ) * Property {
298271 pathParts := strings .Split (path , "." )
299272
@@ -305,29 +278,23 @@ func (p *Property) GetProperty(path string) *Property {
305278 }
306279
307280 if property .IsNotMap () {
308- return nil
281+ return property . nullProperty ()
309282 }
310283
311- for n , p := range property .AsMap () {
312- if n == first {
313- property = p
314- break
315- }
284+ child , ok := property .AsMap ()[first ]
285+ if ! ok {
286+ return property .nullProperty ()
316287 }
317288
318- if len (pathParts ) == 1 || property == nil {
319- return property
320- }
321-
322- if nestedProperty := property .GetProperty (strings .Join (pathParts [1 :], "." )); nestedProperty != nil {
323- if nestedProperty .isFunction () {
324- resolved , _ := nestedProperty .resolveValue ()
289+ if len (pathParts ) == 1 {
290+ if child .isFunction () {
291+ resolved , _ := child .resolveValue ()
325292 return resolved
326293 }
327- return nestedProperty
294+ return child
328295 }
329296
330- return & Property {}
297+ return child . GetProperty ( strings . Join ( pathParts [ 1 :], "." ))
331298}
332299
333300func (p * Property ) deriveResolved (propType cftypes.CfType , propValue any ) * Property {
@@ -341,39 +308,6 @@ func (p *Property) ParentRange() iacTypes.Range {
341308 return p .parentRange
342309}
343310
344- func (p * Property ) inferBool (prop * Property , defaultValue bool ) iacTypes.BoolValue {
345- if prop .IsString () {
346- if prop .EqualTo ("true" , IgnoreCase ) {
347- return iacTypes .Bool (true , prop .Metadata ())
348- }
349- if prop .EqualTo ("yes" , IgnoreCase ) {
350- return iacTypes .Bool (true , prop .Metadata ())
351- }
352- if prop .EqualTo ("1" , IgnoreCase ) {
353- return iacTypes .Bool (true , prop .Metadata ())
354- }
355- if prop .EqualTo ("false" , IgnoreCase ) {
356- return iacTypes .Bool (false , prop .Metadata ())
357- }
358- if prop .EqualTo ("no" , IgnoreCase ) {
359- return iacTypes .Bool (false , prop .Metadata ())
360- }
361- if prop .EqualTo ("0" , IgnoreCase ) {
362- return iacTypes .Bool (false , prop .Metadata ())
363- }
364- }
365-
366- if prop .IsInt () {
367- if prop .EqualTo (0 ) {
368- return iacTypes .Bool (false , prop .Metadata ())
369- }
370- if prop .EqualTo (1 ) {
371- return iacTypes .Bool (true , prop .Metadata ())
372- }
373- }
374-
375- return p .BoolDefault (defaultValue )
376- }
377311
378312func (p * Property ) String () string {
379313 r := ""
0 commit comments