Skip to content

Commit

Permalink
Add a few more patterns to match for GCP
Browse files Browse the repository at this point in the history
  • Loading branch information
guineveresaenger committed Apr 19, 2024
1 parent 1a8446c commit 992353c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/tfgen/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,13 @@ var nestedObjectRegexps = []*regexp.Regexp{
// sql_database_instance.html.markdown:
// "The optional `settings.ip_configuration.authorized_networks[]`` sublist supports:"
regexp.MustCompile("`([a-zA-Z_.\\[\\]]+)`.*supports:"),

// For example when blocks/subblocks/sublists are defined across more than one line
// sql_database_instance.html.markdown:
//"The optional `settings.maintenance_window` subblock for instances declares a one-hour"
regexp.MustCompile("The .* `([a-zA-Z_.\\[\\]]+)` sublist .*"),
regexp.MustCompile("The .* `([a-zA-Z_.\\[\\]]+)` subblock .*"),
regexp.MustCompile("The .* `([a-zA-Z_.\\[\\]]+)` block .*"),
}

// getMultipleNestedBlockNames is called when we detect that a resource matches the "`([a-z_0-9]+)`.*following" regex.
Expand Down
64 changes: 64 additions & 0 deletions pkg/tfgen/docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,70 @@ func TestArgumentRegex(t *testing.T) {
},
},
},
{
input: []string{
"The optional `settings.location_preference` subblock supports:",
"",
"* `follow_gae_application` - (Optional) A GAE application whose zone to remain",
"in. Must be in the same region as this instance.",
"",
"* `zone` - (Optional) The preferred compute engine",
"[zone](https://cloud.google.com/compute/docs/zones?hl=en).",
"",
"The optional `settings.maintenance_window` subblock for instances declares a one-hour",
"[maintenance window](https://cloud.google.com/sql/docs/instance-settings?hl=en#maintenance-window-2ndgen)",
"when an Instance can automatically restart to apply updates. The maintenance window is specified in UTC time. It supports:",
"",
"* `day` - (Optional) Day of week (`1-7`), starting on Monday",
"",
"* `hour` - (Optional) Hour of day (`0-23`), ignored if `day` not set",
"",
"* `update_track` - (Optional) Receive updates earlier (`canary`) or later",
},
expected: map[docsPath]*argumentDocs{
"settings.location_preference.follow_gae_application": {description: "A GAE application whose zone to remain\nin. Must be in the same region as this instance."},
"settings.location_preference.zone": {description: "The preferred compute engine\n[zone](https://cloud.google.com/compute/docs/zones?hl=en)."},
"settings.maintenance_window.day": {description: "Day of week (`1-7`), starting on Monday"},
"settings.maintenance_window.hour": {description: "Hour of day (`0-23`), ignored if `day` not set"},
"settings.maintenance_window.update_track": {description: "Receive updates earlier (`canary`) or later"},
},
},
{
input: []string{
"The optional `settings.location_preference` subblock supports:",
"",
"* `follow_gae_application` - (Optional) A GAE application whose zone to remain",
"in. Must be in the same region as this instance.",
"",
"The optional `settings.maintenance_window` block for instances declares a one-hour",
"[maintenance window](https://cloud.google.com/sql/docs/instance-settings?hl=en#maintenance-window-2ndgen)",
"when an Instance can automatically restart to apply updates. The maintenance window is specified in UTC time. It supports:",
"",
"* `day` - (Optional) Day of week (`1-7`), starting on Monday",
},
expected: map[docsPath]*argumentDocs{
"settings.location_preference.follow_gae_application": {description: "A GAE application whose zone to remain\nin. Must be in the same region as this instance."},
"settings.maintenance_window.day": {description: "Day of week (`1-7`), starting on Monday"},
},
},
{
input: []string{
"The optional `settings.location_preference` subblock supports:",
"",
"* `follow_gae_application` - (Optional) A GAE application whose zone to remain",
"in. Must be in the same region as this instance.",
"",
"The optional `settings.maintenance_window` sublist for instances declares a one-hour",
"[maintenance window](https://cloud.google.com/sql/docs/instance-settings?hl=en#maintenance-window-2ndgen)",
"when an Instance can automatically restart to apply updates. The maintenance window is specified in UTC time. It supports:",
"",
"* `day` - (Optional) Day of week (`1-7`), starting on Monday",
},
expected: map[docsPath]*argumentDocs{
"settings.location_preference.follow_gae_application": {description: "A GAE application whose zone to remain\nin. Must be in the same region as this instance."},
"settings.maintenance_window.day": {description: "Day of week (`1-7`), starting on Monday"},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 992353c

Please sign in to comment.