generated from deploymenttheory/Template
-
Notifications
You must be signed in to change notification settings - Fork 1
Fixed a variety of issues #5
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
Closed
marcusmarlowe0x
wants to merge
1
commit into
deploymenttheory:main
from
marcusmarlowe0x:working_commit
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
# Jamf Pro API Credentials | ||
JAMF_AUTH_METHOD=oauth2 | ||
JAMF_URL=https://your-instance.jamfcloud.com | ||
JAMF_CLIENT_ID=your-client-id | ||
JAMF_CLIENT_SECRET=your-client-secret |
This file contains hidden or 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This Readme skews the repo toward a single track execution path which is not the intended use. It's a library. |
This file contains hidden or 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 |
---|---|---|
@@ -1,89 +1,125 @@ | ||
# jamftf-python-terraform-importer | ||
# Jamf Pro Terraform Importer | ||
|
||
A Python-based utility to automate the import of existing Jamf Pro resources into Terraform state files. | ||
A Python tool to generate Terraform import blocks for existing Jamf Pro resources. | ||
|
||
## Overview | ||
|
||
Managing Jamf Pro resources with Terraform enhances reproducibility, version control, and automation. However, importing existing Jamf Pro resources into Terraform can be tedious and error-prone. This tool simplifies the process by: | ||
This tool connects to a Jamf Pro instance and generates Terraform import blocks for specified resources. It supports importing various Jamf Pro resources such as: | ||
|
||
- Connecting to your Jamf Pro tenant via the Classic API. | ||
- Fetching specified resources (e.g., scripts, policies, configuration profiles). | ||
- Generating Terraform import blocks for each resource. | ||
|
||
This facilitates a smoother transition to Infrastructure as Code (IaC) practices with Jamf Pro. | ||
|
||
## Features | ||
|
||
- Supports multiple Jamf Pro resource types. | ||
- Generates Terraform import blocks compatible with Terraform v1.5 and above. | ||
- Modular design for easy extension to additional resource types. | ||
- Command-line interface for straightforward operation. | ||
- Scripts | ||
- Categories | ||
- Policies | ||
- macOS Configuration Profiles | ||
- Static Computer Groups | ||
- Smart Computer Groups | ||
- Advanced Computer Searches | ||
- Computer Extension Attributes | ||
|
||
## Prerequisites | ||
|
||
- Python 3.7 or higher | ||
- Access to a Jamf Pro instance with appropriate API credentials | ||
- Terraform v1.5 or higher | ||
- Python 3.8 or higher | ||
- A Jamf Pro instance with API access | ||
- OAuth2 credentials (Client ID and Secret) for Jamf Pro API access | ||
|
||
## Installation | ||
|
||
1. Clone the repository: | ||
|
||
1. Clone this repository: | ||
```bash | ||
git clone https://github.com/deploymenttheory/jamftf-python-terraform-importer.git | ||
git clone https://github.com/yourusername/jamftf-python-terraform-importer.git | ||
cd jamftf-python-terraform-importer | ||
``` | ||
|
||
2. Install the required Python packages: | ||
2. Create and activate a virtual environment: | ||
```bash | ||
python -m venv env | ||
source env/bin/activate # On Windows: env\Scripts\activate | ||
``` | ||
|
||
3. Install the package in development mode: | ||
```bash | ||
pip install -r requirements.txt | ||
pip install -e . | ||
``` | ||
|
||
## Usage | ||
## Configuration | ||
|
||
1. Configure your Jamf Pro API credentials and desired resources using environment variables or a JSON config file like `import_config.json`: | ||
1. Create a `.env` file in the project root with your Jamf Pro credentials: | ||
```env | ||
JAMF_AUTH_METHOD=oauth2 | ||
JAMF_URL=https://your-instance.jamfcloud.com | ||
JAMF_CLIENT_ID=your-client-id | ||
JAMF_CLIENT_SECRET=your-client-secret | ||
``` | ||
|
||
2. Create an `import_config.json` file to specify which resources to import: | ||
```json | ||
{ | ||
"jamfpro_macos_configuration_profile_plist": true | ||
"scripts": true, | ||
"categories": true, | ||
"policies": true, | ||
"configuration_profiles": true, | ||
"computer_groups_static": true, | ||
"computer_groups_smart": true, | ||
"advanced_computer_searches": true, | ||
"computer_extension_attributes": true | ||
} | ||
``` | ||
|
||
2. Run the importer script: | ||
|
||
```bash | ||
python main.py | ||
``` | ||
|
||
This will generate Terraform import blocks for the selected resource types. | ||
|
||
3. Use the generated import blocks to import resources into Terraform state: | ||
|
||
```bash | ||
terraform import <resource_type>.<resource_name> <resource_id> | ||
``` | ||
|
||
## Supported Resources | ||
|
||
- Scripts | ||
- Policies | ||
- Configuration Profiles | ||
- Categories | ||
- Computer Groups (Static and Smart) | ||
- Advanced Computer Searches | ||
- Computer Extension Attributes | ||
|
||
Support for additional resource types can be added by extending the `Resource` class and implementing the `_get()` method. | ||
|
||
## Contributing | ||
## Usage | ||
|
||
Contributions are welcome! Please submit a pull request or open an issue to propose changes or enhancements. | ||
Run the importer with default settings: | ||
```bash | ||
python main.py | ||
``` | ||
|
||
### Command Line Options | ||
|
||
- `-c, --config`: Specify a different configuration file (default: `import_config.json`) | ||
- `-o, --output`: Write output to a file instead of stdout | ||
- `--env-file`: Specify a different `.env` file (default: `.env`) | ||
|
||
Example: | ||
```bash | ||
python main.py -c my_config.json -o import_blocks.tf | ||
``` | ||
|
||
## Output | ||
|
||
The tool generates Terraform import blocks in HCL format. Example output: | ||
```hcl | ||
import { | ||
to = jamfpro_computer_extension_attribute.apn_cert_uid1 | ||
id = "1" | ||
} | ||
resource "jamfpro_computer_extension_attribute" "apn_cert_uid1" { | ||
name = "APN Cert UID" | ||
} | ||
``` | ||
|
||
## Development | ||
|
||
### Project Structure | ||
|
||
``` | ||
jamftf/ | ||
├── __init__.py | ||
├── config_ingest.py # Configuration file handling | ||
├── constants.py # Constants and mappings | ||
├── dataclasses.py # Data structures | ||
├── enums.py # Enumerations | ||
├── exceptions.py # Custom exceptions | ||
├── hcl.py # HCL generation | ||
├── importer.py # Main importer logic | ||
├── models.py # Base resource models | ||
└── resources.py # Resource-specific implementations | ||
``` | ||
|
||
### Adding New Resource Types | ||
|
||
1. Add the resource type to `ProviderResourceTags` in `enums.py` | ||
2. Add the response key to `ResourceResponseKeys` in `enums.py` | ||
3. Create a new resource class in `resources.py` | ||
4. Add the resource to `RESOURCE_KEY_MAP` and `RESOURCE_TYPE_OBJECT_MAP` in `constants.py` | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. | ||
|
||
--- | ||
|
||
For more information and updates, visit the [GitHub repository](https://github.com/deploymenttheory/jamftf-python-terraform-importer). | ||
This project is licensed under the MIT License - see the LICENSE file for details. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be in a library or a CLI tool? |
This file contains hidden or 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,10 @@ | ||
{ | ||
"scripts": true, | ||
"policies": true, | ||
"configuration_profiles": true, | ||
"categories": true, | ||
"computer_groups_static": true, | ||
"computer_groups_smart": true, | ||
"advanced_computer_searches": true, | ||
"computer_extension_attributes": true | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
"""Storage for dataclases""" | ||
"""Storage for dataclasses.""" | ||
|
||
from dataclasses import dataclass | ||
|
||
@dataclass | ||
class SingleItem: | ||
"""Represents a single Jamf resource item.""" | ||
def __init__(self, resource_type, jpro_id): | ||
def __init__(self, resource_type, resource_name, jpro_id): | ||
self.resource_type = resource_type | ||
self.resource_name = resource_name | ||
self.jpro_id = jpro_id |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there terraform in the gitignore for a Python Library?