Getting Started
Terrascan is a static code analyzer for Infrastructure as Code. It can be installed and run in a number of different ways, and is most commonly used in automated pipelines to identify policy violations before insecure infrastructure is provisioned.
Running Terrascan for the First Time
Quickly get started with these common first tasks:
Installing Terrascan
Terrascan is a portable executable that does not strictly require installation, and is also available as a container image in Docker Hub. You can use Terrascan in two different methods based on your preference:
Native executable
Terrascan’s release page includes latest version of builds for common platforms. Download and extract the package for your platform. Follow instructions that apply to your platform:
macOS and Linux
Download the latest version of builds for macOS and enter the following command.
Note: for linux, replace Darwin
with Linux
If you want to use this executable for the rest of this quickstart, it will help to create an alias or install the executable onto your path. For example with bash you could do something like this:
or:
Windows
Download the latest version of builds for Windows and enter the following command:
Using a Docker Container
Terrascan is also available as a Docker image in Docker Hub and can be used as follows (assuming you have Docker installed):
If you want to use the Docker image for the rest of this “Getting Started” guide, please refer to the following command. Note the volume (-v)
that is being mapped to the docker, and modify it if necessary to suit your environment.
Note: This command includes a few extra options to enable Terrascan has access to the current directory when it is run.
Scanning with Terrascan
Example of interactive scan or using CLI
In this example, the KaiMonkey project contains some vulnerable Terraform files to scan. To run a scan, follow these steps:
By default Terrascan will output its findings in human friendly format:
You should see a total of 9 violations, which are detailed in the output.
Now that you understand how to run Terrascan, you can explore various options available. The usage page covers the options in detail. For more information, see Related resources.
Related resources
- The usage guide explains general usage, how to scan other types of IaC (such as: Kubernetes, Helm, and Kustomize), List of other IaC providers (e.g. Kubernetes, Helm, etc.), instructions to limit the scan to specific directories or files, and generating the output in different formats.
- The CI/CD page explains how to integrate Terrascan on CI/CD pipelines.
- Terrascan Policy Reference
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.