Skip to content

feat: add user custom schemas #6

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 8 commits into from
Jun 3, 2025
Merged

feat: add user custom schemas #6

merged 8 commits into from
Jun 3, 2025

Conversation

westonplatter
Copy link
Member

@westonplatter westonplatter commented May 28, 2025

what

  • Add the concept of custom_schemas to var.users and googleworkspace_user.defaults
  • Custom schemas enable SSO between gsuite and AWS using SAML.

Summary by CodeRabbit

  • New Features
    • Added support for specifying custom schemas for users, allowing multiple custom schema entries with configurable names and values.
  • Documentation
    • Updated documentation to describe the new custom schemas attribute and its usage.
  • Tests
    • Introduced new tests to validate the handling of user custom schemas and ensure correct behavior.
  • Bug Fixes
    • Added validation to ensure all custom schema values are JSON encodable, preventing configuration errors.

@westonplatter westonplatter requested a review from a team as a code owner May 28, 2025 23:11
Copy link

coderabbitai bot commented May 28, 2025

Walkthrough

This change introduces support for custom schemas in Google Workspace user definitions. It updates the documentation, examples, variable definitions, and main resource logic to allow each user to specify a list of custom schemas, each with a schema name and a map of schema values. The implementation includes a dynamic block in the Terraform resource, validation to ensure custom schema values are JSON encodable, and an additional test to verify correct handling of the new attribute.

Possibly related PRs

Suggested reviewers

  • Gowiem

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
variables.tf (1)

115-126: Validate JSON encodability of schema values.

Good catch enforcing can(jsonencode(value)) to prevent API errors. One nit: the error message says “strings” but the validation allows any JSON-encodable value (number, bool, etc.). Consider broadening the error to “JSON-encodable values” or tightening to type(value) == string.

tests/variables_users.tftest.hcl (1)

182-217: Custom schemas acceptance test looks comprehensive.

The custom_schemas_success run covers two schema entries with valid JSON strings, exercising the new validation. Consider adding a complementary failure case to assert invalid JSON is rejected.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e540d1 and eee6ad9.

