Skip to content

Commit

Permalink
Add override for docs sections - apply to compute and monitoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
nat-henderson committed Sep 30, 2021
1 parent dc1fe2b commit dbc4172
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 3 deletions.
5 changes: 3 additions & 2 deletions tpgtools/override.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ type OverrideType string // enum

// Product-level Overrides
const (
ProductBasePath OverrideType = "PRODUCT_BASE_PATH"
ProductTitle OverrideType = "PRODUCT_TITLE"
ProductBasePath OverrideType = "PRODUCT_BASE_PATH"
ProductTitle OverrideType = "PRODUCT_TITLE"
ProductDocsSection OverrideType = "PRODUCT_DOCS_SECTION"
)

// Resource-level Overrides
Expand Down
5 changes: 5 additions & 0 deletions tpgtools/override_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,8 @@ type ProductTitleDetails struct {
// alternative name to be used for the product resources
Title string
}

type ProductDocsSectionDetails struct {
// alternative name to be used for the product resources in docs.
DocsSection string
}
5 changes: 5 additions & 0 deletions tpgtools/overrides/compute/beta/tpgtools_product.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## product level overrides

- type: PRODUCT_DOCS_SECTION
details:
docssection: Compute Engine
5 changes: 5 additions & 0 deletions tpgtools/overrides/compute/tpgtools_product.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## product level overrides

- type: PRODUCT_DOCS_SECTION
details:
docssection: Compute Engine
5 changes: 5 additions & 0 deletions tpgtools/overrides/monitoring/beta/tpgtools_product.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## product level overrides

- type: PRODUCT_DOCS_SECTION
details:
docssection: Cloud (Stackdriver) Monitoring
5 changes: 5 additions & 0 deletions tpgtools/overrides/monitoring/tpgtools_product.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## product level overrides

- type: PRODUCT_DOCS_SECTION
details:
docssection: Cloud (Stackdriver) Monitoring
17 changes: 17 additions & 0 deletions tpgtools/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,23 @@ func (pm *ProductMetadata) ProductType() string {
return snakeToTitleCase(pm.ProductName)
}

func (pm *ProductMetadata) DocsSection() string {
overrides, ok := productOverrides[pm.PackagePath]
if !ok {
glog.Fatalf("product overrides should be loaded already for packagePath %s", pm.PackagePath)
}
pt := ProductDocsSectionDetails{}
ptOk, err := overrides.ProductOverrideWithDetails(ProductDocsSection, &pt)
if err != nil {
glog.Fatalf("could not parse override %v", err)
}
if ptOk {
return pt.DocsSection
}

return pm.ProductType()
}

// ProductNameUpper is the all caps snakecase product name of a resource.
// For example, "NETWORK_SERVICES".
func (pm *ProductMetadata) ProductNameUpper() string {
Expand Down
6 changes: 6 additions & 0 deletions tpgtools/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ func (r Resource) ProductType() string {
return r.productMetadata.ProductType()
}

// DocsSection is *usuallu* the title-cased product name of a resource. For example,
// "NetworkServices" - but subject to overrides.
func (r Resource) DocsSection() string {
return r.productMetadata.DocsSection()
}

// ProductType is the snakecase product name of a resource. For example,
// "network_services".
func (r Resource) ProductName() string {
Expand Down
2 changes: 1 addition & 1 deletion tpgtools/templates/resource.html.markdown.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# are required, please file an issue at https:#github.com/hashicorp/terraform-provider-google/issues/new/choose
#
# ----------------------------------------------------------------------------
subcategory: "{{$.ProductType}}"
subcategory: "{{$.DocsSection}}"
layout: "google"
page_title: "Google: {{$.TerraformName}}"
sidebar_current: "{{$.SidebarCurrent}}"
Expand Down

0 comments on commit dbc4172

Please sign in to comment.