Skip to content

Conversation

@shannonxtreme
Copy link
Contributor

@shannonxtreme shannonxtreme commented Jun 19, 2025

Description

Fixed #754

Add docs samples for creating a custom IAM service account that has the least-privilege role for GKE nodes.

  • Add a standalone sample for creating a service account and assigning the role
  • Add a sample for Autopilot to create the account, grant the role, and create a cluster
  • Fix Standard regional node pool sample to correctly grant the role. The previous version created a service account with no roles and used it in the node pool (which would lead to errors).

Checklist

Readiness

  • Yes, merge this PR after it is approved

Style

Testing

Intended location

API enablement

  • If the sample needs an API enabled to pass testing, I have added the service to the Test setup file

Review

  • If this sample adds a new directory, I have added codeowners to the CODEOWNERS file

@shannonxtreme shannonxtreme requested review from a team as code owners June 19, 2025 18:52
@snippet-bot
Copy link

snippet-bot bot commented Jun 19, 2025

Here is the summary of changes.

You are about to add 4 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@shannonxtreme shannonxtreme changed the title Add sample for custom node service accounts [feat]: Add sample for custom node service account Jun 19, 2025
@apeabody
Copy link
Contributor

/gcbrun

@apeabody apeabody changed the title [feat]: Add sample for custom node service account feat: Add sample for custom node service account Jun 20, 2025
Copy link
Contributor

@apeabody apeabody left a comment

Choose a reason for hiding this comment

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

Thanks @shannonxtreme!

Copy link
Contributor

@glasnt glasnt left a comment

Choose a reason for hiding this comment

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

There are some issues with your PR, comments below.

Also: if you're going to rebase, reword your commit to start with feat: to solve the coventional commit error

@apeabody
Copy link
Contributor

/gcbrun

1 similar comment
@apeabody
Copy link
Contributor

/gcbrun

@apeabody
Copy link
Contributor

/gcbrun

@shannonxtreme
Copy link
Contributor Author

Oh I should probably rebase and squash

@shannonxtreme shannonxtreme force-pushed the main branch 2 times, most recently from 182b76f to 19b95dd Compare June 24, 2025 15:04
@apeabody
Copy link
Contributor

/gcbrun

Copy link
Contributor

@apeabody apeabody left a comment

Choose a reason for hiding this comment

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

Thanks @shannonxtreme! All the tests are now passing!

During final review I believe there is an opportunity to consolidate/deduplicate by adding the required region tags to gke/autopilot/custom_service_account/main.tf and dropping the gke/node_service_account/main.tf file?

@shannonxtreme
Copy link
Contributor Author

@apeabody the reason I made it a separate file is because creating the least privilege service account is a standalone task that's applicable both Standard and Autopilot clusters (and to standard node pools). It'd feel less correct to include this region in the autopilot cluster create file in, for example, the gke hardening guide. Wdyt?

@apeabody
Copy link
Contributor

@apeabody the reason I made it a separate file is because creating the least privilege service account is a standalone task that's applicable both Standard and Autopilot clusters (and to standard node pools). It'd feel less correct to include this region in the autopilot cluster create file in, for example, the gke hardening guide. Wdyt?

Thanks @shannonxtreme! I know we've done it in the past, but lets check with @glasnt on any best practice?

@glasnt
Copy link
Contributor

glasnt commented Jun 25, 2025

@apeabody the reason I made it a separate file is because creating the least privilege service account is a standalone task that's applicable both Standard and Autopilot clusters (and to standard node pools). It'd feel less correct to include this region in the autopilot cluster create file in, for example, the gke hardening guide. Wdyt?

Thanks @shannonxtreme! I know we've done it in the past, but lets check with @glasnt on any best practice?

The way region tags work is that you can have one file with multiple different sections marked within a region tag for inclusion in the documentation.

So in this case, you can wrap the service account creation section separately from the cluster declaration, so you can have this code embedded in separate steps of your documentation.

If you have the service account in both the standard and autopilot cluster files, you can wrap it in region tags (like Andrew's suggest changes), and embed each part for each cluster type in context.

Since that code is already defined, there's no reason to repeat the code in an isolated sample, when you can just re-use the region tag from another sample. Now I can see where if you wanted to show how to show the creation in a page not specific to a cluster type you may want a separate example, but given the code is identical I think it's more correct to reuse the code from one of the cluster types, if it can apply to both.

Note that region tags must be unique per repo, so some of Andrew's suggested comments will only be valid if the duplicate file is deleted, but reusing code through region tags is best practice 👍

@glasnt glasnt added the waiting-response Waiting for issue author to respond. label Jul 3, 2025
@shannonxtreme
Copy link
Contributor Author

Makes sense @glasnt, I'll make those changes soon.

Out of scope, but curious: would a standalone service account sample have made more sense in the iam directory with placeholders for the service account ID and role name?

@glasnt
Copy link
Contributor

glasnt commented Jul 14, 2025

Out of scope, but curious: would a standalone service account sample have made more sense in the iam directory with placeholders for the service account ID and role name?

Yup! You're welcome to reuse create_service_agent that already exists (currently used in docs), but it looks like it's a bit context-specific. You could also link to this docs page showing this code. We could also create a simpler example explicitly for re-use like this.

@shannonxtreme shannonxtreme force-pushed the main branch 2 times, most recently from 5c9c3e9 to 6cf0db6 Compare July 18, 2025 17:54
@shannonxtreme
Copy link
Contributor Author

Removed the standalone directory and added a region tag to the sample in autopilot/

@apeabody
Copy link
Contributor

/gcbrun

@glasnt glasnt merged commit 0bfb7ef into terraform-google-modules:main Jul 20, 2025
5 checks passed
niharika-98 pushed a commit to niharika-98/terraform-docs-samples that referenced this pull request Sep 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-response Waiting for issue author to respond.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New sample requests: Create an IAM service account and grant it a role

3 participants