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

Avoid crash when importing invalid ID #46

Merged
merged 1 commit into from
Aug 15, 2017

Conversation

radeksimko
Copy link
Member

Fixes #41

Before

$ terraform import kubernetes_pod.test terraform-nginx-example-43zkw
kubernetes_pod.test: Importing from ID "terraform-nginx-example-43zkw"...
kubernetes_pod.test: Import complete!
  Imported kubernetes_pod (ID: terraform-nginx-example-43zkw)
kubernetes_pod.test: Refreshing state... (ID: terraform-nginx-example-43zkw)
Error importing: 1 error(s) occurred:

* kubernetes_pod.test (import id: terraform-nginx-example-43zkw): 1 error(s) occurred:

* import kubernetes_pod.test result: terraform-nginx-example-43zkw: kubernetes_pod.test: unexpected EOF
panic: runtime error: index out of range
2017/08/11 15:02:10 [DEBUG] plugin: terraform-provider-kubernetes:
2017/08/11 15:02:10 [DEBUG] plugin: terraform-provider-kubernetes: goroutine 32 [running]:
2017/08/11 15:02:10 [DEBUG] plugin: terraform-provider-kubernetes: github.com/terraform-providers/terraform-provider-kubernetes/kubernetes.idParts(0xc4205d5b00, 0x1d, 0x68, 0x26d1000, 0xc4202a70f8, 0x0)
2017/08/11 15:02:10 [DEBUG] plugin: terraform-provider-kubernetes: 	/Users/radeksimko/gopath/src/github.com/terraform-providers/terraform-provider-kubernetes/kubernetes/structures.go:17 +0x95
...

After

$ terraform import kubernetes_pod.test terraform-nginx-example-43zkw
kubernetes_pod.test: Importing from ID "terraform-nginx-example-43zkw"...
kubernetes_pod.test: Import complete!
  Imported kubernetes_pod (ID: terraform-nginx-example-43zkw)
kubernetes_pod.test: Refreshing state... (ID: terraform-nginx-example-43zkw)
Error importing: 1 error(s) occurred:

* kubernetes_pod.test (import id: terraform-nginx-example-43zkw): 1 error(s) occurred:

* import kubernetes_pod.test result: terraform-nginx-example-43zkw: kubernetes_pod.test: Unexpected ID format ("terraform-nginx-example-43zkw"), expected "namespace/name".

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise LGTM :)

parts := strings.Split(id, "/")
return parts[0], parts[1]
if len(parts) < 2 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this want to be if len(parts) != 2 to catch trailing slashes too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I'll change it.

@radeksimko radeksimko force-pushed the b-error-out-on-invalid-id branch from ac55e72 to d821aa6 Compare August 15, 2017 08:42
@radeksimko radeksimko merged commit 004ed6b into master Aug 15, 2017
@radeksimko radeksimko deleted the b-error-out-on-invalid-id branch August 15, 2017 08:44
@ghost ghost locked and limited conversation to collaborators Apr 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terraform import command crash failures for resources with ids of the form x/y
2 participants