2017-11-15 21:14:03 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccDataSourceGoogleActiveFolder(t *testing.T) {
|
2017-11-20 23:45:51 +00:00
|
|
|
org := getTestOrgFromEnv(t)
|
2017-11-15 21:14:03 +00:00
|
|
|
|
|
|
|
parent := fmt.Sprintf("organizations/%s", org)
|
|
|
|
displayName := "terraform-test-" + acctest.RandString(10)
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccDataSourceGoogleActiveFolderConfig(parent, displayName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccDataSourceGoogleActiveFolderCheck("data.google_active_folder.my_folder", "google_folder.foobar"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccDataSourceGoogleActiveFolderCheck(data_source_name string, resource_name string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
ds, ok := s.RootModule().Resources[data_source_name]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("root module has no resource called %s", data_source_name)
|
|
|
|
}
|
|
|
|
|
|
|
|
rs, ok := s.RootModule().Resources[resource_name]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("can't find %s in state", resource_name)
|
|
|
|
}
|
|
|
|
|
|
|
|
ds_attr := ds.Primary.Attributes
|
|
|
|
rs_attr := rs.Primary.Attributes
|
|
|
|
folder_attrs_to_test := []string{"parent", "display_name", "name"}
|
|
|
|
|
|
|
|
for _, attr_to_check := range folder_attrs_to_test {
|
|
|
|
if ds_attr[attr_to_check] != rs_attr[attr_to_check] {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"%s is %s; want %s",
|
|
|
|
attr_to_check,
|
|
|
|
ds_attr[attr_to_check],
|
|
|
|
rs_attr[attr_to_check],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccDataSourceGoogleActiveFolderConfig(parent string, displayName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_folder" "foobar" {
|
|
|
|
parent = "%s"
|
|
|
|
display_name = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
data "google_active_folder" "my_folder" {
|
|
|
|
parent = "${google_folder.foobar.parent}"
|
|
|
|
display_name = "${google_folder.foobar.display_name}"
|
|
|
|
}
|
|
|
|
`, parent, displayName)
|
|
|
|
}
|