HashiCorp - Terraform Associate Study Guide

    7: Maintain infrastructure with Terraform

    This chapter covers the maintenance commands that operate against infrastructure that already exists in real providers and state that already lives in a backend. It walks through importing pre-existing cloud objects into the workspace through the `terraform import` CLI and the declarative `import` block, inspecting what state contains with `terraform state list` and `terraform state show` plus their inspection siblings, and turning up verbose logging through `TF_LOG`, `TF_LOG_PATH`, `TF_LOG_CORE`, and `TF_LOG_PROVIDER` when an investigation requires it.

    Learning Objectives

    By the end of this chapter, you will be able to:

    • Import existing infrastructure into your Terraform workspace using both terraform import and the import block.
    • 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, and TF_LOG_PROVIDER.

    Executive Summary

    • The legacy terraform import CLI binds one real object to one address in state per invocation; it never writes HCL.
    • The import block makes import a planned, reviewable change and pairs with terraform plan -generate-config-out to scaffold HCL for the imported resource.
    • terraform state list and terraform state show are read-only inspection commands; both honour resource-address syntax and both redact attributes marked sensitive.
    • TF_LOG set to TRACE, DEBUG, INFO, WARN, ERROR, or JSON switches Terraform's internal logger on; TF_LOG_PATH redirects the stream off stderr; TF_LOG_CORE and TF_LOG_PROVIDER target 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 terraform block, 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.

    Sections in this chapter

    1. Free
    2. Free with account
    3. Free with account
    4. Free with account