Import blocks in Terraform

Profile pictureToni Petrina
Published on 2023-09-191 min read
  • #terraform
  • #cicd

Terraform 1.5.0 introduces import blocks which simplify importing resources. Instead of doing the following:

terraform import github_repository.resource_name repo-name

You can write:

import {
    to = github_repository.resource_name
    id = "repo-name"

This is declarative, avoids CLI and can be reviewed in a PR! If you are using Atlantis or similar tool, then import is done when applying instead of a separate step that might change your state.

Additionally, once it is merged, import blocks can be removed in subsequent PRs.

Read more at Import Syntax.

Change code theme: