Skip to content

CfnLoadBalancer: CfnInclude broken for conditional tags #30740

Closed
@KyleBS

Description

@KyleBS

Describe the bug

When you attempt to CfnInclude a AWS::ElasticLoadBalancingV2::LoadBalancer resource with valid conditional tags CDK errors out

Expected Behavior

CfnInclude should succeed

Current Behavior

An error is thrown:

CfnSynthesisError: Resolution error: Supplied properties not correct for "CfnLoadBalancerProps"                                                                                                                                                                                              
  tags: element 1: {} should have a 'key' and a 'value' property. 

Reproduction Steps

Create a stack and include the following:

const template = `{                                                                                                                         
  "AWSTemplateFormatVersion": "2010-09-09",                             
  "Parameters": {                                                      
    "IsExtraTag": {                                                       
      "Type": "String",            
      "AllowedValues": [                                                  
        "true",                                                           
        "false"                             
      ],                                                                                                                                            
      "Default": "false"                                                                                                                                                                                                                                                                                 
    }                                                                                                                                                                                                                                                                                                    
  },                                                                                                                                                
  "Conditions": {                        
    "AddExtraTag": {                                                 
      "Fn::Equals": [                                                                                                                               
        {                                                                                                                                           
          "data": "IsExtraTag",                                  
          "type": "Ref",                                 
          "isCfnFunction": true                                                                                                                     
        },                                                             
        "true"                                                                                                                                      
      ]                                                        
    }                                                                                                                                               
  },                                                                                                                                                
  "Resources": {                                                                                                                                    
    "MyLoadBalancer": {                                                
      "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",                                                                                          
      "Properties": {                                        
        "Name": "my-load-balancer",                                                                                                                 
        "Subnets": [                                                                                                                                
          "subnet-0123456789abcdef0"                                                                                                                                                                                                                                                                     
        ],                                                                                                                                          
        "SecurityGroups": [                                               
          "sg-0123456789abcdef0"                                                                                                                    
        ],                                                                
        "Scheme": "internet-facing",                                                                                                                
        "LoadBalancerAttributes": [                                       
          {                                                                                                                                         
            "Key": "idle_timeout.timeout_seconds",                      
            "Value": "60"                                                                                                                           
          }                                                               
        ],                         
        "IpAddressType": "ipv4",                                          
        "Tags": [                                                                                                                                   
          {                                 
            "Key": "Name",                                                                                                                          
            "Value": "MyLoadBalancer"                                                                                                                                                                                                                                                                    
          },                                                                                                                                                                                                                                                                                             
          {                                                                                                                                         
            "data": [                          
              "IsExtraTag",                                          
              {                                                                                                                                     
                "Key": "Name2",                                                                                                                     
                "Value": "MyLoadBalancer2"                       
              },                                         
              {                                                                                                                                     
                "data": "AWS::NoValue",                                
                "type": "Ref",                                                                                                                      
                "isCfnFunction": true                          
              }                                                                                                                                     
            ],                                                                                                                                      
            "type": "Fn::If",                                                                                                                       
            "isCfnFunction": true                                      
          }                                                                                                                                         
        ]                                                    
      }                                                                                                                                             
    }                                                                                                                                               
  }
}`;

const tmpobj = tmp.fileSync();                                                                                                                    
                                                                          
fs.writeFileSync(tmpobj.fd, template);                                                                                                            
                                                                          
new CfnInclude(this, 'MyStack', {                                                                                                                 
    templateFile: tmpobj.name                                         
});                                                                                                                                               
                                                                          
tmpobj.removeCallback();  

You will get the exception

CfnSynthesisError: Resolution error: Supplied properties not correct for "CfnLoadBalancerProps"                                                     
  tags: element 1: {} should have a 'key' and a 'value' property.    

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.87.0

Framework Version

No response

Node.js Version

v18.18.2

OS

AL2

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

@aws-cdk/cloudformation-includeIssues related to the "CFN include v.20" package@aws-cdk/coreRelated to core CDK functionalitybugThis issue is a bug.effort/mediumMedium work item – several days of effortp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions