-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
How to modify a cty.ObjectVal? #57
Comments
Hi @steeve85,
If the change you want to make is shallow (that is, it only involves changes to the top-level map or object) then foo1 := cty.ObjectVal(map[string]cty.Value{
"example1": cty.StringVal("a"),
})
fooMap := foo1.AsValueMap()
fooMap["example2"] = cty.StringVal("b")
foo2 := cty.ObjectVal(fooMap) If you want to make a change deep inside the structure then things can get more involved: you'll need to reconstruct each level you want to modify one at a time.
|
@apparentlymart Great, totally make sense. Thank you for the help! |
I am new to Go and to go-cty, and I am wondering how to add a new element into
a["type"]
based on the following sample:I tried something like
a["type"]["test"] = cty.StringVal("value")
anda["type"].AsValueMap()["test"] = cty.StringVal("test2")
but it didn't work.How can I add a new element into
a["type"]
? ThanksThe text was updated successfully, but these errors were encountered: