| 283 | } |
| 284 | |
| 285 | func evalMatchSpec(b *terraform.Block, spec *MatchSpec, customCtx *customContext) bool { |
| 286 | if b.IsNil() { |
| 287 | return false |
| 288 | } |
| 289 | var evalResult bool |
| 290 | |
| 291 | for _, preCondition := range spec.PreConditions { |
| 292 | clone := preCondition |
| 293 | if !evalMatchSpec(b, &clone, customCtx) { |
| 294 | // precondition not met |
| 295 | return true |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | var matchFunctionsDirect = map[CheckAction]func(*terraform.Block, *MatchSpec, *customContext) bool{ |
| 300 | InModule: func(b *terraform.Block, spec *MatchSpec, customCtx *customContext) bool { |
| 301 | return b.InModule() |
| 302 | }, |
| 303 | HasTag: checkTags, |
| 304 | OfType: func(b *terraform.Block, spec *MatchSpec, customCtx *customContext) bool { |
| 305 | return ofType(b, spec) |
| 306 | }, |
| 307 | Not: notifyPredicate, |
| 308 | And: processAndPredicate, |
| 309 | Or: processOrPredicate, |
| 310 | } |
| 311 | |
| 312 | if matchFunction, ok := matchFunctionsDirect[spec.Action]; ok { |
| 313 | return matchFunction(b, spec, customCtx) |
| 314 | } else { |
| 315 | evalResult = matchFunctions[spec.Action](b, spec, customCtx) |
| 316 | } |
| 317 | |
| 318 | if len(spec.AssignVariable) > 0 { |
| 319 | customCtx.variables[spec.AssignVariable] = b.GetAttribute(spec.Name).AsStringValueOrDefault("", b).Value() |
| 320 | } |
| 321 | |
| 322 | if spec.SubMatch != nil && evalResult { |
| 323 | evalResult = processSubMatches(b, spec, customCtx) |
| 324 | } |
| 325 | |
| 326 | if spec.SubMatchOne != nil && evalResult { |
| 327 | evalResult = processSubMatchOnes(b, spec, customCtx) |
| 328 | } |
| 329 | |
| 330 | return evalResult |
| 331 | } |
| 332 | |
| 333 | func evalMatchSpecAttr(a *terraform.Attribute, spec *MatchSpec, customCtx *customContext) bool { |
| 334 | for _, preCondition := range spec.PreConditions { |