-
Notifications
You must be signed in to change notification settings - Fork 1
Add comprehensive Copilot instructions for meshStack Terraform Provider #50
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
base: main
Are you sure you want to change the base?
Changes from all commits
62fa347
32d319f
b984420
7a5696d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# Copilot Instructions for meshStack Terraform Provider | ||
|
||
## Repository Overview | ||
|
||
This is the official **meshStack Terraform Provider** developed by meshcloud GmbH. It enables Infrastructure as Code (IaC) management of meshStack resources through Terraform by integrating with the meshStack meshObject API. | ||
|
||
**Key Information:** | ||
- **Purpose**: Manage meshStack cloud resources (projects, workspaces, tenants, building blocks, etc.) using Terraform | ||
- **API Integration**: Uses the meshStack meshObject API (`/api/meshobjects` endpoints) | ||
- **API Documentation**: https://docs.dev.meshcloud.io/api/index.html#mesh_objects | ||
- **Provider Registry**: https://registry.terraform.io/providers/meshcloud/meshstack/latest/docs | ||
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. d: we also publish to opentofu registry |
||
- **License**: MPL-2.0 | ||
|
||
## Architecture Overview | ||
|
||
This provider follows the standard Terraform Provider Plugin Framework pattern: | ||
|
||
``` | ||
├── main.go # Provider entry point | ||
├── internal/provider/ # Provider implementation (resources, data sources) | ||
├── client/ # API client for meshStack meshObject API | ||
├── docs/ # Terraform registry documentation | ||
├── examples/ # Example Terraform configurations | ||
└── templates/ # Documentation templates | ||
``` | ||
|
||
### API Authentication | ||
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. d: not sure if this is wasted context (auth is already codified in the provider) 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. a more useful explanation here would be the key concept of workspace and that most resources live in a workspace, and that API tokens are also usually scoped to a single workspace |
||
The provider authenticates with meshStack using: | ||
- `endpoint`: meshStack API URL (e.g., `https://api.my.meshstack.io`) | ||
- `apikey` & `apisecret`: API credentials for meshStack | ||
- Environment variables: `MESHSTACK_ENDPOINT`, `MESHSTACK_API_KEY`, `MESHSTACK_API_SECRET` | ||
|
||
## Directory Structure | ||
|
||
### `/internal/provider/` | ||
Contains all Terraform provider implementation: | ||
- **`provider.go`**: Main provider configuration and setup | ||
- **`*_resource.go`**: Resource implementations (Create, Read, Update, Delete) | ||
- **`*_data_source.go`**: Data source implementations (Read-only) | ||
- **Pattern**: Each meshObject type has separate resource and data source files | ||
|
||
### `/client/` | ||
meshStack API client implementation: | ||
- **`client.go`**: Core HTTP client with authentication | ||
- **`*.go`**: Individual API client methods for each resource type | ||
- **Authentication**: JWT token-based with automatic refresh | ||
- **API Base Path**: `/api/meshobjects` | ||
|
||
### `/docs/` | ||
Terraform registry documentation (auto-generated): | ||
- **`index.md`**: Provider documentation | ||
- **`resources/`**: Resource documentation | ||
- **`data-sources/`**: Data source documentation | ||
|
||
### `/examples/` | ||
Example Terraform configurations for testing and documentation | ||
|
||
## Development Patterns | ||
|
||
### Resource Implementation Pattern | ||
Each resource follows this structure: | ||
```go | ||
type resourceName struct { | ||
client *client.MeshStackProviderClient | ||
} | ||
|
||
// Standard Terraform resource interface methods: | ||
func (r *resourceName) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) | ||
func (r *resourceName) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) | ||
func (r *resourceName) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) | ||
func (r *resourceName) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) | ||
func (r *resourceName) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) | ||
``` | ||
|
||
### API Client Pattern | ||
API clients follow RESTful patterns: | ||
```go | ||
func (c *MeshStackProviderClient) CreateResource(resource ResourceType) (*ResourceType, error) | ||
func (c *MeshStackProviderClient) ReadResource(id string) (*ResourceType, error) | ||
func (c *MeshStackProviderClient) UpdateResource(resource ResourceType) (*ResourceType, error) | ||
func (c *MeshStackProviderClient) DeleteResource(id string) error | ||
``` | ||
|
||
### Schema Patterns | ||
Resources use consistent schema structures: | ||
- `api_version` - meshObject API version | ||
- `kind` - meshObject type (e.g., "meshProject", "meshWorkspace") | ||
- `metadata` - Object metadata (name, uuid, timestamps, etc.) | ||
- `spec` - Object specification (user-defined configuration) | ||
- `status` - Object status (system-managed state) | ||
|
||
## Common Development Tasks | ||
|
||
### Adding a New Resource | ||
1. Create `*_resource.go` in `/internal/provider/` | ||
2. Implement the resource interface (Create, Read, Update, Delete, Schema) | ||
3. Add API client methods in `/client/` | ||
4. Register resource in `provider.go` | ||
5. Create example in `/examples/resources/*/` | ||
6. Run `go generate` to update documentation | ||
|
||
### meshObject API Integration | ||
- All resources are meshObjects with standard structure | ||
- Use consistent error handling and HTTP status checking | ||
- Implement proper authentication token refresh | ||
- Follow meshStack API conventions for CRUD operations | ||
|
||
## Key Dependencies | ||
|
||
- **Terraform Plugin Framework**: Latest stable version for provider development | ||
- **Standard Library**: HTTP client, JSON marshaling, context handling | ||
- **meshStack API**: RESTful API following meshObject patterns |
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.