-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
1b59d16
commit be1e66c
Showing
7 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-datasource | ||
`google_app_engine_default_service_account` | ||
``` |
80 changes: 80 additions & 0 deletions
80
google/data_source_google_app_engine_default_service_account.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceGoogleAppEngineDefaultServiceAccount() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceGoogleAppEngineDefaultServiceAccountRead, | ||
Schema: map[string]*schema.Schema{ | ||
"project": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"email": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"unique_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"display_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceGoogleAppEngineDefaultServiceAccountRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
userAgent, err := generateUserAgentString(d, config.userAgent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
project, err := getProject(d, config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
serviceAccountEmail := fmt.Sprintf("%[email protected]", project) | ||
|
||
serviceAccountName, err := serviceAccountFQN(serviceAccountEmail, d, config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sa, err := config.NewIamClient(userAgent).Projects.ServiceAccounts.Get(serviceAccountName).Do() | ||
if err != nil { | ||
return handleNotFoundError(err, d, fmt.Sprintf("Service Account %q", serviceAccountName)) | ||
} | ||
|
||
d.SetId(sa.Name) | ||
if err := d.Set("email", sa.Email); err != nil { | ||
return fmt.Errorf("Error setting email: %s", err) | ||
} | ||
if err := d.Set("unique_id", sa.UniqueId); err != nil { | ||
return fmt.Errorf("Error setting unique_id: %s", err) | ||
} | ||
if err := d.Set("project", sa.ProjectId); err != nil { | ||
return fmt.Errorf("Error setting project: %s", err) | ||
} | ||
if err := d.Set("name", sa.Name); err != nil { | ||
return fmt.Errorf("Error setting name: %s", err) | ||
} | ||
if err := d.Set("display_name", sa.DisplayName); err != nil { | ||
return fmt.Errorf("Error setting display_name: %s", err) | ||
} | ||
|
||
return nil | ||
} |
34 changes: 34 additions & 0 deletions
34
google/data_source_google_app_engine_default_service_account_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package google | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceGoogleAppEngineDefaultServiceAccount_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
resourceName := "data.google_app_engine_default_service_account.default" | ||
|
||
vcrTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckGoogleAppEngineDefaultServiceAccount_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(resourceName, "id"), | ||
resource.TestCheckResourceAttrSet(resourceName, "email"), | ||
resource.TestCheckResourceAttrSet(resourceName, "unique_id"), | ||
resource.TestCheckResourceAttrSet(resourceName, "name"), | ||
resource.TestCheckResourceAttrSet(resourceName, "display_name"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccCheckGoogleAppEngineDefaultServiceAccount_basic = ` | ||
data "google_app_engine_default_service_account" "default" {} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
website/docs/d/app_engine_default_service_account.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
subcategory: "App Engine" | ||
layout: "google" | ||
page_title: "Google: google_app_engine_default_service_account" | ||
sidebar_current: "docs-google-datasource-app_engine-default-service-account" | ||
description: |- | ||
Retrieve the default App Engine service account used in this project | ||
--- | ||
|
||
# google\_app_engine\_default\_service\_account | ||
|
||
Use this data source to retrieve the default App Engine service account for the specified project. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "google_app_engine_default_service_account" "default" { | ||
} | ||
output "default_account" { | ||
value = data.google_app_engine_default_service_account.default.email | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `project` - (Optional) The project ID. If it is not provided, the provider project is used. | ||
|
||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `email` - Email address of the default service account used by App Engine in this project. | ||
|
||
* `unique_id` - The unique id of the service account. | ||
|
||
* `name` - The fully-qualified name of the service account. | ||
|
||
* `display_name` - The display name for the service account. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters