英文:
How can I fix ExactlyOneOf: foo references unknown attribute (bar) at part (bar) from terraform-plugin-sdk?
问题
一些背景信息:我正在编写自己的TF提供程序,具有以下模式:
func Provider() *schema.Provider {
log.Printf("[INFO] Creating Cool Provider")
return &schema.Provider{
Schema: map[string]*schema.Schema{
...
"foo": {
Type: schema.TypeString,
Optional: true,
Default: "bar",
ExactlyOneOf: []string{"bar"},
},
},
ConfigureContextFunc: providerConfigure,
ResourcesMap: map[string]*schema.Resource{
...
},
}
}
当我构建并运行tf plan
时,我遇到了以下问题:
│ 内部验证提供程序失败!这始终是提供程序本身的错误,而不是用户问题。请报告此错误:
│
│ 发生了1个错误:
│ * ExactlyOneOf: foo引用了未知属性(bar),位于部分(bar)
这似乎是由于terraform-plugin-sdk
引起的:链接。例如,当我注释掉ExactlyOneOf
部分时,tf plan
没有错误,并且按预期输出计划。
英文:
Some context: I'm in the process of writing my own TF provider with the following schema:
func Provider() *schema.Provider {
log.Printf("[INFO] Creating Cool Provider")
return &schema.Provider{
Schema: map[string]*schema.Schema{
...
"foo": {
Type: schema.TypeString,
Optional: true,
Default: "bar",
ExactlyOneOf: []string{"bar"},
},
},
ConfigureContextFunc: providerConfigure,
ResourcesMap: map[string]*schema.Resource{
...
},
}
}
When I build it and run tf plan
I run into:
│ Internal validation of the provider failed! This is always a bug
│ with the provider itself, and not a user issue. Please report
│ this bug:
│
│ 1 error occurred:
│ * ExactlyOneOf: foo references unknown attribute (bar) at part (bar)
which seems to be triggering from terraform-plugin-sdk
: link. E.g., when I comment out ExactlyOneOf
part, there're no errors for tf plan
and it outputs the plan as expected.
答案1
得分: 3
正如错误消息所述,属性foo
在其模式结构中引用了另一个未定义的属性bar
。根据您显示的代码,您目前没有定义其他属性bar
,因此您需要定义它或引用一个已定义的属性。
如果您添加了以下属性bar
:
Schema: map[string]*schema.Schema{
...
"foo": {
Type: schema.TypeString,
Optional: true,
Default: "bar",
ExactlyOneOf: []string{"bar"},
},
"bar": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
那么这将修复您的代码。请注意,在模式结构的文档中,ExactlyOneOf
的说明如下:
// ExactlyOneOf是一组模式键,当设置时,该列表中的一个键可以被指定。如果没有指定任何键,它将报错。
ExactlyOneOf []string
英文:
As the error message states, the attribute foo
is referencing another undefined attribute bar
in its schema struct. You currently have no other attribute bar
defined according to your displayed code, so you would need to define it or reference a defined attribute.
If you added an attribute bar
like the following:
Schema: map[string]*schema.Schema{
...
"foo": {
Type: schema.TypeString,
Optional: true,
Default: "bar",
ExactlyOneOf: []string{"bar"},
},
"bar": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
then this would fix your code. Note in the schema struct documentation for ExactlyOneOf
:
// ExactlyOneOf is a set of schema keys that, when set, only one of the
// keys in that list can be specified. It will error if none are
// specified as well.
ExactlyOneOf []string
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论