santosh.a
santosh.a

Reputation: 535

unable to initialize tflint

I installed tflint on my mac and when I try to execute --init it is throwing 401 error. Could you tell me if I need to export any env variables to fetch git repo.

tflint --init
   Installing `azurerm` plugin...
   Failed to install a plugin. An error occurred:

   Error: Failed to fetch GitHub releases: GET https://api.github.com/repos/terraform- 
   linters/tflint-ruleset-azurerm/releases/tags/v0.14.0: 401 Bad credentials []

.tflint.hcl file

plugin "azurerm" {
    enabled = true
    version = "0.14.0"
    source  = "github.com/terraform-linters/tflint-ruleset-azurerm"
}

i searched tflint documentation but could not find anything.

thanks, Santosh

Upvotes: 3

Views: 14504

Answers (2)

Justin
Justin

Reputation: 745

I was recently was trying to use tflint behind a corporate firewall and was getting checksums errors. I was able to resolve it by:

  1. Adding the following to my .zshrc file. Try open ~/.zshrc to open the file from the Mac terminal.
setup_local_tflint_plugin() {
    for PLUGIN in ${PLUGINS[@]}; do
        TFLINT_PLUGIN_NAME=${PLUGIN%|*}
        TFLINT_PLUGIN_VERSION=${PLUGIN#*|}
 
        TFLINT_PLUGIN_DIR=~/.tflint.d/plugins/terraform-linters/tflint-ruleset-${TFLINT_PLUGIN_NAME}/${TFLINT_PLUGIN_VERSION}
        mkdir -p $TFLINT_PLUGIN_DIR
        FILE=$TFLINT_PLUGIN_DIR/tflint-ruleset-${TFLINT_PLUGIN_NAME}
        if [ ! -f "$FILE" ]; then
            echo "Downloading version ${TFLINT_PLUGIN_VERSION} of the ${TFLINT_PLUGIN_NAME} plugin."
            curl -L "https://github.com/terraform-linters/tflint-ruleset-${TFLINT_PLUGIN_NAME}/releases/download/v${TFLINT_PLUGIN_VERSION}/tflint-ruleset-${TFLINT_PLUGIN_NAME}_${PLATFORM_ARCHITECTURE}.zip" > ${TFLINT_PLUGIN_DIR}/provider.zip
            yes yes | unzip "${TFLINT_PLUGIN_DIR}/provider.zip" -d ${TFLINT_PLUGIN_DIR} | rm ${TFLINT_PLUGIN_DIR}/provider.zip
        fi
    done
    chmod -R +x ~/.tflint.d/plugins
}
 
# Valid values for PLATFORM_ARCHITECTURE are:
# 'darwin_amd64', 'darwin_arm64', 'linux_386', 'linux_amd64',
# 'linux_arm', 'linux_arm64', 'windows_386', 'windows_amd64'
PLATFORM_ARCHITECTURE="darwin_amd64"
PLUGINS=("azurerm|0.16.0" "aws|0.16.0")
 
setup_local_tflint_plugin
  1. Opening up my code editor and navigating to my Terraform scripts.
  2. Creating a .tflint.hcl configuration file in the same folder as my Terraform scripts (like below).
config {
    module = true
    force = false
    disabled_by_default = false
 
    plugin_dir = "~/.tflint.d/plugins/terraform-linters/tflint-ruleset-azurerm/0.16.0"
}
 
plugin "azurerm" {
    enabled = true
}
  1. Opening a new terminal window (plugins should start installing).
  2. Running tflint . --config ./.tflint.hcl.

Note: This only works for one plugin at a time (e.g. azurerm, aws, etc.).

To install a new plugin or plugin version simply add more to the PLUGINS attribute in the .zshrc file. To select the plugin, update the .tflint.hcl files plugin_dir attribute to point to the right plugin and version.

Upvotes: 0

Oleg K
Oleg K

Reputation: 61

tflint requires azurem plugin to be installed. For that download the azurem proper plugin binary here: https://github.com/terraform-linters/tflint-ruleset-azurerm/releases/tag/v0.16.0 (check the version that you need) , unzip it and then move it to your user's .tflint.d/plugins directory (create it if it doesn't exist)

mv ~/Downloads/tflint-ruleset-azurerm ~/.tflint.d/plugins/

Upvotes: 0

Related Questions