terraform-provider-argocd
terraform-provider-argocd copied to clipboard
Failure to import an existing argocd application
Terraform version: 1.9.1
ArgoCD provider version: 6.1.1
ArgoCD version: v2.11.1+9f40df0
Affected Resource(s)
- argocd_application
Terraform Configuration Files
resource "argocd_application" "airbyte" {
provider = argocd
metadata {
name = "airbyte"
namespace = "airbyte"
}
spec {
project = "default"
destination {
server = "https://kubernetes.default.svc"
namespace = "airbyte"
}
source {
repo_url = "https://airbytehq.github.io/helm-charts"
chart = "airbyte"
target_revision = "0.248.5"
helm {
release_name = "airbyte"
values = yamlencode({
"global" : {
"airbyteUrl" : "<redacted>"
},
"webapp" : {
"ingress" : {
"enabled" : true,
"className" : "alb",
"annotations" : {
"alb.ingress.kubernetes.io/scheme" : "internal",
"alb.ingress.kubernetes.io/target-type" : "ip",
"alb.ingress.kubernetes.io/backend-protocol" : "HTTP",
"alb.ingress.kubernetes.io/listen-ports" : "[{\"HTTPS\":80}, {\"HTTPS\":443}]",
"alb.ingress.kubernetes.io/ssl-redirect" : "443",
"alb.ingress.kubernetes.io/certificate-arn" : "<redacted>",
"ingress.kubernetes.io/ssl-redirect" : "true"
},
"hosts" : [
{
"host" : "<redacted>",
"paths" : [
{
"path" : "/",
"pathType" : "Prefix"
}
]
}
]
}
}
})
}
}
}
}
Issue Description
When trying to import an existing argocd application into the terraform resource Terraform fails to do so and complains about me trying to import a resource that doesn't exist
> terraform import -var-file vars_development_us-east-1.tfvars argocd_application.airbyte airbyte:airbyte
argocd_application.airbyte: Importing from ID "airbyte:airbyte"...
argocd_application.airbyte: Import prepared!
Prepared argocd_application for import
argocd_application.airbyte: Refreshing state... [id=airbyte:airbyte]
╷
│ Error: Cannot import non-existent remote object
│
│ While attempting to import an existing object to "argocd_application.airbyte", the provider detected that no object exists with the given id. Only pre-existing objects can be imported; check that the id is
│ correct and that it is associated with the provider's configured region or endpoint, or use "terraform apply" to create a new remote object for this resource.
However the resource does exist
argocd app get airbyte
Name: airbyte
Project: default
Server: https://kubernetes.default.svc
Namespace: airbyte
URL: <redacted>
Repo: https://airbytehq.github.io/helm-charts
Target: 0.248.5
Path:
SyncWindow: Sync Allowed
Sync Policy: <none>
Sync Status: Synced to 0.248.5
Health Status: Healthy
...
...
Debug Output
https://gist.github.com/pedrojflores/7a8f1602d209f36bd5300cb3c10345ef
Panic Output
No crash.log available as the provider does not crash
Steps to Reproduce
- Define resource as described above
- terraform import -var-file vars_dev.tfvars argocd_application.airbyte airbyte:airbyte
Expected Behavior
The expected behavior here would be that the resource is imported successfully
Actual Behavior
Terraform complains about the resource I'm trying to import does not exist
Important Factoids
- The Argo CD instance is hosted in EKS
- Access to the Argo CD instance is exposed via an ALB ingress
- The terraform provider is using admin credentials (username and password) to connect to the Argo CD instance
- I'm able to deploy other resources to Argo CD. I'm just not being able to import this application.
References
n/a
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
It seems the provider isn't generating the id of the resource correctly so when you create a resource it just shows argocd_application.myapp: Creation complete after 5s. [id=myapp:] instead of argocd_application.myapp: Creation complete after 5s [id=myapp:namespace] so if you try with terraform import argocd_application.myapp myapp: it should work for now.
I'm also observing this issue and unfortunately the above solution is not working, argocd provider v7.1.0.
can confirm this still an issue in Aug 2025, and the solution above works for me with provider version v7.11.0
also if you try to input the name without the namespace like simply terraform import argocd_application.myapp myapp, it will crash the provider with index out of range error, that should also be fixed and gracefully handled.
The issue still persists in Nov 2025, with 7.11.2 provider. What makes the situation even worse, that I can't use fallback namespace: solution.
I have application A, and application B as a "sidecar" in the same namespace. Application A is already in terraform.
When I do import application B with this hack namespace: terraform is catching application A and fill out the resource's structure of prepared application B. And it's insane.
The solution here to delete non-cascade application B and create the same predefined structure. But it's very very risky because I can misplace resources and damage/destroy resources in namespace. So it's big NO.
I know there are many other tasks, but we need to address this import issue somehow and fix it. The issue exists more than an year.
I spent some time with debugging provider, folks, and it's insane. The problem is in Argocd API. We are using correct structure appName:namespace, but server API responds with argocd instead of a real namespace.
I injected debug appname:namespace collector:
apps, err := si.ApplicationClient.List(ctx, &applicationClient.ApplicationQuery{
// Name: &appName,
// AppNamespace: &namespace,
})
result := ""
for {
apps, _ := si.ApplicationClient.List(ctx, &applicationClient.ApplicationQuery{})
// Print apps
for _, app := range apps.Items {
// fmt.Println(">>>>", app.Name, app.Namespace)
result += fmt.Sprintf("|", app.GetName(), app.GetNamespace())
}
// If no more pages, break
if apps.Continue == "" {
break
}
}
return []diag.Diagnostic{
{
Severity: diag.Error,
Summary: fmt.Sprintf(">>>>>", result),
},
}
My debug output:
Error: >>>>>%!(EXTRA string=|(EXTRA string=datadog-agent, string=argocd)|%!(EXTRA string=external-dns, string=argocd)|%!(EXTRA string=external-secrets, string=argocd)|%!
And query method fails with lookup. You can reproduce this issue with argocd CLI. Take a look:
% argocd app list -N external-dns --grpc-web
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET
(.venv) %
Application kinda doesn't exist.
But if you skip N or namespace (It's exactly how our fallback solution appname: works) you will get all applications and lookup will work:
argocd/external-dns https://kubernetes.default.svc external-dns infra Synced Healthy Manual <none> https://kubernetes-sigs.github.io/external-dns/ . 1.18.0
It's possible to fix the issue on provider level (some dirty hack), but better to fix the root cause. I did some research, and found this bug https://github.com/argoproj/argo-cd/issues/13008 , so it's not something new.