-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
157 additions
and
15 deletions.
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,138 @@ | ||
| # sso-create-sc-group.py | ||
|
|
||
| ## Problem | ||
|
|
||
| ## Requirements | ||
|
|
||
| * **Python 3.x** | ||
| * **Jinja2** library | ||
|
|
||
| ## Installation | ||
|
|
||
| 1. **Clone or copy** the script `sso-create-sc-group.py` to your working directory. | ||
| 2. **Install Dependencies**: | ||
| ```bash | ||
| pip install jinja2 | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| 3. **Make Executable**: | ||
| ```bash | ||
| chmod +x sso-create-sc-group.py | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| 4. **Prepare Templates**: Ensure a directory named `TEMPLATE/` exists in the same folder as the script. | ||
|
|
||
| ## How It Works | ||
|
|
||
| The script automates the creation of service control groups by processing a template directory and generating a new, standardized folder. | ||
|
|
||
| ### 1. Naming Convention | ||
|
|
||
| The target directory name (`created_group`) is constructed as follows: | ||
|
|
||
| * **Format**: `{business_label}-{application_label}-{group}` | ||
| * **Format (no app label)**: `{business_label}-{group}` | ||
| * **Case**: The `group` and the final `created_group` name are automatically converted to **lowercase**. | ||
|
|
||
| ### 2. File Processing Logic | ||
|
|
||
| The script iterates through every file in the `TEMPLATE/` directory: | ||
|
|
||
| * **Jinja2 Templates (`.j2`)**: Any file ending in `.j2` is rendered using the Jinja2 engine. The literal string `GROUP` in the filename is replaced by the `created_group` name. | ||
| * **Static Files**: All other files are copied directly into the new directory without modification. | ||
|
|
||
| ### 3. Template Variables | ||
|
|
||
| The following variables are exposed to Jinja2 and can be used in your templates via `{{ variable_name }}`: | ||
|
|
||
| | Variable | Description | | ||
| | --- | --- | | ||
| | `business_label` | The value provided via `-b` | | ||
| | `application_label` | The value provided via `-a` (if any) | | ||
| | `group` | The group name (provided via `-g` or the current folder name) | | ||
| | `created_group` | The final computed lowercase name of the directory | | ||
| | `description` | The text provided via `-d` | | ||
|
|
||
| ## Usage Examples | ||
|
|
||
| **Basic Usage** (uses current directory name as group): | ||
|
|
||
| ```bash | ||
| ./sso-create-sc-group.py -b fin -d "Financial audit logs" | ||
|
|
||
| ``` | ||
|
|
||
| **Full Specification**: | ||
|
|
||
| ```bash | ||
| ./sso-create-sc-group.py -b mkt -a email -g subscribers -d "Marketing email list" | ||
|
|
||
| ``` | ||
|
|
||
| **Overwrite Existing**: | ||
|
|
||
| ```bash | ||
| ./sso-create-sc-group.py -b fin -g audit -f | ||
|
|
||
| ``` | ||
|
|
||
| ## Template Variables | ||
|
|
||
| You can now use these metadata variables in your templates (e.g., in a file header): | ||
|
|
||
| | Variable | Description | | ||
| | --- | --- | | ||
| | `script_name` | The name of the script (`sso-create-sc-group.py`) | | ||
| | `version` | The current script version (e.g., `1.0.5`) | | ||
| | `created_time` | Timestamp of execution (`YYYY-MM-DD HH:MM:SS`) | | ||
|
|
||
| **Example usage in `TEMPLATE/GROUP.tf.j2`:** | ||
|
|
||
| ```hcl | ||
| # Generated by {{ script_name }} v{{ version }} | ||
| # Created at: {{ created_time }} | ||
| # Description: {{ description }} | ||
| resource "aws_identitystore_group" "this" { | ||
| display_name = "{{ created_group }}" | ||
| } | ||
| ``` | ||
|
|
||
| ## CHANGELOG | ||
|
|
||
| ### v1.0.5 | ||
|
|
||
| * Added `script_name`, `version`, and `created_time` to the Jinja2 render context for better file auditing/header generation. | ||
|
|
||
|
|
||
| ### v1.0.4 | ||
|
|
||
| * Added `--description` (`-d`) argument and exposed it to Jinja2 context. | ||
| * Added a startup banner displaying the script name, version, and target group. | ||
|
|
||
| ### v1.0.3 | ||
|
|
||
| * Added directory existence validation. | ||
| * Implemented `--force` (`-f`) flag to allow overwriting of existing directories. | ||
| * Added `sys.exit(1)` on errors for better CI/CD integration. | ||
|
|
||
| ### v1.0.2 | ||
|
|
||
| * Enforced lowercase normalization for the `group` name and the final `created_group` name. | ||
|
|
||
| ### v1.0.1 | ||
|
|
||
| * Added `#!/usr/bin/env python` shebang for direct execution. | ||
| * Exposed `business_label`, `application_label`, `group`, and `created_group` as variables to the Jinja2 engine. | ||
|
|
||
| ### v1.0.0 | ||
|
|
||
| * Initial release. | ||
| * Basic CLI argument parsing (`-b`, `-a`, `-g`). | ||
| * Template rendering logic for `.j2` files and static file copying. | ||
|
|
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