mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-15 07:27:15 +00:00
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
|
package google
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/hashicorp/terraform/helper/resource"
|
||
|
"github.com/hashicorp/terraform/terraform"
|
||
|
)
|
||
|
|
||
|
func TestAccDataSourceIAMRole(t *testing.T) {
|
||
|
name := "roles/viewer"
|
||
|
|
||
|
resource.Test(t, resource.TestCase{
|
||
|
PreCheck: func() { testAccPreCheck(t) },
|
||
|
Providers: testAccProviders,
|
||
|
Steps: []resource.TestStep{
|
||
|
{
|
||
|
Config: testAccCheckGoogleIamRoleConfig(name),
|
||
|
Check: resource.ComposeTestCheckFunc(
|
||
|
testAccCheckGoogleIAMRoleCheck("data.google_iam_role.role"),
|
||
|
),
|
||
|
},
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func testAccCheckGoogleIAMRoleCheck(n string) resource.TestCheckFunc {
|
||
|
return func(s *terraform.State) error {
|
||
|
ds, ok := s.RootModule().Resources[n]
|
||
|
if !ok {
|
||
|
return fmt.Errorf("Can't find iam role data source: %s", n)
|
||
|
}
|
||
|
|
||
|
_, ok = ds.Primary.Attributes["included_permissions.#"]
|
||
|
if !ok {
|
||
|
return errors.New("can't find 'included_permissions' attribute")
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func testAccCheckGoogleIamRoleConfig(name string) string {
|
||
|
return fmt.Sprintf(`
|
||
|
data "google_iam_role" "role" {
|
||
|
name = "%s"
|
||
|
}
|
||
|
`, name)
|
||
|
}
|