Skip to content

Commit e3fab9a

Browse files
SBGoodsbflad
andauthored
Strip Provider Prefix from File Names during Migration (#349)
* Add `--provider-name` flag to `migrate` subcommand and strip provider short name prefix during migration * Update README.md * Add changelog entries * Default the `--provider-name` flag to use the provider directory basename * Update .changes/unreleased/ENHANCEMENTS-20240327-160831.yaml Co-authored-by: Brian Flad <[email protected]> --------- Co-authored-by: Brian Flad <[email protected]>
1 parent 836a890 commit e3fab9a

File tree

7 files changed

+1980
-14
lines changed

7 files changed

+1980
-14
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: BUG FIXES
2+
body: 'migrate: fixed a bug where documentation files with provider name prefixes were
3+
migrated to templates directory as-is, causing `generate` to create duplicate templates'
4+
time: 2024-03-27T16:10:37.029568-04:00
5+
custom:
6+
Issue: "349"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: ENHANCEMENTS
2+
body: 'migrate: Added `--provider-name` flag to override the default provider name when any
3+
file names that contain provider name prefixes are removed during migration'
4+
time: 2024-03-27T16:08:31.541882-04:00
5+
custom:
6+
Issue: "349"

README.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Usage: tfplugindocs migrate [<args>]
9898
--examples-dir <ARG> examples directory based on provider-dir (default: "examples")
9999
--provider-dir <ARG> relative or absolute path to the root provider code directory when running the command outside the root provider code directory
100100
--templates-dir <ARG> new website templates directory based on provider-dir; files will be migrated to this directory (default: "templates")
101+
--provider-name <ARG> provider name, as used in Terraform configurations; this will default to provider-dir basename if not set
101102
```
102103
103104
### How it Works
@@ -175,23 +176,24 @@ ingress issues.
175176
176177
The `migrate` subcommand takes the following actions:
177178
1. Determines the rendered website directory based on the `--provider-dir` argument
178-
2. Copies the contents of the rendered website directory to the `--templates-dir` folder (will create this folder if it doesn't exist)
179-
3. (if the rendered website is using legacy format) Renames `docs/d/` and `docs/r/` subdirectories to `data-sources/` and `resources/` respectively
180-
4. Change file suffixes for Markdown files to `.md.tmpl` to create website templates
181-
5. Extracts code blocks from website docs to create individual example files in `--examples-dir` (will create this folder if it doesn't exist)
182-
6. Replace extracted example code in website templates with `codefile`/`tffile` template functions referencing the example files.
183-
7. Copies non-template files to `--templates-dir` folder
184-
8. Removes the `website/` directory
179+
2. Determines the provider name based on the `--provider-name` argument
180+
3. Copies the contents of the rendered website directory to the `--templates-dir` folder (will create this folder if it doesn't exist)
181+
4. (if the rendered website is using legacy format) Renames `docs/d/` and `docs/r/` subdirectories to `data-sources/` and `resources/` respectively
182+
5. Renames files in the `--templates-dir` folder to remove the provider shortname prefix from the file name
183+
6. Change file suffixes for Markdown files to `.md.tmpl` to create website templates
184+
7. Extracts code blocks from website docs to create individual example files in `--examples-dir` (will create this folder if it doesn't exist)
185+
8. Replace extracted example code in website templates with `codefile`/`tffile` template functions referencing the example files.
186+
9. Copies non-template files to `--templates-dir` folder
187+
10. Removes the `website/` directory
185188
186189
### Conventional Paths
187190
188191
The generation of missing documentation is based on a number of assumptions / conventional paths.
189192
190-
> **NOTE:** In the following conventional paths, `<data source name>` and `<resource name>` include the provider prefix as well, but the provider prefix is **NOT** included in`<function name>`.
191-
> For example, the data source [`caller_identity`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) in the `aws` provider would have an "example" conventional path of: `examples/data-sources/aws_caller_identity/data-source.tf`
192-
193193
For templates:
194194
195+
> **NOTE:** In the following conventional paths for templates, `<data source name>`, `<resource name>`, and `<function name>` do not include the provider prefix.
196+
195197
| Path | Description |
196198
|-------------------------------------------------------|----------------------------------------|
197199
| `templates/` | Root of templated docs |
@@ -207,6 +209,9 @@ Note: the `.tmpl` extension is necessary, for the file to be correctly handled a
207209
208210
For examples:
209211
212+
> **NOTE:** In the following conventional paths for examples, `<data source name>` and `<resource name>` include the provider prefix as well, but the provider prefix is **NOT** included in`<function name>`.
213+
> For example, the data source [`caller_identity`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) in the `aws` provider would have an "example" conventional path of: `examples/data-sources/aws_caller_identity/data-source.tf`
214+
210215
| Path | Description |
211216
|-----------------------------------------------------------|---------------------------------|
212217
| `examples/` | Root of examples |
@@ -220,6 +225,9 @@ For examples:
220225
221226
The `migrate` subcommand assumes the following conventional paths for the rendered website directory:
222227
228+
> **NOTE:** In the following conventional paths for templates, `<data source name>`, `<resource name>`, and `<function name>` do not include the provider prefix.
229+
> if the `--provider-name` argument is set, the provider prefix will be removed from the file names during migration.
230+
223231
Legacy website directory structure:
224232
225233
| Path | Description |

0 commit comments

Comments
 (0)