Skip to content

Latest commit

 

History

History
71 lines (52 loc) · 2.5 KB

terraform.md

File metadata and controls

71 lines (52 loc) · 2.5 KB

Run with Terraform

falco supports reading VCL configuration from terraform planned result which is generated by Fastly Provider.

Usage

falco terraform -h
=========================================================
    ____        __
   / __/______ / /_____ ____
  / /_ / __  // //  __// __ \
 / __// /_/ // // /__ / /_/ /
/_/   \____//_/ \___/ \____/  Fastly VCL developer tool

=========================================================
Usage:
    falco terraform [action] [flags]

Actions:
    lint     : Run lint (default)
    stats    : Analyze VCL statistics
    simulate : Run simulator server with planned JSON
    test     : Run local testing for planned JSON

Flags:
    -I, --include_path : Add include path
    -h, --help         : Show this help
    -v                 : Output lint warnings (verbose)
    -vv                : Output all lint results (very verbose)
    -json              : Output results as JSON (very verbose)

Linting with terraform:
    terraform plan -out planned.out
    terraform show -json planned.out | falco -vv terraform

Terraform can output plan result to file and show as JSON. falco could retrieve planned VCL definition from it, and run action linting, simulate, and testing from the retrieved source.

falco terraform subcommand builds VCLs from providing JSON as stdin:

# Plan terraform and output to file using fastly terraform provider
terraform plan -out planned.out

# Show JSON and pipe to the falco, run linting
terraform show -json planned.out | falco terraform

# If the linter has passed, apply it!
terraform apply "planned.out"

For example, if you run unit testing from terraform planned result, you can do as following:

# Plan terraform and output to file using fastly terraform provider
terraform plan -out planned.out

# Show JSON and pipe to the falco, run linting
terraform show -json planned.out | falco terraform test -I /path/to/testing/director

How it work

terraform plan result has specific field about built VCL, then falco could retrieve its fields internally and process actions. You MUST include Fastly Provider planned result in output either root module or child module.

Note

You can define multiple custom VCLs in vcl field in fastly_service_vcl resource, but falco treats only the main module which is defined with main = true initially, and will not evaluate other vcl definitions until they are included by a include statement in main VCL.