我在main.tf中定义了列表嵌套属性规范,它看起来如下所示:
di_name = [
{
source_name = "test1"
new_d_name = "test2"
new_di_name = "test3"
di_type = "test4"
},
{
source_name = "test1"
new_d_name = "test2"
new_di_name = "test3"
di_type = "test4"
},
]
它对应于以下内容.
"di_name" : schema.ListNestedAttribute{
Optional: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"source_name": schema.StringAttribute{
Required: true,
},
"new_d_name" : schema.StringAttribute{
Required: true,
},
"new_di_name" : schema.StringAttribute{
Required: true,
},
"di_type" : schema.StringAttribute{
Required: true,
},
},
},
type ModelStruct struct {
DName []vmDi `tfsdk:"di_name"`
}
type vmDi struct {
Source Name types.String `tfsdk:"source_name"`
NewDName types.String `tfsdk:"new_d_name"`
NewDiName types.String `tfsdk:"new_di_name"`
DiType types.String `tfsdk:"di_type"`
}
在新的类/包希望是正确的在GO中,我有相应的 struct ,我想用数据初始化.
type VmBi struct {
GetData [] VmDi
}
type VmDi struct {
Source Name string
NewDName string
NewDiName string
DiType string
}
现在,我想使用这个Create方法从di_name列表中的main.tf获取所有值:
func (r *vmResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
Initialize struct with di_name values.
newData := newGoPackage.VmDi {
Put data here from di_name
}
}
既然我不能在这里访问len(Di_Name),我该如何初始化该 struct 呢?
任何帮助都可以,先谢谢你.