There are two ways to do so.

1. Import directly from CLI

Warning

This approach entails you modifying Terraform’s state file directly, instead of going through a CI/CD pipeline.

Run the following command, with variables specified as needed:

terraform import -var-file=my-var-file.tfvars ADDR ID

ADDR is the path to the resource defined in the Terraform codebase. Something like module.my-submodule.resource_type.resource_name

ID is the identifier for that existing resource to import.

2. Using an import block

This approach wasn’t successful initially. It requires that the block be placed in the root of the module. However, I wasn’t able to get the syntax working to try this further.

Deployment strategy

In theory, the import block is first added in a PR along with the resource definition. Once the resource is added, a second PR is created to remove that import block.