Skip to content

Latest commit

 

History

History
183 lines (139 loc) · 10.1 KB

cli.md

File metadata and controls

183 lines (139 loc) · 10.1 KB

CLI reference

Every option can also be set with its environment variable, and most root options with worker_options in the configuration file. See Running the worker for how the commands fit together.

worker

The terraform worker is a command line utility to orchestrate terraform

The goal is to reduce the amount of boiler plate terraform code, and allow for both a more dynamic execution, as well as a more controlled execution. Through a combination of definitions and providers specified in the configuration file, the worker can be used to build, destroy, and manage terraform deployments.

worker [OPTIONS] COMMAND [ARGS]...
Option Environment variable Default Description
--aws-access-key-id AWS_ACCESS_KEY_ID AWS Access key
--aws-external-id AWS_EXTERNAL_ID If provided, will be used to assume the role specified by --aws-role-arn
--aws-profile AWS_PROFILE The AWS/Boto3 profile to use
--aws-region AWS_DEFAULT_REGION us-east-1 AWS Region to build in
--aws-role-arn AWS_ROLE_ARN If provided, credentials will be used to assume this role (complete ARN)
--aws-secret-access-key AWS_SECRET_ACCESS_KEY AWS access key secret
--aws-session-token AWS_SESSION_TOKEN AWS access key token
--backend WORKER_BACKEND s3 State/locking provider. One of: s3
--backend-bucket WORKER_BACKEND_BUCKET Bucket (must exist) where all terraform states are stored
--backend-plans / --no-backend-plans WORKER_BACKEND_PLANS --no-backend-plans Store plans in the backend
--backend-prefix WORKER_BACKEND_PREFIX terraform/state/{deployment} Prefix to use in backend storage bucket for all terraform states
--backend-region us-east-1 Region where terraform root/lock bucket exists
--config-file (repeatable) WORKER_CONFIG_FILE ./worker.yaml Path to one or more configuration files
--config-var (repeatable) key=value to be supplied as jinja variables in config_file under "var" dictionary, can be specified multiple times
--create-backend-bucket / --no-create-backend-bucket --create-backend-bucket Create the backend bucket if it does not exist
--log-format LOG_FORMAT TEXT The format to use for logging/output
--log-level LOG_LEVEL INFO The level to use for logging/output
--repository-path WORKER_REPOSITORY_PATH . The root repository/working path, any relative paths will be resolved from here
--run-id WORKER_RUN_ID When set, prefix remote plan files with this id
--run-label (repeatable) WORKER_RUN_LABELS key=value recorded on the run by run reporting, such as origin=ci; repeatable, or comma separated
--version Show the version and exit.
--working-dir WORKER_WORKING_DIR Path to use instead of a temporary directory; it must exist, be empty and be writeable, and is left in place after the run

worker clean

Clean up remnants of a deployment

Once a deployment is destroyed via terraform, there are traces left in the backend such as S3 buckets, DynamoDB tables, etc. This command will verify the state is empty, and then remove those traces from the backend.

worker clean [OPTIONS] DEPLOYMENT

DEPLOYMENT is required. Can also be set with WORKER_DEPLOYMENT.

Option Environment variable Default Description
--limit / -l (repeatable) WORKER_LIMIT limit operations to a single definition, multiple values allowed, or separate with commas

worker env

Export environment variables for the configured backend

This command can be useful to setup environment credentials, that the worker will use. It handles configuration for the different backends allowing you to eval the output to have terraform commands work as the worker will execute them. This can be helpful when doing manual state management

worker env [OPTIONS] DEPLOYMENT

DEPLOYMENT is required. Can also be set with WORKER_DEPLOYMENT.

worker plans

List, discard and sweep saved plans

Works on the manifests saved plans get in an S3 backend, under <prefix>/_tfworker/plans/.

worker plans [OPTIONS] COMMAND [ARGS]...

worker plans discard

Discard pending plans so no run can apply them

worker plans discard [OPTIONS] DEPLOYMENT PLAN_IDS

DEPLOYMENT is required. Can also be set with WORKER_DEPLOYMENT.

PLAN_IDS is required.

Option Environment variable Default Description
--definition / -d Only look for the plans in this definition
--reason required Why the plans are discarded

worker plans gc

Retire saved plans that are stale, expired or orphaned

worker plans gc [OPTIONS] DEPLOYMENT

DEPLOYMENT is required. Can also be set with WORKER_DEPLOYMENT.

Option Environment variable Default Description
--all-records Check every plan record, not only those in the pending index
--applying-timeout Also mark plans applying for longer than this (such as 6h) failed
--discard-unconfigured Discard plans for definitions missing from the configuration, even when their state exists
--dry-run Report what would be retired, change nothing
--json Print the result as JSON

worker plans list

List saved plans, oldest first

worker plans list [OPTIONS] DEPLOYMENT

DEPLOYMENT is required. Can also be set with WORKER_DEPLOYMENT.

Option Environment variable Default Description
--definition / -d Only plans for this definition
--json Print the manifests as JSON
--status (repeatable) Only plans in this status; may be given more than once

worker terraform

Execute terraform orchestration on all or a subset of definitions in a deployment

The terraform command is used to plan, apply, and destroy terraform deployments. It dynamically creates and breaks down large states into smaller subsets of deployments which can share common parameters and a fixed set of providers.

worker terraform [OPTIONS] DEPLOYMENT

DEPLOYMENT is required. Can also be set with WORKER_DEPLOYMENT.

Option Environment variable Default Description
--apply / --no-apply WORKER_APPLY --no-apply Apply a terraform plan from a plan file
--apply-failures / --no-apply-failures WORKER_APPLY_FAILURES --apply-failures Stop applying or destroying remaining definitions when an apply or destroy fails
--b64-encode / --no-b64-encode WORKER_B64_ENCODE --no-b64-encode Base64 encode Terraform variables and outputs for use in hook scripts
--backend-use-all-remotes / --no-backend-use-all-remotes WORKER_BACKEND_USE_ALL_REMOTES --no-backend-use-all-remotes Generate remote data sources based on all definition paths present in the backend
--color / --no-color WORKER_COLOR --no-color Colorize the output from terraform command
--destroy / --no-destroy WORKER_DESTROY --no-destroy Execute a destroy operation from a destroy plan file
--fail-on-apply-error / --no-fail-on-apply-error WORKER_FAIL_ON_APPLY_ERROR --fail-on-apply-error Exit non-zero at end of apply or destroy if any definition failed
--fail-on-init-error / --no-fail-on-init-error WORKER_FAIL_ON_INIT_ERROR --fail-on-init-error Exit non-zero at end of init if any definition failed to prepare or init
--fail-on-plan-error / --no-fail-on-plan-error WORKER_FAIL_ON_PLAN_ERROR --fail-on-plan-error Exit non-zero at end of planning if any definition had a plan error
--force-plan / --no-force-plan WORKER_FORCE_PLAN --no-force-plan Plan even when a saved plan is available, replacing the saved plan
--init-failures / --no-init-failures WORKER_INIT_FAILURES --init-failures Stop initializing remaining definitions when a definition fails to prepare or init
--limit (repeatable) WORKER_LIMIT Limit operations to a single definition
--lock-timeout WORKER_LOCK_TIMEOUT How long terraform retries a held state lock, such as 90s or 10m (passed as -lock-timeout to plan, apply and destroy)
--module-mirror / --no-module-mirror WORKER_MODULE_MIRROR --no-module-mirror Fetch git:: module sources for terraform get through one local git mirror per repository per run (needs git 2.31 or newer)
--plan / --no-plan WORKER_PLAN --no-plan Create a terraform plan
--plan-destroy / --no-plan-destroy WORKER_PLAN_DESTROY --no-plan-destroy Create a destroy plan (mutually exclusive with --plan)
--plan-failures / --no-plan-failures WORKER_PLAN_FAILURES --plan-failures Stop planning remaining definitions when a plan error occurs (exit code 1)
--plan-file-path WORKER_PLAN_FILE_PATH Path to plan files, with plan it will save to this location, apply will read from it
--plan-ttl WORKER_PLAN_TTL 7d How long a saved plan may be applied after it was made, such as 12h or 7d
--provider-cache WORKER_PROVIDER_CACHE Directory to be used as a cache for provider plugins
--require-plan-manifest / --no-require-plan-manifest WORKER_REQUIRE_PLAN_MANIFEST --no-require-plan-manifest Refuse to apply a saved plan that has no manifest (plans saved by older workers)
--stream-output / --no-stream-output WORKER_STREAM_OUTPUT --stream-output Stream the output from terraform command
--strict-locking / --no-strict-locking WORKER_STRICT_LOCKING --strict-locking Enable strict locking for terraform providers (fail if pinned providers do not meet constraints)
--target (repeatable) WORKER_TARGET Target specific resources for apply/destroy, can be specified multiple times
--terraform-bin WORKER_TERRAFORM_BIN The complete location of the terraform binary