atmos terraform
Use these subcommands to interact with terraform
.
Usage
Executes terraform
commands.
atmos terraform <command> <component> -s <stack> [options]
atmos terraform <command> <component> --stack <stack> [options]
Atmos supports all terraform
commands and options described in Terraform CLI reference.
In addition, the component
argument and stack
flag are required to generate variables and backend config for the component in the stack.
Additions and differences from native terraform
:
before executing other
terraform
commands, Atmos runsterraform init
you can skip over atmos calling
terraform init
if you know your project is already in a good working state by using the--skip-init
flag like soatmos terraform <command> <component> -s <stack> --skip-init
atmos terraform deploy
command executesterraform apply -auto-approve
(sets-auto-approve
flag when runningterraform apply
)atmos terraform deploy
command supports--deploy-run-init=true|false
flag to enable/disable runningterraform init
before executing the commandatmos terraform apply
andatmos terraform deploy
commands support--from-plan
flag. If the flag is specified, the commands will use the planfile previously generated byatmos terraform plan
command instead of generating a new planfile, e.g.atmos terraform apply <component> -s <stack> --from-plan
. Note that in this case, the planfile name is in the format supported by Atmos and is saved to the component's folderatmos terraform apply
andatmos terraform deploy
commands support--planfile
flag to specify the path to a planfile. The--planfile
flag should be used instead of the planfile argument in the nativeterraform apply <planfile>
command. For example, you can execute the commandatmos terraform plan <component> -s <stack> -out=<FILE>
, which will save the generated plan to a file on disk, and then execute the commandatmos terraform apply <component> -s <stack> --planfile <FILE>
to apply the previously generated planfileatmos terraform clean
command deletes the.terraform
folder,.terraform.lock.hcl
lock file, and the previously generatedplanfile
andvarfile
for the specified component and stack. Use the--skip-lock-file
flag to skip deleting the.terraform.lock.hcl
file.atmos terraform workspace
command first runsterraform init -reconfigure
, thenterraform workspace select
, and if the workspace was not created before, it then runsterraform workspace new
atmos terraform import
command searches forregion
in the variables for the specified component and stack, and if it finds it, setsAWS_REGION=<region>
ENV var before executing the commandatmos terraform generate backend
command generates a backend config file for an Atmos component in a stackatmos terraform generate backends
command generates backend config files for all Atmos components in all stacksatmos terraform generate varfile
command generates a varfile for an Atmos component in a stackatmos terraform generate varfiles
command generates varfiles for all Atmos components in all stacksatmos terraform shell
command configures an environment for an Atmos component in a stack and starts a new shell allowing executing all native terraform commands inside the shelldouble-dash
--
can be used to signify the end of the options for Atmos and the start of the additional native arguments and flags for theterraform
commands. For example:atmos terraform plan <component> -s <stack> -- -refresh=false
atmos terraform apply <component> -s <stack> -- -lock=false
Run atmos terraform --help
to see all the available options
Examples
atmos terraform plan test/test-component-override-3 -s tenant1-ue2-dev
atmos terraform plan test/test-component-override-3 -s tenant1-ue2-dev --skip-lock-file
atmos terraform plan test/test-component-override-2 -s tenant1-ue2-dev --redirect-stderr /dev/stdout
atmos terraform plan test/test-component-override -s tenant1-ue2-dev --redirect-stderr ./errors.txt
atmos terraform apply test/test-component-override-3 -s tenant1-ue2-dev
atmos terraform apply test/test-component-override-2 -s tenant1-ue2-dev --redirect-stderr /dev/stdout
atmos terraform apply test/test-component-override -s tenant1-ue2-dev --redirect-stderr ./errors.txt
atmos terraform destroy test/test-component-override-3 -s tenant1-ue2-dev
atmos terraform destroy test/test-component-override-2 -s tenant1-ue2-dev --redirect-stderr /dev/stdout
atmos terraform destroy test/test-component-override -s tenant1-ue2-dev --redirect-stderr /dev/null
atmos terraform init test/test-component-override-3 -s tenant1-ue2-dev
atmos terraform clean test/test-component-override-3 -s tenant1-ue2-dev
atmos terraform workspace test/test-component-override-3 -s tenant1-ue2-dev
atmos terraform workspace test/test-component-override-3 -s tenant1-ue2-dev --redirect-stderr /dev/null
atmos terraform workspace test/test-component-override-3 -s tenant1-ue2-dev --redirect-stderr /dev/stdout
atmos terraform workspace test/test-component-override-3 -s tenant1-ue2-dev --redirect-stderr ./errors.txt
atmos terraform plan test/test-component -s tenant1-ue2-dev -- -refresh=false -lock=false
Arguments
Argument | Description | Required |
---|---|---|
component | Atmos terraform component | yes |
Flags
Flag | Description | Alias | Required |
---|---|---|---|
--stack | Atmos stack | -s | yes |
--dry-run | Dry run | no | |
--redirect-stderr | File descriptor to redirect stderr to.Errors can be redirected to any file or any standard file descriptor (including /dev/null ) | no |
All native terraform
flags are supported
Subcommands
📄️ clean
Use this command to delete the .terraform folder, the folder that TFDATADIR ENV var points to, .terraform.lock.hcl file, varfile
📄️ deploy
Use this command to execute terraform apply -auto-approve on an Atmos component in an Atmos stack.
📄️ generate backend
Use this command to generate a Terraform backend config file for an Atmos terraform component in a stack.
📄️ generate backends
Use this command to generate the Terraform backend config files for all Atmos terraform components in all stacks.
📄️ generate varfile
Use this command to generate a varfile (.tfvar ) for an Atmos terraform component in a stack.
📄️ generate varfiles
Use this command to generate the Terraform varfiles (`.tfvar`) for all Atmos terraform components in all stacks.
📄️ shell
This command starts a new `SHELL` configured with the environment for an Atmos component in a stack to allow execution of all native terraform commands inside the shell without using any atmos-specific arguments and flags. This may by helpful to debug a component without going through Atmos.
📄️ workspace
This command calculates the `terraform` workspace for an Atmos component (from the context variables and stack config). It runs `terraform init -reconfigure` and selects the workspace by executing the `terraform workspace select` command.