Skip to content

Datasource for GCE service account #1119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 12, 2018

Conversation

ishashchuk
Copy link
Contributor

@ishashchuk ishashchuk commented Feb 22, 2018

Fixes #1104


func dataSourceGoogleComputeDefaultServiceAccount() *schema.Resource {
return &schema.Resource{
Read: dataSourceGoogleComputeDefaultServiceAccountRead,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an optional project field to the schema? This way, users can find the default service account for projects that are not necessarily set as their default Terraform provider project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ready for another pass


The following attributes are exported:

* `id` - Email address of the default service account used by VMs running in this project
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a field named service_account in the schema instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that, but the data source itself is named data "google_compute_default_service_account". Does it make sense to add a field "service_account"? "google_compute_default_service_account.service_account" seems a little repetitive to me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danawillow what are your thoughts on this?

To give you some context. The DefaultServiceAccount is retrieved by calling the compute Project GET API. Our google_project data source is getting the project details from the resource manager GET API. The response does not include the DefaultServiceAccount.

I see different options:

  1. Create a google_compute_default_service_account resource (this PR). In that case, do we only set the id field or do we call the field a different name (e.g. service_account)?
  2. Create a new resource to get all the compute GET API project details. In addition to the DefaultServiceAccount, we can also get the quotas, enabledFeatures and commoninstancemetadata. But how do we call this data source since we already have one for the resource manager GET API called google_project?
  3. Make a call to the compute GET API in the project data source and include the data there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Interpolating based on ids isn't a good idea, since we've had many examples of changing ids for a resource over time. If we go with option one, then we should have it as a separate field even though it seems weird. In the google_service_account resource we have fields called email and account_id, so this one could match that.
  2. If we did this, we could call it google_compute_project or google_compute_project_info. I don't love either of those names, but metadata is a totally separate thing we can't call it that.
  3. The thing that makes me a bit nervous about this is that the info the compute projects resource returns is compute specific. For example, the quotas it returns are only the GCE quotas. I don't know if that will ever change.

Right now I'm leaning towards option 1 (and then just have separate data sources for each item in the project resources as needed), but could definitely be persuaded that option 2 is the way to go.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your input Dana :)

I am also leaning towards option 1. To be consistent with the google_service_account resource, we should add a new field called email and set the default service account email to this field.

In the future, if users ask for the default service account id, we can add a new field called account_id to this google_compute_default_service_account data source and extract this value from the email.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rosbo @danawillow thanks for you input. I agree that having those to be consistent is a better approach. commit with the requested changes is on its way.

Type: schema.TypeString,
Optional: true,
},
"project_id": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with all the other resource, could you rename this field "project"

return err
}

if v, ok := d.GetOk("project_id"); ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the getProject method checks first if the "project" field is set and then fallback on the default provider project. This means you won't need this check here.


The following arguments are supported:

* `project_id` - (Optional) The project ID. If it is not provided, the provider project is used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename here too.

@rosbo rosbo merged commit 2efa710 into hashicorp:master Mar 12, 2018
@rosbo
Copy link
Contributor

rosbo commented Mar 12, 2018

Merged! Thank you @ishashchuk for your contribution :)

@ishashchuk ishashchuk deleted the ishashchuk_gceServiceAccount branch March 12, 2018 17:08
ashish-amarnath pushed a commit to ashish-amarnath/terraform-provider-google that referenced this pull request Mar 20, 2018
* Data source for retrieving GCE service account
* Added project id for service account lookups (hashicorp#15)
* Renaming attribute project_id -> project
chrisst pushed a commit to chrisst/terraform-provider-google that referenced this pull request Nov 9, 2018
* Data source for retrieving GCE service account
* Added project id for service account lookups (#15)
* Renaming attribute project_id -> project
@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add default GCE account data source
3 participants