Learning Objectives
By the end of this chapter, you will be able to:
- Import existing infrastructure into your Terraform workspace using both
terraform importand theimportblock. - Use the CLI to inspect state through
terraform state list,terraform state show, and their related commands. - Describe when and how to use verbose logging with
TF_LOG,TF_LOG_PATH,TF_LOG_CORE, andTF_LOG_PROVIDER.
Executive Summary
- The legacy
terraform importCLI binds one real object to one address in state per invocation; it never writes HCL. - The
importblock makes import a planned, reviewable change and pairs withterraform plan -generate-config-outto scaffold HCL for the imported resource. terraform state listandterraform state showare read-only inspection commands; both honour resource-address syntax and both redact attributes marked sensitive.TF_LOGset toTRACE,DEBUG,INFO,WARN,ERROR, orJSONswitches Terraform's internal logger on;TF_LOG_PATHredirects the stream off stderr;TF_LOG_COREandTF_LOG_PROVIDERtarget only Core or only the provider plugins.
Assumptions
- The reader has worked through the workflow, configuration, modules, and state chapters and is comfortable with resource addresses, the
terraformblock, and remote backends. - Examples use generic providers (
random,local,null,tls) and a single illustrative cloud surface so the focus stays on maintenance semantics rather than cloud-service trivia. - Cross-references use the exact terminology established in earlier chapters; no previously defined term is re-defined here.