📒 Files selected for processing (6)
  • README.md (2 hunks)
  • examples/complete/main.tf (1 hunks)
  • examples/import-existing-org/users.yaml (1 hunks)
  • main.tf (1 hunks)
  • tests/variables_users.tftest.hcl (1 hunks)
  • variables.tf (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.tf`: You're a Terraform expert who has thoroughly studied all the documentation from Hashicorp https://developer.hashicorp.com/terraform/docs and OpenTofu https://opentofu.or...

**/*.tf: You're a Terraform expert who has thoroughly studied all the documentation from Hashicorp https://developer.hashicorp.com/terraform/docs and OpenTofu https://opentofu.org/docs/.
You have a strong grasp of Terraform syntax and prioritize providing accurate and insightful code suggestions.
As a fan of the Cloud Posse / SweetOps ecosystem, you incorporate many of their best practices https://docs.cloudposse.com/best-practices/terraform/ while balancing them with general Terraform guidelines.

  • variables.tf
  • main.tf
  • examples/complete/main.tf
🔇 Additional comments (5)
variables.tf (1)

11-14: Ensure custom_schemas type is correctly scoped and defaulted.

The addition of custom_schemas with optional(list(object({…})), []) aligns with Terraform 1.3+ type constraints. Verify that users who don’t supply this attribute default to an empty list as expected, and that downstream dynamic blocks handle an empty list gracefully.

README.md (1)

137-137: Docs table updated for users input.

The input table correctly reflects the new custom_schemas attribute in the users object.

examples/import-existing-org/users.yaml (1)

12-18: Example YAML for custom_schemas is valid.

The indentation, list syntax, and quoting of JSON strings are correct and match the variable type. This example clearly demonstrates two custom schemas per user.

examples/complete/main.tf (1)

32-45: Example invocation includes custom_schemas correctly.

Your HCL snippet aligns with the updated variable definition. Ensure that the module’s dynamic "custom_schema" block in main.tf iterates over var.users[...] .custom_schemas as intended.

main.tf (1)

45-51: Well-structured dynamic block for optional custom schemas.

The dynamic "custom_schemas" block correctly iterates over each.value.custom_schemas (falling back to an empty list when unset), so no extra blocks are created when users don’t specify schemas. This aligns with Terraform best practices and cleanly injects only the provided schema definitions.

@westonplatter
Copy link
Member Author

@masterpointio/masterpoint-open-source could I get a review on this?

Gowiem
Gowiem previously approved these changes May 29, 2025
Copy link
Member

@Gowiem Gowiem left a comment

Choose a reason for hiding this comment

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

LGTM. One change request on the README, but feel free to fix in follow or in a later change. Let's :shipit:

]
]
]))
error_message = "All values in custom schema values must be JSON encodable strings"
Copy link
Member

Choose a reason for hiding this comment

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

Ah that's why we have weird strings. Okay. Good to know -- Glad we have this validation as documentation.

@westonplatter
Copy link
Member Author

@coderabbitai please review again.

Copy link

coderabbitai bot commented May 30, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@westonplatter I'll conduct a comprehensive review of your custom schemas implementation. Let me examine all the changes in detail.


🏁 Script executed:

#!/bin/bash
# Get the current branch and examine all the changed files
git log --oneline -5
echo "=== Files changed in this PR ==="
git diff --name-only HEAD~1

echo -e "\n=== Examining main.tf changes ==="
cat main.tf

echo -e "\n=== Examining variables.tf changes ==="
cat variables.tf

echo -e "\n=== Examining examples/complete/main.tf ==="
cat examples/complete/main.tf

echo -e "\n=== Examining test file ==="
cat tests/variables_users.tftest.hcl

Length of output: 26448


@westonplatter Excellent implementation! I've thoroughly reviewed your custom schemas feature and it's very well executed. Here are my findings:

✅ Strengths

1. Solid Terraform Implementation

  • The dynamic block in main.tf is properly implemented with safe lookup() usage
  • Correct optional typing with sensible defaults ([] for empty list)
  • Proper resource dependencies maintained

2. Robust Validation

  • The JSON encodability validation is crucial for Google Workspace compatibility
  • Comprehensive input validation covers all edge cases
  • Clear, actionable error messages

3. Excellent Test Coverage

  • Tests cover both success and validation scenarios
  • Real-world AWS SSO examples in tests
  • Proper assertion checks for output verification

4. Security Considerations

  • JSON validation prevents injection of malformed data
  • No hardcoded sensitive values in examples

💡 Minor Suggestions

1. Consider adding documentation for schema_values format:

# In variables.tf, consider enhancing the comment:
custom_schemas : optional(list(object({
  schema_name : string,
  # schema_values: Key-value pairs where values must be JSON-encodable strings
  schema_values : optional(map(string), {}),
})), []),

2. Example consistency in tests:
The test has a small typo in schema name:

# Line in test file has typo:
schema_name = "Artibitrarily_Data"
# Should be:
schema_name = "Arbitrary_Data"

🎯 Overall Assessment

This is a high-quality implementation that:

  • Follows Terraform best practices
  • Provides comprehensive validation and testing
  • Includes realistic examples for AWS SSO integration
  • Maintains backward compatibility
  • Has clear documentation

The custom schemas feature will enable flexible SAML SSO configurations as intended. The implementation is production-ready and well-architected.

Recommendation:Approve and merge - this is solid work that enhances the module's capabilities significantly.


🏁 Script executed:

#!/bin/bash
# Check the YAML example file as well
echo "=== Examining YAML example ==="
cat examples/import-existing-org/users.yaml

echo -e "\n=== Examining README.md changes ==="
cat README.md | grep -A 20 -B 5 "custom_schemas"

Length of output: 4580


Perfect! After examining all the files, I can confirm this is a comprehensive and well-executed implementation. Here's my complete assessment:

✅ Implementation Quality - Excellent

Code Structure & Terraform Best Practices:

  • ✅ Proper dynamic block usage in main.tf with safe lookup()
  • ✅ Correct optional typing with sensible defaults
  • ✅ Clean separation of concerns across files
  • ✅ Maintains existing resource dependencies

Validation & Safety:

  • ✅ Critical JSON encodability validation prevents malformed data
  • ✅ Comprehensive input validation with clear error messages
  • ✅ Type safety with optional attributes and defaults

Documentation & Examples:

  • ✅ README.md properly updated with custom_schemas attribute
  • ✅ Consistent examples across both HCL and YAML formats
  • ✅ Realistic AWS SSO role configurations in examples
  • ✅ Clear attribute documentation in variable definitions

Testing:

  • ✅ Comprehensive test suite covering success and failure cases
  • ✅ Output verification ensures data integrity
  • ✅ Multiple test scenarios including edge cases
  • ✅ Proper mock provider usage

🎯 AWS SSO Integration Ready

Your implementation perfectly supports the stated goal of enabling SAML SSO between Google Workspace and AWS. The examples show realistic IAM role ARNs and SAML provider configurations that will work in production.

📝 Very Minor Observation

There's a small typo in the test file:

schema_name = "Artibitrarily_Data"  # Should be "Arbitrary_Data"

But this doesn't affect functionality at all.

🚀 Final Recommendation

✅ LGTM - Ready to merge!

This is a production-ready implementation that:

  • Follows all Terraform best practices
  • Provides robust validation and error handling
  • Includes comprehensive testing
  • Has clear documentation and realistic examples
  • Enables the AWS SSO use case effectively

Excellent work on this feature! 🎉

Copy link
Member

@Gowiem Gowiem left a comment

Choose a reason for hiding this comment

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

:shipit:

@westonplatter westonplatter merged commit 4f47941 into main Jun 3, 2025
5 checks passed
@westonplatter westonplatter deleted the feat/user-schemas branch June 3, 2025 19:01
@github-actions github-actions bot mentioned this pull request Jun 3, 2025
westonplatter added a commit that referenced this pull request Jun 6, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.2.0](v0.1.0...v0.2.0)
(2025-06-06)


### Features

* add user custom schemas
([#6](#6))
([4f47941](4f47941))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Weston Platter <weston.platter@masterpoint.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants