aws-cloudformation / cloudformation-coverage-roadmap

The AWS CloudFormation Public Coverage Roadmap
https://aws.amazon.com/cloudformation/
Creative Commons Attribution Share Alike 4.0 International
1.1k stars 53 forks source link

Allow conditions passed as parameters to be used in modules #1980

Open JGSweets opened 3 months ago

JGSweets commented 3 months ago

Name of the resource

Other

Resource name

No response

Description

Currently, one cannot pass a condition from a top level module to a custom module for usage in a module's lower level condition. Below I present the condition for which this occurs:

Top Level file:

AWSTemplateFormatVersion: "2010-09-09"
Parameters:
  Var1:
    Type: String
    Default: ''
  Var2:
    Type: String
    Default: ''

Conditions:
  BothVarsFilled: !And
    - !Not
      - !Equals
        - !Ref Var1
        - ''
    - !Not
      - !Equals
        - !Ref Var2
        - ''

Resources:
  MyModule:
    Type: "CUSTOM::Test::Test::MODULE"
    Properties:
      AreBothVarsFilled: !If [BothVarsFilled, true, false]

CUSTOM::Test::Test::MODULE:


AreBothVarsFilled:
    Type: String
    AllowedValues:
      - true
      - false
    Description: Boolean parameter validating whether both vars are filled.

Conditions:
  BothVarsFilledCond: !Equals
    - !Ref AreBothVarsFilled
    - true

Resources:
  NewResource:
    Type: ...
    Condition: BothVarsFilledCond
    Properties:
      ...

In this case, currently one receives the following error message when deploying a stack:

CloudFormation failed to preprocess the stack: Template error: Fn::If cannot be preprocessed

This occurs because the module condition is utilizing the condition from the top level as a parameter.

Other Details

Likely the same issue experienced by: https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/1257