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

Having issues with more complex templates (e.g. !Ref, FindInMap, !If ) #46

Closed
alinazemian opened this issue Mar 30, 2019 · 7 comments
Closed

Comments

@alinazemian
Copy link

I have installed this extension on Visual Studio Code. Although it is installed properly, the plugin does not recognize more advanced templates. Is that correct or I am missing some part of the installation?

For example, every tag starts with "!" is unknown including the following tags:
!Ref
!FindInMap
!If

@kddejong
Copy link
Contributor

@mraliagha when cfn-lint provides errors it will do so by prefixing them with cfn-lint. Can you provide the full error so I can validate its cfn-lint thats causing it. Usually we see this issue when people are using the generic yaml plugin is as well as it doesn't know about the CloudFormation tags. One thing you could do is configure that plugin to know what the CloudFormation Tags are. In settings just do this.

"yaml.customTags": [
        "!And",
        "!If",
        "!Not",
        "!Equals",
        "!Or",
        "!FindInMap",
        "!Base64",
        "!Cidr",
        "!Ref",
        "!Sub",
        "!GetAtt",
        "!GetAZs",
        "!ImportValue",
        "!Select",
        "!Split",
        "!Join"
    ],

@waynerobinson
Copy link

I've also just installed the package and seem to have similar issues.

A more complete example, which is providing a bad indentation of mapping entry error on the closing square-bracket after the AvailabilityZone: !Select [0, !GetAZs ""].

This template deploys fine and I can't see why there would be an error.

Resources:
  PublicSubnet1:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      AvailabilityZone: !Select [0, !GetAZs ""]
      CidrBlock: !Ref PublicSubnet1CIDR
      MapPublicIpOnLaunch: true
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentName} Public Subnet (AZ1)

My settings.json:

    // Custom tags for the parser to use
    "yaml.customTags": [
        "!And",
        "!If",
        "!Not",
        "!Equals",
        "!Or",
        "!FindInMap",
        "!Base64",
        "!Cidr",
        "!Ref",
        "!Sub",
        "!GetAtt",
        "!GetAZs",
        "!ImportValue",
        "!Select",
        "!Split",
        "!Join"
    ],
    
    // Enable/disable default YAML formatter (requires restart)
    "yaml.format.enable": true,

    "cfnLint.path": "/usr/local/bin/cfn-lint"

The version of cfn-lint is 0.18.1.

When I run it against the YAML file directly it doens't raise these errors.

@waynerobinson
Copy link

waynerobinson commented Apr 6, 2019

Replacing the

AvailabilityZone: !Select [0, !GetAZs ""]

with

AvailabilityZone: 
  Fn::Select: [0, !GetAZs ""]

Fixes the issue with the error being raised in the IDE, but both are valid syntaxes (and I would vastly prefer to use the shortened version).

This seems to happen wherever the shortened function syntax is used within the parameters of another shortened function.

@waynerobinson
Copy link

OK, my fix so far after further research. I have adjusted my yaml.customTags config to specify if each tag's parameter is a scalar or a sequence (or in some case, like !GetAtt a definition for both).

I'm sure I'll probably have to make further changes to this over time, but it appears the value suggested for configuring CloudFormation plugins is incorrect.

Here is my current settings:

    "yaml.customTags": [
        "!And",
        "!If",
        "!Not",
        "!Equals",
        "!Or",
        "!FindInMap sequence",
        "!Base64",
        "!Cidr",
        "!Ref",
        "!Sub",
        "!GetAtt scalar",
        "!GetAtt sequence",
        "!GetAZs",
        "!ImportValue",
        "!Select sequence",
        "!Split",
        "!Join sequence"
    ]

@kddejong
Copy link
Contributor

kddejong commented Apr 6, 2019

Thanks @waynerobinson I'm actually going to update my settings to match this as well. Since this is all related to this plugin https://github.com/redhat-developer/vscode-yaml are you or @mraliagha ok with me closing this issue?

@alinazemian
Copy link
Author

Yes. Mine is fixed as well. Thank you.

@kddejong
Copy link
Contributor

kddejong commented Apr 6, 2019

Thanks.

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

3 participants