Merge pull request #8202 from hashicorp/f-testing-value-is-set
testing: Add TestCheckResourceAttrSet helper
This commit is contained in:
commit
cb1787c2f7
|
@ -520,6 +520,31 @@ func ComposeTestCheckFunc(fs ...TestCheckFunc) TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestCheckResourceAttrSet is a TestCheckFunc which ensures a value
|
||||||
|
// exists in state for the given name/key combination. It is useful when
|
||||||
|
// testing that computed values were set, when it is not possible to
|
||||||
|
// know ahead of time what the values will be.
|
||||||
|
func TestCheckResourceAttrSet(name, key string) TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
ms := s.RootModule()
|
||||||
|
rs, ok := ms.Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
is := rs.Primary
|
||||||
|
if is == nil {
|
||||||
|
return fmt.Errorf("No primary instance: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := is.Attributes[key]; ok && val != "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("%s: Attribute '%s' expected to be set", name, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCheckResourceAttr(name, key, value string) TestCheckFunc {
|
func TestCheckResourceAttr(name, key, value string) TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
ms := s.RootModule()
|
ms := s.RootModule()
|
||||||
|
|
Loading…
Reference in New Issue