|
| 1 | +# Version Metadata Documentation |
| 2 | + |
| 3 | +This document explains how to add version requirements to resources and attributes in the terraform-provider-coder. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Version information is embedded directly in resource and attribute descriptions using special markers. The documentation generation process automatically extracts this information and formats it appropriately. |
| 8 | + |
| 9 | +## Adding Version Requirements |
| 10 | + |
| 11 | +### For Resources |
| 12 | + |
| 13 | +Add a version marker to the resource's `Description` field: |
| 14 | + |
| 15 | +```go |
| 16 | +Description: "Your resource description. @minCoderVersion:v2.21.0", |
| 17 | +``` |
| 18 | + |
| 19 | +The marker will be automatically removed from the generated docs and replaced with a formatted note. |
| 20 | + |
| 21 | +### For Attributes |
| 22 | + |
| 23 | +Add a version marker to the attribute's `Description` field: |
| 24 | + |
| 25 | +```go |
| 26 | +"my_attribute": { |
| 27 | + Type: schema.TypeString, |
| 28 | + Description: "Attribute description. @since:v2.16.0", |
| 29 | + Optional: true, |
| 30 | +}, |
| 31 | +``` |
| 32 | + |
| 33 | +This will result in the documentation showing: `- my_attribute (String) Attribute description. *(since v2.16.0)*` |
| 34 | + |
| 35 | +## Version Marker Formats |
| 36 | + |
| 37 | +You can use either format: |
| 38 | +- `@minCoderVersion:vX.Y.Z` - For resources |
| 39 | +- `@since:vX.Y.Z` - For attributes |
| 40 | + |
| 41 | +Both formats are recognized and processed the same way. |
| 42 | + |
| 43 | +## How It Works |
| 44 | + |
| 45 | +1. **During Development**: Add version markers to descriptions |
| 46 | +2. **During Doc Generation**: |
| 47 | + - `terraform-plugin-docs` generates initial documentation |
| 48 | + - Our custom `docsgen` script: |
| 49 | + - Extracts version information from descriptions |
| 50 | + - Adds formatted version notes to resources |
| 51 | + - Adds inline version markers to attributes |
| 52 | + - Cleans up the version patterns from descriptions |
| 53 | + |
| 54 | +## Examples |
| 55 | + |
| 56 | +### Resource Example |
| 57 | + |
| 58 | +```go |
| 59 | +func myNewResource() *schema.Resource { |
| 60 | + return &schema.Resource{ |
| 61 | + Description: "Manages a new Coder feature. @minCoderVersion:v2.25.0", |
| 62 | + // ... rest of resource definition |
| 63 | + } |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +Results in documentation with: |
| 68 | +```markdown |
| 69 | +# coder_my_new (Resource) |
| 70 | + |
| 71 | +Manages a new Coder feature. |
| 72 | + |
| 73 | +~> **Note:** This resource requires [Coder v2.25.0](https://github.com/coder/coder/releases/tag/v2.25.0) or later. |
| 74 | +``` |
| 75 | + |
| 76 | +### Attribute Example |
| 77 | + |
| 78 | +```go |
| 79 | +"advanced_option": { |
| 80 | + Type: schema.TypeBool, |
| 81 | + Description: "Enable advanced features. @since:v2.22.0", |
| 82 | + Optional: true, |
| 83 | +}, |
| 84 | +``` |
| 85 | + |
| 86 | +Results in documentation with: |
| 87 | +```markdown |
| 88 | +- `advanced_option` (Boolean) Enable advanced features. *(since v2.22.0)* |
| 89 | +``` |
| 90 | + |
| 91 | +## Default Versions |
| 92 | + |
| 93 | +- Resources without version markers default to `v2.18.0` (the base requirement) |
| 94 | +- Attributes without version markers don't show version information |
| 95 | +- Special resources have hardcoded defaults: |
| 96 | + - `coder_devcontainer`: v2.21.0 |
| 97 | + - `coder_ai_task`: v2.24.0 |
| 98 | + |
| 99 | +## Best Practices |
| 100 | + |
| 101 | +1. **Always add version markers** when creating new resources or attributes |
| 102 | +2. **Use semantic versioning** (vX.Y.Z format) |
| 103 | +3. **Test documentation generation** with `make gen` after adding markers |
| 104 | +4. **Keep descriptions concise** - the version marker is removed from the final docs |
0 commit comments