cfn-language-discussion icon indicating copy to clipboard operation
cfn-language-discussion copied to clipboard

Transform AWS::LanguageExtensions failed with: Condition layout is incorrect. Rollback requested by user

Open Luchiap opened this issue 1 year ago • 3 comments

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

What goes wrong? Please describe the issue in as much detail as possible. The following code

AWSTemplateFormatVersion: 2010-09-09
Conditions:
  CreateProdAlarm: !Equals #this is true when Environment (which is a parameter) is equal to prod
    - !Ref Environment
    - prod
Transform: 'AWS::LanguageExtensions'
Parameters:
  pRepoARNs1:
    Description: ARN of SSO instance
    Type: CommaDelimitedList
  prepoARNs2:
    Description: ARN of SSO instance
    Type: CommaDelimitedList
  Environment:
    Description: Environment type.
    Type: String
    AllowedValues:
      - prod
      - test
Resources:
  'Fn::ForEach::Topics':
    - TopicName2
    - !If 
      - CreateProdAlarm #if the condition evaluates to true, then use pRepoARNs1, if false use prepoARNs2
      - !Ref pRepoARNs1
      - !Ref prepoARNs2
    - 'SnsTopic${TopicName2}':
        Condition: CreateProdAlarm
        Type: 'AWS::SNS::Topic'
        Properties:
          TopicName: 
           'Fn::Join':
            - '.'
            - - !Ref TopicName2
              - fifo
          FifoTopic: true

if deployed in cloudformation will give error: Transform AWS::LanguageExtensions failed with: Condition layout is incorrect. Rollback requested by user.

While the virtually same template down below will work with no issues.

AWSTemplateFormatVersion: 2010-09-09
Conditions:
  CreateProdAlarm: !Equals #this is true when Environment (which is a parameter) is equal to prod
    - !Ref Environment
    - prod
Transform: 'AWS::LanguageExtensions'
Parameters:
  pRepoARNs1:
    Description: ARN of SSO instance
    Type: CommaDelimitedList
  prepoARNs2:
    Description: ARN of SSO instance
    Type: CommaDelimitedList
  Environment:
    Description: Environment type.
    Type: String
    AllowedValues:
      - prod
      - test
Resources:
  'Fn::ForEach::Topics':
    - TopicName2
    - !If 
      - CreateProdAlarm #if the condition evaluates to true, then use pRepoARNs1, if false use prepoARNs2
      - !Ref pRepoARNs1
      - !Ref prepoARNs2
    - 'SnsTopic${TopicName2}':
        Type: 'AWS::SNS::Topic'
        Condition: CreateProdAlarm
        Properties:
          TopicName: 
           'Fn::Join':
            - '.'
            - - !Ref TopicName2
              - fifo
          FifoTopic: true
        

The difference? The line order. In the second template notice that Type: 'AWS::SNS::Topic' goes at the end. After the Condition statement of the resource.

Expected behavior

I expected the first template to work with no issues.

Observed behavior

The first template failed with error Transform AWS::LanguageExtensions failed with: Condition layout is incorrect. Rollback requested by user. The second template worked with no issues.

Test cases

Parameters: Use prod for Environment Use string comma delimited values for pRepoARNs1 and prepoARNs2.

Additional context

Luchiap avatar Nov 01 '23 16:11 Luchiap

Discovered this same bug recently. You can trigger it by adding DependsOn inside a Container Definition within a Task Definition, since it has a condition.

Seems to be a bug that's merely triggered on the word Condition?

The problematic block that triggered the bug was:

...
ContainerDefinitions:
  - Name: caddy
    DependsOn:
      - Condition: HEALTHY
        ContainerName: app
...

Removing the DependsOn section meant I no longer got the Transform AWS::LanguageExtensions failed with: Condition layout is incorrect. Rollback requested by user. error.

rupertbg avatar Mar 19 '24 11:03 rupertbg

Seeing the same issue on my side. Been working on a feature for a few weeks and this has been a blocker for me.

betancourtl avatar Mar 27 '24 16:03 betancourtl

Using AWS::LanguageExtensions causes errors to be obscured:

Transform: AWS::LanguageExtensions

Parameters:
  Environment:
    Description: Environment
    Type: String

Mappings:
  Environment:
    production:
      Something: true

Resources:
  WebACL:
    Type: AWS::WAFv2::WebACL
    Properties:
      Rules:
        - Key: !If
            - !FindInMap [Environment, !Ref Environment, Something] # <-- This is wrong
            - A
            - B

This is the obscure error message 👎

Failed to create the changeset: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state: For expression "Status" we matched expected path: "FAILED" Status: FAILED. Reason: Transform AWS::LanguageExtensions failed with: Fn::If layout is incorrect

But when just removing the extension

- Transform: AWS::LanguageExtensions

The error message become much more clear 👍

An error occurred (ValidationError) when calling the CreateChangeSet operation: Template error: Fn::If requires a list argument with the first element being a condition

yvele avatar Jun 07 '24 08:06 yvele