aws-cloudformation / cfn-lint-visual-studio-code

CloudFormation Linter IDE integration, autocompletion, and documentation
https://marketplace.visualstudio.com/items?itemName=kddejong.vscode-cfn-lint
Apache License 2.0
257 stars 136 forks source link

Is it possible to pass relative paths to cfn-lint? #90

Open craighurley opened 4 years ago

craighurley commented 4 years ago

Plugin Version: 0.10.20 VS Code version: 1.43.2 OS: Darwin x64 19.4.0

Is it possible to make the cfn-lint plugin use relative paths from the project root rather than absolute paths?

The reason I ask is that I am trying to use cfn-lint in a docker container to avoid pip dependency conflicts I'm having. Outside of VS Code, running cfn-lint in the container against templates works successfully.

In order to make VS Code use the container I do the following:

  1. Create a script at $HOME/bin/cfn-lint
  2. Configure the path to cfn-lint in the VS Code plugin settings to: $HOME/bin/cfn-lint.

The script at $HOME/bin/cfn-lint which I use to pass arguments from VS Code to the container is as follows:

#!/usr/bin/env bash
set -e
docker run --rm -v $PWD:/workdir:ro craighurley/cfn-lint "$@"
exit 0

Now I do the following:

A. Open a project with a project root of /Users/hurley/Projects/example/. B. Open a CFN template at ./templates/ec2.yaml C. VS Code correctly calls the script and passes the template, but because it uses absolute paths it fails with the following:

Settings: {"cfnLint":{"enableAutocomplete":true,"validateUsingJsonSchema":false,"path":"$HOME/bin/cfn-lint","appendRules":[],"ignoreRules":["E3012","W2001","W3011"],"overrideSpecPath":""}}
Determined this file is a CloudFormation Template. file:///Users/hurley/Projects/example/templates/ec2.yaml. Found the string AWSTemplateFormatVersion
running............. $HOME/bin/cfn-lint --format,json,--ignore-checks,E3012,--ignore-checks,W2001,--ignore-checks,W3011,--,"/Users/hurley/Projects/example/templates/ec2.yaml"
2020-04-04 10:04:19,384 - cfnlint.decode - ERROR - Template file not found: /Users/hurley/Projects/example/templates/ec2.yaml

child process exited with code 2 and signal null

The reason for the error is because the container has a volume mapped from /Users/hurley/Projects/example/ on my local machine to /workdir in the container, so cfn-lint inside the container is not aware of /Users/hurley/Projects/example/.

craighurley commented 4 years ago

This issue would also help in my case: https://github.com/aws-cloudformation/aws-cfn-lint-visual-studio-code/issues/60

PatMyron commented 4 years ago

The reason I ask is that I am trying to use cfn-lint in a docker container to avoid pip dependency conflicts I'm having

Sorry about the delayed response. Not sure if this fits your use-case, but figured I'd mention the online demo pre-configures the environment with dependencies and could be a potential alternative without installation problems