New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/shellwhale/terraform-target-autocompletion

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/shellwhale/terraform-target-autocompletion

  • v0.0.0-20230818110614-accf62fe19ff
  • Source
  • Go
  • Socket score

Version published
Created
Source

terraform-target-autocompletion 🎯💨

License PowerShell Bash

Press tab after --target and get autocomplete suggestions for your resources and modules.

Demo GIF

Requirements

terraform-target-autocompletion is a Go program that rely on terraform-config-inspect for the heavy lifting. So it should work with any Terraform version. You don't need anything else than the binary and the completion scripts provided. But currently you'll need Go 1.21.0 installed to build it yourself.

Installation

PowerShell

First you have to install the binary

go install github.com/shellwhale/terraform-target-autocompletion@latest

Then you need to setup add the following to your PowerShell $PROFILE

$__terraformTargetCompleterBlock = {
    param($supposedToBeDashDashTarget, $commandAst, $cursorPosition);
    $cmdElements = $commandAst.CommandElements;

    $currentLength = $cmdElements[0].Value.Length + $cmdElements[1].Value.Length + $cmdElements[2].Value.Length + 2
    $lengthAfterSearchString = $currentLength + $cmdElements[3].Value.Length + 2
    $targetWordLocation = $cmdElements[2].Value;

    if ($targetWordLocation -EQ '--target' -OR $targetWordLocation -EQ '-target' -AND $cursorPosition -GT $currentLength -AND $cursorPosition -LE $lengthAfterSearchString) {
        $filter = $cmdElements[3].Value;
        if ($filter -EQ "") {
            $filter = "*";
        }
        else {
            $filter += "*";
        }

        $completionResults = @();
        terraform-target-autocompletion | Where-Object { $_ -like $filter } | Sort-Object | ForEach-Object {
            $completionResults += [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
        };
        
        # If no completion items were found, return $null to prevent the trigger of the default filesystem completion.
        if (-not $completionResults) {
            $null;
        } else {
            $completionResults;
        }
    }
}

Register-ArgumentCompleter -Native -CommandName 'terraform' -ScriptBlock $__terraformTargetCompleterBlock;

Bash

First you have to install the binary

# This will install the binary in your $GOBIN
# Make sure it's in your $PATH
# You can set it with export PATH=$PATH:$(go env GOPATH)/bin
go install github.com/shellwhale/terraform-target-autocompletion@latest

Then you need to setup add the following to your bashrc This will currently overwrite the terraform -install-autocomplete bash command so only completion for --target will work. I'm working on a fix for this so you can use both.

#!/bin/bash

terraform_target_autocompletion() {
    if [[ ${COMP_CWORD} -eq 2 || ${COMP_CWORD} -eq 3 ]]; then
        if [[ ${COMP_WORDS[2]} == "--target" || ${COMP_WORDS[2]} == "-target" ]]; then
            if [[ -z ${COMP_WORDS[3]} ]]; then
                filter=".*"
            else
                filter="^${COMP_WORDS[3]}"
            fi
            COMPREPLY=($(terraform-target-autocompletion | grep "$filter" | sort))
        fi
    fi
}

complete -F terraform_target_autocompletion terraform

FAQs

Package last updated on 18 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc