tfctl variable import
The tfctl variable import command imports variables from .tfvars files or environment variables into workspaces or variable sets.
Usage
$ tfctl variable import [TFVARS_FILE] [options]
Description
The tfctl variable import command lets you import Terraform variables from .tfvars files or environment variables from the tfctl process environment into a workspace or variable set.
By default, the command targets the current workspace, determined from your profile or local Terraform configuration. Use --variable-set-name and set an organization name to target a variable set instead of a workspace.
The command imports variables from the .tfvars file specified by the TFVARS_FILE argument, if any, and imports them as Terraform variables. The command imports any environment variables specified with the --env option as environment variables.
By default, the command errors if one of the variables already exists in the target workspace or variable set. Use --overwrite to overwrite existing variables.
Arguments
TFVARS_FILE: The.tfvarsfile to import variables from.
Flags
--env=NAME,-e=NAME: Environment variable to import. Imports the specified environment variable from your current shell. Can be repeated to import multiple environment variables.- Optional.
- Data type: string (repeatable)
- Default value: None
--variable-set-name=NAME: Target variable set by name. When specified, imports variables into the named variable set instead of a workspace. The CLI creates the variable set if it does not already exist. When specified, an organization name is also required.- Optional.
- Data type: string
- Default value: None
--organization=NAME: Organization name. An organization name is required when targeting a variable set, either in the active profile's properties, Terraform configuration in the current directory, or set with this option.- Optional.
- Data type: string
- Default value: Auto-resolved from profile or Terraform cloud config
--workspace=NAME: Workspace name override. Overrides the workspace resolved from local configuration.- Optional.
- Data type: string
- Default value: Auto-resolved from Terraform
cloudconfiguration
--overwrite: Update matching existing variables instead of erroring. When enabled, existing variables with the same key are updated instead of causing an error.- Optional.
- Data type: boolean
- Default value:
false
Options
All tfctl commands support options that control output formatting and CLI behavior. Refer to Global flags reference for the complete list of available options.
Examples
The following examples demonstrate how to import variables from .tfvars files or environment variables.
Import Terraform variables from a .tfvars file into the current workspace
The following example imports variables from a .tfvars file into the default workspace.
$ tfctl variable import variables.tfvars
Import environment variables from the tfctl process into a variable set
The following example imports specific environment variables into a variable set.
$ tfctl variable import --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --variable-set-name my-variable-set --organization my-org
Import both .tfvars and environment variables
The following example imports variables from both a .tfvars file and environment variables.
$ tfctl variable import terraform.tfvars --env DATABASE_URL --workspace my-workspace
Import with overwrite enabled
The following example imports variables and overwrites any existing variables with the same key.
$ tfctl variable import variables.tfvars --overwrite