Usage

terraform init

It’s
 the
 first
 command
 you
 need
 to
 execute.
 Otherwise,
 terraform plan,
 apply,
 destroy
 and
 import
 will
 not
 work. It is safe to run this command multiple times.


The
 command will

:

  • find terraform
 modules based on source provided

  • configure and validate 
a
 backend (if present)

  • install provider(s) 
plugins

terraform validate

Once you’ve initialized the directory, it’s a good idea to run thevalidate command before you run plan or apply. Validation catches syntax errors, version errors and more.

It is safe to run this command automatically, for example as a post-save check in a text editor or as a test step for a re-usable module in a CI system.

This
 command
 is
 useful
 when you have
 some
 modules defined.


terraform get
­

The modules are downloaded into a .terraform subdirectory of the current working directory. Don't commit this directory to your version control repository.

update=true - If specified, modules that are already downloaded will be checked for updates and the updates will be downloaded if present.

The
 plan
 command creates an execution plan which allows previewing changes. Like a dry run, it won't actually apply any of the proposed changes.


terraform
 plan
­

By default, when Terraform creates a plan it:

  • Reads the current state of any already-existing remote objects to make sure that the Terraform state is up-to-date.

  • Compares the current configuration to the prior state and noting any differences.

  • Proposes a set of change actions that should, if applied, make the remote objects match the configuration.

Next comes the apply command which will execute the actions proposed in the plan.

terraform apply

-auto-approve - Skips interactive approval of plan before applying. This option is ignored when you pass a previously-saved plan file, because Terraform considers you passing the plan file as the approval and so will never prompt in that case.

Apply only one resource

terraform
 apply -target="module.s3"


terraform 
destroy

This command deletes all the resources in the configuration.

A
 deletion 
plan
 can
 be 
created
 before execution:


terraform 
plan 
–destroy

Deletions can take a target resource too.

terraform 
destroy -
­target="
aws_s3_bucket.my_bucket"

Last updated