这个错误信息表明在使用Terraform的插件SDK时,ExactlyOneOf
约束中的foo
属性引用了未知的属性bar
。ExactlyOneOf
约束用于确保配置中恰好有一个指定的属性被设置。
bar
属性可能不存在于你的schema定义中。bar
属性在你的schema定义中正确声明。bar
属性在你的schema定义中正确声明。bar
属性的名称在所有引用它的地方都拼写正确。以下是一个完整的示例,展示了如何在Terraform插件SDK中正确使用ExactlyOneOf
约束。
package main
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceExample() *schema.Resource {
return &schema.Resource{
Create: resourceExampleCreate,
Read: resourceExampleRead,
Update: resourceExampleUpdate,
Delete: resourceExampleDelete,
Schema: map[string]*schema.Schema{
"foo": {
Type: schema.TypeList,
ExactlyOneOf: []string{"bar"},
Optional: true,
},
"bar": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
func resourceExampleCreate(d *schema.ResourceData, m interface{}) error {
// Implementation for create
return nil
}
func resourceExampleRead(d *schema.ResourceData, m interface{}) error {
// Implementation for read
return nil
}
func resourceExampleUpdate(d *schema.ResourceData, m interface{}) error {
// Implementation for update
return nil
}
func resourceExampleDelete(d *schema.ResourceData, m interface{}) error {
// Implementation for delete
return nil
}
func main() {
// Main function to initialize the provider
}
通过以上步骤和示例代码,你应该能够解决ExactlyOneOf: foo在terraform-plugin-sdk的部分(bar)引用未知属性(bar)
的问题。如果问题仍然存在,建议检查Terraform插件的日志输出,以获取更多详细的错误信息。
领取专属 10元无门槛券
手把手带您无忧上云