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

Converting Stdout []string back to []byte? #57

Closed
14leeyuchieh opened this issue Jan 7, 2021 · 1 comment
Closed

Converting Stdout []string back to []byte? #57

14leeyuchieh opened this issue Jan 7, 2021 · 1 comment

Comments

@14leeyuchieh
Copy link

14leeyuchieh commented Jan 7, 2021

Hi there,

While using this library, I wanted to take the stdout and convert it back into []byte array. However, as Stdout returns a string using the default buffer, I'm having trouble with that.

I tried something along the line of

tfCmd := cmd.NewCmd("/export/content/lid/terraform/bins/0.12.20/terraform", "show", "-no-color", "-json", "tfaasgenerated/plan.tf.out")
// tfCmd := cmd.NewCmd("/export/content/lid/terraform/bins/0.12.20/terraform", "show", "-no-color", "-json")
tfCmd.Dir = "/export/content/lid/data/tfaas-worker/fbe47527-6dd2-4283-95ce-298bdd2e12d9/iac/lit-zscus-1/test-unmanaged"
result := <-tfCmd.Start()
b, err := terraform.NewJSONProcessor(strings.Join(result.Stdout, "\n"), terraform.WithFilter("prior_state")).Bytes()
assert.Nil(t, err)
fmt.Println(fmt.Sprintf("%s", b))

However, parts of the values are missing in the conversion back to []byte! I'm not sure why this is the case. Is there any advice on the way to handle this?

@14leeyuchieh
Copy link
Author

I figured it out. It was b/c I had a wrong command that wasn't sending the full json.

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

1 participant