Skip to content

Commit 9668009

Browse files
Add more regex filters to installation docsgen (#2421)
Rather than handling these in individual providers, they're best served here. Adds a few test cases to guard against any regression. - **Match TF mentions found in gitlab provider and add test cases** - **Add a header to skip as seen in hcloud**
1 parent cd77457 commit 9668009

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

pkg/tfgen/installation_docs.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,16 @@ func getDefaultHeadersToSkip() []*regexp.Regexp {
398398
regexp.MustCompile("[Dd]ebugging"),
399399
regexp.MustCompile("[Tt]erraform CLI"),
400400
regexp.MustCompile("[Tt]erraform Cloud"),
401+
regexp.MustCompile("Delete Protection"),
401402
}
402403
return defaultHeaderSkipRegexps
403404
}
404405

405406
func getTfVersionsToRemove() []*regexp.Regexp {
406407
tfVersionsToRemove := []*regexp.Regexp{
407-
regexp.MustCompile(`It requires [tT]erraform [v0-9]+\.?[0-9]?\.?[0-9]? or later.`),
408+
regexp.MustCompile(`(It|This provider) requires( at least)? [tT]erraform [v0-9]+\.?[0-9]?\.?[0-9]?( or later)?.`),
408409
regexp.MustCompile(`(?s)(For )?[tT]erraform [v0-9]+\.?[0-9]?\.?[0-9]? and (later|earlier):`),
410+
regexp.MustCompile(`A minimum of [tT]erraform [v0-9]+\.?[0-9]?\.?[0-9]? is recommended.`),
409411
}
410412
return tfVersionsToRemove
411413
}

pkg/tfgen/installation_docs_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,34 @@ func TestApplyEditRules(t *testing.T) {
278278
},
279279
expected: []byte("This is a provider with an example.\nUse this code."),
280280
},
281+
{
282+
name: "Strips mentions of Terraform version pattern 6",
283+
docFile: DocFile{
284+
Content: []byte("This provider requires at least Terraform 1.0."),
285+
},
286+
expected: []byte(""),
287+
},
288+
{
289+
name: "Strips mentions of Terraform version pattern 7",
290+
docFile: DocFile{
291+
Content: []byte("This provider requires Terraform 1.0."),
292+
},
293+
expected: []byte(""),
294+
},
295+
{
296+
name: "Strips mentions of Terraform version pattern 8",
297+
docFile: DocFile{
298+
Content: []byte("A minimum of Terraform 1.4.0 is recommended."),
299+
},
300+
expected: []byte(""),
301+
},
302+
{
303+
name: "Strips mentions of Terraform version With Surrounding Text",
304+
docFile: DocFile{
305+
Content: []byte(readfile(t, "test_data/replace-terraform-version/input.md")),
306+
},
307+
expected: []byte(readfile(t, "test_data/replace-terraform-version/expected.md")),
308+
},
281309
}
282310
for _, tt := range tests {
283311
tt := tt
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Use the GitLab provider to interact with GitLab resources, like
2+
users, groups, projects and more. You must configure the provider with
3+
the proper credentials before you can use it.
4+
5+
The provider uses the [`xanzy/go-gitlab`](https://github.com/xanzy/go-gitlab) library
6+
to interact with the [GitLab REST API](https://docs.gitlab.com/ee/api/api_resources.html).
7+
8+
Each data source and resource references the appropriate upstream GitLab REST API documentation,
9+
which may be consumed to better understand the behavior of the API.
10+
11+
Use the navigation to the left to read about the valid data sources and resources.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Use the GitLab provider to interact with GitLab resources, like
2+
users, groups, projects and more. You must configure the provider with
3+
the proper credentials before you can use it.
4+
5+
The provider uses the [`xanzy/go-gitlab`](https://github.com/xanzy/go-gitlab) library
6+
to interact with the [GitLab REST API](https://docs.gitlab.com/ee/api/api_resources.html).
7+
8+
This provider requires Terraform 1.0.
9+
10+
Each data source and resource references the appropriate upstream GitLab REST API documentation,
11+
which may be consumed to better understand the behavior of the API.
12+
13+
Use the navigation to the left to read about the valid data sources and resources.
14+
15+
This provider requires at least [Terraform 1.0](https://www.terraform.io/downloads.html).
16+
A minimum of Terraform 1.4.0 is recommended.

0 commit comments

Comments
 (0)