Open houkms opened 5 years ago
I expect it's only the root property in Read function need such modifications.
I expect it's only the root property in Read function need such modifications.
What if there is also nested object inside another nested object? E.g. we have following nested objects:
type Foo struct {
*Bar
}
type Bar struct {
*Baz
}
type Baz struct {
Name string
}
func main() {
f := &Foo{
&Bar{
&Baz{
Name: "foobar",
},
},
}
if prop := f.Bar; prop != nil {
// `prop` below has different identity
if prop := prop.Baz; prop != nil {
fmt.Println(prop.Name)
}
}
}
Take note at the comment above, where prop
has different identity in one line. Does this kind of style introduce other issue?
I suppose this case will not appear. This issue is essentially a naming convention of Hashicorp, specifically, when using client.response
to set the go SDK filed, they require:
props
to accept the response values.go_filed_name
as the tmp variable name. MM now always uses go_field_name
as the tmp variable name to accept the response values, which is what Hashicorp complains about.
For your specific example. it should be in this way (because Baz
is a nestedOject, we need a flatten function).
if prop := f.Bar; prop != nil {
// `prop` below has different identity
if err := d.set("Baz", flattenBaz(prop.Baz)){
return fmt.Error(" ... ")
}
}
If Baz
is not a nestedObject, we can do it in this way
if prop := f.Bar; prop != nil {
// `prop` below has different identity
if baz := prop.Baz; baz != nil {
return fmt.Error(" ... ")
}
}
After digging further, I found that part of naming is controled by file: nested_object_shcema_assign.erb, as below:
<%
...
temp_var = sdk_type.go_variable_name || sdk_type.go_field_name.camelcase(:lower) || input
-%>
...
And this part is only used for this purpose. From the code above we can see the var name is resolved via prioprity: go_variable_name > go_field_name > input (input is a passed in argument, e.g., 'resp')
So I suppose for this issue, we can just modify the read::response
section in terraform.yaml, adding go_variable_name: properties
to /properties
field.
Auto-Gened:
Expected: