question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I1022 Subject to false positives when using intrinstics in Fn::Join

See original GitHub issue

*cfn-lint version: 0.25.0

Description of issue. The recently introduced I1022 which flags the use of Fn::Join with empty delimiter flags use cases which are not necessarily sensible to replace with Fn:Sub.

For example parts of a join can be conditional values, or other intrinsic functions like an Fn::Select on an Fn::Split.

I would suggest that the rule should not trigger if the Fn:Join arguments include any intrinstics other than Fn:Ref or Fn:GetAtt

Here is a simple standalone stack that somewhat questionably triggers I1022, I say questionable in this case because you could argue that it might be clearer to use a conditional outside of two Fn:Sub’s

AWSTemplateFormatVersion: 2010-09-09
Description: "cfn-lint I1022 false positive"

Conditions:
    Cond1: !Equals [ !Ref 'AWS::Region', 'us-east-1' ]

Resources:

    # Simple Conditional In Join with empty delimiter
    Bucket:
        Type: AWS::S3::Bucket
        Properties:
            Tags:
              - Key: Foo
                Value: !Join [ '', [
                     'Prefix/',
                     !If [ Cond1, 'Infix-', '' ],
                     '/Suffix',
                ]]

Here is a more complex real-world example of a situation that would probably very difficult to sensibly convert o Fn:::Sub but triggers I1022

!Join [ '', [ 'ecs-alb-', !Select [ 2, !Split [ '/', !GetAtt ECSALB.LoadBalancerFullName ] ], '.', !Ref ServicesDomainSuffix, '.' ] ]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kddejongcommented, Nov 16, 2019

Good question. I may have to do some testing on that.

I’ve always wondered the same thing about naming a resource and parameter by the same name. What is used when you do a Ref to that similar name.

1reaction
trav-ccommented, Nov 16, 2019

Ah, I hadn’t actually realised that Fn::Sub supported variable maps, I’m inclined to agree that the Sub option is probably clearer / more readable here given that.

The only potential confusion issue I can see with it is that I don’t see any information on the Fn::Sub documentation as to whether mapped variables take precedence (or even triggers an error) if the name conflicts with a !Ref name eg:

Parameters:
    Foo:
        Type: String
        Default: Bar
   NotFoo:
        Type: String
        Default: NotBar
Resources:
...
        Fn::Sub:
            - Replace-${Foo}
            - Foo: !Ref NotFoo

I don’t think that impacts which option is preferable too much though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I1022 Subject to false positives when using intrinstics in Fn::Join
The recently introduced I1022 which flags the use of Fn::Join with empty delimiter flags use cases which are not necessarily sensible to replace ......
Read more >
CloudFormation's built-in functions Fn::Sub vs Fn::Join
Many individuals use the Fn::Join command to combine information in their CloudFormation ... Using Join function we can connect text and variables.
Read more >
Diff - f22bf9f809def57c96a19d932467a175bbd9c08c^2 ... - Google Git
Merge "Merge layout-speed compiler filter into speed-profile." ... disable_flag_offset); + + // Check static flags that prevent using intrinsic.
Read more >
https://raw.githubusercontent.com/aws-cloudformati...
... /blob/main/docs/rules.md#I1022) to not suggest `Fn::Sub` on complext `Fn::Join`s ... Avoid false positives when using a `Ref` against a resource (pull ...
Read more >
CloudFormation protip: use !Sub instead of !Join
CloudFormation supports a number of intrinsic functions and Fn::Join (or !Join ) is often used to construct parameterised names and paths.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found