Repository navigation
Expand file tree
/
Copy path06-import-existing.tf
More file actions
54 lines (49 loc) · 1.76 KB
/
Copy path06-import-existing.tf
File metadata and controls
54 lines (49 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 06 - Import Existing Resources: bring Coolify resources under Terraform
#
# Shows how to write resource blocks for existing Coolify resources
# and import them into Terraform state. After import, Terraform
# manages the resource lifecycle.
#
# Prerequisites:
# - Existing resources in Coolify (project, application, database)
# - Their UUIDs (find via API or Coolify UI)
#
# Step 1: Write the resource blocks below with matching attributes.
# Step 2: Import each resource:
# terraform import coolify_project.existing <project-uuid>
# terraform import coolify_application.existing <app-uuid>
# terraform import coolify_database_postgresql.existing <db-uuid>
#
# Step 3: Run terraform plan to verify no changes are detected.
# Step 4: Adjust attributes until plan shows no diff.
terraform {
required_providers {
coolify = {
source = "coolify-terraform/coolify"
}
}
}
provider "coolify" {}
# Import: terraform import coolify_project.existing <uuid>
resource "coolify_project" "existing" {
name = "existing-project"
description = "Imported into Terraform"
}
# Import: terraform import coolify_application.existing <uuid>
resource "coolify_application" "existing" {
project_uuid = coolify_project.existing.uuid
server_uuid = "your-server-uuid"
git_repository = "https://github.com/your-org/your-repo"
git_branch = "main"
build_pack = "nixpacks"
ports_exposes = "3000"
}
# Import with composite ID:
# terraform import coolify_environment_variable.db_url \
# application:<app-uuid>:<env-var-uuid>
resource "coolify_environment_variable" "db_url" {
application_uuid = coolify_application.existing.uuid
key = "DATABASE_URL"
value = "postgresql://user:pass@db:5432/myapp"
is_build = false
}