Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import CRD definition #158

Open
headyj opened this issue Mar 7, 2022 · 3 comments
Open

Cannot import CRD definition #158

headyj opened this issue Mar 7, 2022 · 3 comments

Comments

@headyj
Copy link

headyj commented Mar 7, 2022

I cannot import an existing resource in my state using the provided documentation:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: rabbitmqclusters.rabbitmq.com
terraform import kubectl_manifest.rabbitmq_clusters
apiextensions.k8s.io/v1//CustomResourceDefinition//rabbitmqclusters.rabbitmq.com
kubectl_manifest.rabbitmq_clusters[0]: Importing from ID "apiextensions.k8s.io/v1//CustomResourceDefinition//rabbitmqclusters.rabbitmq.com"...
╷
│ Error: failed to get resource apiextensions.k8s.io/v1 CustomResourceDefinition rabbitmqclusters.rabbitmq.com from kubernetes: customresourcedefinitions.apiextensions.k8s.io "rabbitmqclusters.rabbitmq.com" not found

As you can see, it says that the rabbitmqclusters.rabbitmq.com crd does not exist, but it does:

kubectl get crd rabbitmqclusters.rabbitmq.com -o jsonpath='{.apiVersion}:{.metadata.name}'
apiextensions.k8s.io/v1:rabbitmqclusters.rabbitmq.com
@NickLarsenNZ
Copy link

I have a similar problem, except I get an Unauthorized (but I am able to otherwise manage the cluster resources).

Trying to do

terraform import -var-file=env/${ENVIRONMENT}.tfvars 'kubectl_manifest.grafana_operator_crds["grafanadashboards"]' apiextensions.k8s.io/v1//CustomResourceDefinition//grafanadashboards.integreatly.org

The error:

╷
│ Error: failed to get resource apiextensions.k8s.io/v1 CustomResourceDefinition grafanadashboards.integreatly.org from kubernetes: Unauthorized
│ 
│ 
╵

And I can see the resource exists:

kubectl get crd grafanadashboards.integreatly.org -o jsonpath='{.apiVersion}:{.metadata.name}'
apiextensions.k8s.io/v1:grafanadashboards.integreatly.org

@NickLarsenNZ
Copy link

I managed to resolve my issue with this: hashicorp/terraform-provider-kubernetes#918 (comment)

@kolja-lucht
Copy link

Had the same problem where I received an error that the resource that I was trying to import does not exist. After trying it with a slightly different command I actually got an helpful error back:
Error: expected ID in format apiVersion//kind//name//namespace, received: v1//name-of-resource

So after adjusting the ID accordingly the import was finally successful 🙌

terraform import kubectl_manifest.my_configmap v1//ConfigMap//name-of-configmap-//name-of-namespace

I'm assuming by default it looks for the resource in the default namespace if it isn't specified in the import command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants