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

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

Open
#90 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
289
Forks
170
PR merge metrics
No merged PRs in 30d

Description

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/`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.