我已经为需要在自定义 terraform 提供程序中验证的字段编写了一些更复杂的验证逻辑。当然,我可以测试这些是单元测试,但这还不够;为什么如果我忘记实际应用验证器?
所以,我需要实际使用 terraform config 并让提供者这样做是正常的、自然的事情。
基本上,我希望它会出错。该文档似乎表明我应该对输出进行正则表达式匹配。但这不可能是正确的;看起来超级脆。有人能告诉我这是怎么做到的吗?
func TestValidation(t *testing.T) {
const userBasic = `
resource "my_user" "dude" {
name = "the.dude%d"
password = "Password1" // needs a special char to pass
email = "the.dude%d@domain.com"
groups = [ "readers" ]
}
`
rgx, _ := regexp.Compile("abc")
resource.UnitTest(t, resource.TestCase{
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: userBasic,
ExpectError: rgx,
},
},
})
}
这段代码显然不起作用。而且,很多研究都没有给出答案。