mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-09 03:28:29 +00:00
6121d539c2
Signed-off-by: Modular Magician <magic-modules@google.com>
67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package google
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func testAccCheckServiceAccountAccessTokenValue(name, value string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
ms := s.RootModule()
|
|
rs, ok := ms.Outputs[name]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", name)
|
|
}
|
|
|
|
// TODO: validate the token belongs to the service account
|
|
if rs.Value == "" {
|
|
return fmt.Errorf("%s Cannot be empty", name)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func TestAccDataSourceGoogleServiceAccountAccessToken_basic(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
resourceName := "data.google_service_account_access_token.default"
|
|
|
|
targetServiceAccountEmail := getTestServiceAccountFromEnv(t)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccCheckGoogleServiceAccountAccessToken_datasource(targetServiceAccountEmail),
|
|
Destroy: true,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
resource.TestCheckResourceAttr(resourceName, "target_service_account", targetServiceAccountEmail),
|
|
testAccCheckServiceAccountAccessTokenValue("access_token", targetServiceAccountEmail),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckGoogleServiceAccountAccessToken_datasource(targetServiceAccountID string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
data "google_service_account_access_token" "default" {
|
|
target_service_account = "%s"
|
|
scopes = ["userinfo-email", "https://www.googleapis.com/auth/cloud-platform"]
|
|
lifetime = "30s"
|
|
}
|
|
|
|
output "access_token" {
|
|
value = "${data.google_service_account_access_token.default.access_token}"
|
|
}
|
|
`, targetServiceAccountID)
|
|
}
|