Terraform Import
The Tailor Platform Terraform provider supports importing existing resources into your Terraform configuration, allowing you to bring resources that were created through the console or CLI.
Importing a single resource
You can import a single existing resource by adding a resource configuration block to your Terraform files and then running the terraform import command.
Example
Let's import an existing TailorDB Namespace into your Terraform configuration:
resource "tailor_tailordb" "example" {
id = "trn:v1:workspace:<workspace_id>:tailordb:<namespace>"
}Then run:
terraform import tailor_tailordb.example trn:v1:workspace:<workspace_id>:tailordb:<namespace>After importing, run terraform plan to verify and adjust the configuration to match the imported state.
Bulk Import existing workspace resources
You can also import all resources in a workspace by following these steps:
- Export existing resources:
tailorctl workspace export --output {OUTPUT_DIRECTORY}- Create
{OUTPUT_DIRECTORY}/provider.tf:
terraform {
required_providers {
tailor = {
source = "tailor-platform/tailor"
version = ">= 1.1.1"
}
}
}
provider "tailor" {}- Run
terraform planto generate and validate the imported resource configurations:
terraform plan -generate-config-out=imported_resources.tfReview imported_resources.tf to ensure all resources are correctly imported.
Incremental Importing
Incremental importing allows you to gradually bring resources to your workspace comparing and importing only the resources not already tracked in your current state.
- Export current state to JSON:
terraform show -json > existing.json- Export only resources not in the existing state:
tailorctl workspace export --output {OUTPUT_DIRECTORY} --state existing.jsonThis will export the resources that are not in the existing.json file. Import the new resources using the Terraform import process.