Skip to content


terraform init terraform init -backend-config=bucket.tfvars

terraform play

terraform apply

terraform import

The terraform import command is used to import existing infrastructure. The command currently can only import one resource at a time. T Import will find the existing resource from ID and import it into your Terraform state at the given ADDRESS

terraform import aws_instance.example i-abcd1234

Complex Imports

The above import is considered a "simple import": one resource is imported into the state file. An import may also result in a "complex import" where multiple resources are imported. For example, an AWS security group imports an aws_security_group but also one aws_security_group_rule for each rule.

In this scenario, the secondary resources will not already exist in configuration, so it is necessary to consult the import output and create a resource block in configuration for each secondary resource. If this is not done, Terraform will plan to destroy the imported objects on the next run. f

terraform state:

  • The terraform state command is used for advanced state management
  • Usage: terraform state <subcommand> [options] [args]

  • The terraform state list command is used to list resources within a Terraform state.

  • The terraform state pull command is used to manually download and output the state from remote state
  • The terraform state push command is used to manually upload a local state file to remote state
  • The terraform state rm command is used to remove items from the Terraform state
  • The terraform state show command is used to show the attributes of a single resource in the Terraform state.

    Usage: terraform state show [options] ADDRESS

    terraform state rm aws_route_table.todelete
    1 items removed.
    Item removal successful.

terraform taint

The taint command can be used to taint specific resources within a module:

$ terraform taint -module=salt_master aws_instance.salt_master
It is not possible to taint an entire module. Instead, each resource within the module must be tainted separately.

terraform console

The terraform console command creates an interactive console for using interpolations.

If a state file doesn't exist, the console still works and can be used to experiment with supported interpolation functions. Try entering some basic math such as 1 + 5 to see.

The terraform console command will read configured state even if it is remote. This is great for scripting state reading in CI environments or other remote scenarios.

After configuring remote state, run a terraform remote pull command to sync state locally. The terraform console command will use this state for operations.

Because the console currently isn't able to modify state in any way, this is a one way operation and you don't need to worry about remote state conflicts in any way.

terraform remote pull

terraform remote pull command to sync state locally

> terraform remote config \
    -backend=s3 \
    -backend-config="bucket=(YOUR_BUCKET_NAME)" \
    -backend-config="key=terraform.tfstate" \
    -backend-config="region=(YOUR_BUCKET_REGION)" \
Remote configuration updated
Remote state configured and pulled.