Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform AWS::LanguageExtensions failed with: Fn::If layout is incorrect #135

Open
miguel-aws opened this issue Aug 4, 2023 · 2 comments

Comments

@miguel-aws
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Tell us about the bug

Trying to use Fn::If within Fn::ForEach to reference a condition but CloudFormation returns Transform AWS::LanguageExtensions failed with: Fn::If layout is incorrect

Docs state that Fn::If is supported within Fn::ForEach.

See Test cases section for scenarios and replication template.

Expected behavior

Template validates correctly, the conditions are recognized, and proceeds to create the resources.

Observed behavior

Stack events report Transform AWS::LanguageExtensions failed with: Fn::If layout is incorrect

Test cases

Referencing ${Identifier} variable with !Sub to form the condition name causes the error.

        !If
          - !Sub "${ServerType}CreateSecondaryVolume"
          - - DeviceName: xvdf
              Ebs:
                DeleteOnTermination: true
                Encrypted: true
                VolumeSize: 100
                VolumeType: gp3
                Iops: 3000
          - !Ref AWS::NoValue

If we hardcode the condition name (i.e. BackupCreateSecondaryVolume), the stack goes through with no problems,

        !If
          - BackupCreateSecondaryVolume
          - - DeviceName: xvdf
              Ebs:
                DeleteOnTermination: true
                Encrypted: true
                VolumeSize: 100
                VolumeType: gp3
                Iops: 3000
          - !Ref AWS::NoValue

Template

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::LanguageExtensions'
Mappings:
  ServerTypeMapping:
    Backup:
      CreateSecondaryVolume: true
    SQL:
      CreateSecondaryVolume: false
Conditions:
  BackupCreateSecondaryVolume: !Equals [!FindInMap [ServerTypeMapping, Backup, CreateSecondaryVolume], true]
  SQLCreateSecondaryVolume: !Equals [!FindInMap [ServerTypeMapping, SQL, CreateSecondaryVolume], true]
Resources:
  'Fn::ForEach::ServerTypes':
  - ServerType
  - [Backup, SQL]
  - LaunchTemplate${ServerType}:
      Type: AWS::EC2::LaunchTemplate
      Properties:
        LaunchTemplateData:
          BlockDeviceMappings:
            !If
              - !Sub "${ServerType}CreateSecondaryVolume"
              - - DeviceName: xvdf
                  Ebs:
                    DeleteOnTermination: true
                    Encrypted: true
                    VolumeSize: 100
                    VolumeType: gp3
                    Iops: 3000
              - !Ref AWS::NoValue
        LaunchTemplateName:
          Fn::Join: ["-", [!Sub "${AWS::StackName}", !Sub "${ServerType}"]]
@arthurboghossian
Copy link
Contributor

@mparana CloudFormation currently doesn't support an intrinsic function for the 1st parameter (the condition name) of the Fn::If intrinsic function.

For example, calling CreateStack on the template below would result in CreateStack failing with Template error: Fn::If requires a list argument with the first element being a condition:

AWSTemplateFormatVersion: 2010-09-09
Conditions:
  Cond:
    !Equals ["0", "1"]
Resources:
  Topic:
    Type: AWS::SNS::Topic
    Properties:
      TopicName: !If
        - !Sub 'Cond'
        - TrueTopic
        - FalseTopic

So allowing intrinsic functions for the condition name would be a new feature, which would be part of the AWS::LanguageExtensions Transform.

If possible, can you please create a feature request GitHub issue within this repo?

@miguel-aws
Copy link
Author

miguel-aws commented Aug 10, 2023

@arthurboghossian Thank you for the insights.

I created the feature request here: #137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants