mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 09:06:44 +00:00
83 lines
2.0 KiB
Go
83 lines
2.0 KiB
Go
package google
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccDataSourceGoogleProjectServices_basic(t *testing.T) {
|
|
t.Parallel()
|
|
org := getTestOrgFromEnv(t)
|
|
project := "terraform-" + acctest.RandString(10)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccCheckGoogleProjectServicesConfig(project, org),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccDataSourceGoogleProjectServicesCheck("data.google_project_services.project_services", "google_project_services.project_services"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccDataSourceGoogleProjectServicesCheck(dataSourceName string, resourceName string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
ds, ok := s.RootModule().Resources[dataSourceName]
|
|
if !ok {
|
|
return fmt.Errorf("root module has no resource called %s", dataSourceName)
|
|
}
|
|
|
|
rs, ok := s.RootModule().Resources[resourceName]
|
|
if !ok {
|
|
return fmt.Errorf("can't find %s in state", resourceName)
|
|
}
|
|
|
|
dsAttr := ds.Primary.Attributes
|
|
rsAttr := rs.Primary.Attributes
|
|
|
|
projectAttrToCheck := []string{
|
|
"project",
|
|
"services",
|
|
}
|
|
|
|
for _, attr := range projectAttrToCheck {
|
|
if dsAttr[attr] != rsAttr[attr] {
|
|
return fmt.Errorf(
|
|
"%s is %s; want %s",
|
|
attr,
|
|
dsAttr[attr],
|
|
rsAttr[attr],
|
|
)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckGoogleProjectServicesConfig(project, org string) string {
|
|
return fmt.Sprintf(`
|
|
resource "google_project" "project" {
|
|
project_id = "%s"
|
|
name = "%s"
|
|
org_id = "%s"
|
|
}
|
|
|
|
resource "google_project_services" "project_services" {
|
|
project = "${google_project.project.id}"
|
|
services = ["admin.googleapis.com"]
|
|
}
|
|
|
|
data "google_project_services" "project_services" {
|
|
project = "${google_project.project.id}"
|
|
}`, project, project, org)
|
|
}
|