terraform-provider-kustomization: Import errors out with "ResourceExists: unexpected end of JSON input"
As the title says. Any form of import for existing resources errors out with these lines:
kustomization_resource.argocd["~G_v1_Service|argocd|argocd-server"]: Importing from ID "~G_v1_Service|argocd|argocd-server"...
kustomization_resource.argocd["~G_v1_Service|argocd|argocd-server"]: Import prepared!
Prepared kustomization_resource for import
kustomization_resource.argocd["~G_v1_Service|argocd|argocd-server"]: Refreshing state... [id=8a695083-93f5-492f-92ec-959680e9db61]
Error: ResourceExists: unexpected end of JSON input
The id 8a695083-93f5-492f-92ec-959680e9db61 does match with the existing service in this case.
The rendered json in plan mode looks correct as far as I can tell:
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# kustomization_resource.argocd["~G_v1_Service|argocd|argocd-server"] will be created
+ resource "kustomization_resource" "argocd" {
+ id = (known after apply)
+ manifest = jsonencode(
{
+ apiVersion = "v1"
+ kind = "Service"
+ metadata = {
+ labels = {
+ app.kubernetes.io/component = "server"
+ app.kubernetes.io/name = "argocd-server"
+ app.kubernetes.io/part-of = "argocd"
}
+ name = "argocd-server"
+ namespace = "argocd"
}
+ spec = {
+ ports = [
+ {
+ name = "http"
+ port = 80
+ protocol = "TCP"
+ targetPort = 8080
},
+ {
+ name = "https"
+ port = 443
+ protocol = "TCP"
+ targetPort = 8080
},
]
+ selector = {
+ app.kubernetes.io/name = "argocd-server"
}
}
}
)
}
Plan: 1 to add, 0 to change, 0 to destroy.
Am I mistaken about the import line or is this just a bug?
MVP:
# argocd/kustomization.yaml
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: argocd
bases:
- github.com/argoproj/argo-cd/manifests/ha/cluster-install?ref=v1.6.1
# argocd.tf
data "kustomization" "argocd" {
path = "argocd/"
}
resource "kustomization_resource" "argocd" {
for_each = data.kustomization.argocd.ids
manifest = data.kustomization.argocd.manifests[each.value]
}
% terraform import 'kustomization_resource.argocd["~G_v1_Service|argocd|argocd-server"]' "~G_v1_Service|argocd|argocd-server"
kustomization_resource.argocd["~G_v1_Service|argocd|argocd-server"]: Importing from ID "~G_v1_Service|argocd|argocd-server"...
kustomization_resource.argocd["~G_v1_Service|argocd|argocd-server"]: Import prepared!
Prepared kustomization_resource for import
kustomization_resource.argocd["~G_v1_Service|argocd|argocd-server"]: Refreshing state... [id=8a695083-93f5-492f-92ec-959680e9db61]
Error: ResourceExists: unexpected end of JSON input
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (6 by maintainers)
@pst The same exact thing is happening to me using this dashboard configuration:
https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.4/aio/deploy/recommended.yamlIf I manually delete thekubernetes-dashboard-key-holderusing kubectl and I doterraform state rmI can get back where I started. Still any furtherapplyafter the first one which successfully deploys the dashboard will fail!Wild guess, try if the secret not having a data attribute causes the error. If it does, I suggest to open a dedicated issue about this.
Not sure what you’re trying to do. But I’d suggest you simply describe your app using Kustomize, then use the
kustomization_builddata source to run the kustomize build and thekustomization_resourcewith thefor_eachattribute to apply it. No need to usekubectl create deploymentor import anything.Also, do yourself a favor and never use the default namespace. Being explicit about the namespace will save you lots of head scratching along the way. Note, unlike kubectl, this provider does not automatically set the default namespace. You need to explicitly set the namespace attribute, even if you wanted to use
default.Okay. So the kustomize version that was used to install the resources that are causing the conflicts was
{Version:kustomize/v3.5.4 GitCommit:3af514fa9f85430f0c1557c4a0291e62112ab026 BuildDate:2020-01-11T03:12:59Z GoOs:linux GoArch:amd64}I patched the deployed release with the current release of kustomize
{Version:kustomize/v3.8.1 GitCommit:0b359d0ef0272e6545eda0e99aacd63aef99c4d0 BuildDate:2020-07-16T00:58:46Z GoOs:linux GoArch:amd64}afterwards I had the same result as you did. It just works perfectly. I don’t know what caused the issue as both the deployment and the output seemed just fine. But I am closing this for now as the issue itself is resolved.