feat: parameterize provider address and source for multi-stand (DEV/TEST/PROD) support
This commit is contained in:
@@ -19,12 +19,12 @@ import (
|
||||
var CloudOutputByServiceID = map[int]types.CloudOutputSnapshot{}
|
||||
|
||||
// ResourceDocs генерирует полный набор .md файлов для одного сервиса.
|
||||
func ResourceDocs(docsDir string, spec types.ServiceSpec, version string, apiEndpoint string) {
|
||||
func ResourceDocs(docsDir string, spec types.ServiceSpec, version string, apiEndpoint string, providerSource string) {
|
||||
base := spec.Name
|
||||
nav := fmt.Sprintf("[Manual](%s.md) | [Create params](%s_params_create.md) | [Modify params](%s_params_modify.md) | [Output params](%s_outputs.md) | [Operations](%s_ops.md) | [Example](%s_example.md)", base, base, base, base, base, base)
|
||||
|
||||
WriteFile(filepath.Join(docsDir, base+".md"), buildManualPage(spec, nav))
|
||||
WriteFile(filepath.Join(docsDir, base+"_example.md"), buildExamplePage(spec, nav, version, apiEndpoint))
|
||||
WriteFile(filepath.Join(docsDir, base+"_example.md"), buildExamplePage(spec, nav, version, apiEndpoint, providerSource))
|
||||
WriteFile(filepath.Join(docsDir, base+"_params_create.md"), buildCreateParamsPage(spec, nav))
|
||||
WriteFile(filepath.Join(docsDir, base+"_params_modify.md"), buildModifyParamsPage(spec, nav))
|
||||
WriteFile(filepath.Join(docsDir, base+"_outputs.md"), buildOutputsPage(spec, nav))
|
||||
@@ -36,7 +36,7 @@ func ResourceDocs(docsDir string, spec types.ServiceSpec, version string, apiEnd
|
||||
srNav := fmt.Sprintf("[%s (основной)](%s.md) | [Operations](%s_ops.md) | [%s](%s.md) | [Example](%s_example.md)",
|
||||
spec.ServiceDisplayName, base, base, Capitalize(srName), srBase, srBase)
|
||||
WriteFile(filepath.Join(docsDir, srBase+".md"), buildSubresourcePage(spec, srName, srNav))
|
||||
WriteFile(filepath.Join(docsDir, srBase+"_example.md"), buildSubresourceExamplePage(spec, srName, srNav, version, apiEndpoint))
|
||||
WriteFile(filepath.Join(docsDir, srBase+"_example.md"), buildSubresourceExamplePage(spec, srName, srNav, version, apiEndpoint, providerSource))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,12 +178,12 @@ func htmlToMarkdown(s string) string {
|
||||
return strings.TrimSpace(s)
|
||||
}
|
||||
|
||||
func buildExamplePage(spec types.ServiceSpec, nav, version string, apiEndpoint string) string {
|
||||
func buildExamplePage(spec types.ServiceSpec, nav, version string, apiEndpoint string, providerSource string) string {
|
||||
var b strings.Builder
|
||||
b.WriteString(buildHeader(spec, nav))
|
||||
b.WriteString(fmt.Sprintf("## Copy-ready manifest (`%s_main.tf`)\n\n", spec.Name))
|
||||
b.WriteString("```hcl\n")
|
||||
b.WriteString(exampleBlock(spec, version, apiEndpoint))
|
||||
b.WriteString(exampleBlock(spec, version, apiEndpoint, providerSource))
|
||||
b.WriteString("```\n\n")
|
||||
b.WriteString("## Outputs usage\n\n")
|
||||
b.WriteString("```hcl\n")
|
||||
@@ -200,7 +200,7 @@ func buildExamplePage(spec types.ServiceSpec, nav, version string, apiEndpoint s
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func exampleBlock(spec types.ServiceSpec, version string, apiEndpoint string) string {
|
||||
func exampleBlock(spec types.ServiceSpec, version string, apiEndpoint string, providerSource string) string {
|
||||
createParams := FindParams(spec.Operations, "create")
|
||||
requiredParams, defaultParams := SplitParams(createParams)
|
||||
|
||||
@@ -208,7 +208,7 @@ func exampleBlock(spec types.ServiceSpec, version string, apiEndpoint string) st
|
||||
b.WriteString("terraform {\n")
|
||||
b.WriteString(" required_providers {\n")
|
||||
b.WriteString(" nubes = {\n")
|
||||
b.WriteString(" source = \"registry.kube5s.ru/nubes-test/nubes\"\n")
|
||||
b.WriteString(fmt.Sprintf(" source = \"%s\"\n", providerSource))
|
||||
b.WriteString(fmt.Sprintf(" version = \"%s\"\n", version))
|
||||
b.WriteString(" }\n")
|
||||
b.WriteString(" }\n")
|
||||
@@ -452,7 +452,7 @@ func buildSubresourcePage(spec types.ServiceSpec, srName string, nav string) str
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func buildSubresourceExamplePage(spec types.ServiceSpec, srName string, nav string, version string, apiEndpoint string) string {
|
||||
func buildSubresourceExamplePage(spec types.ServiceSpec, srName string, nav string, version string, apiEndpoint string, providerSource string) string {
|
||||
var b strings.Builder
|
||||
srResourceName := fmt.Sprintf("nubes_%s_%s", spec.Name, Slug(srName))
|
||||
b.WriteString(fmt.Sprintf("# Resource %s — Example\n\n", srResourceName))
|
||||
@@ -464,7 +464,7 @@ func buildSubresourceExamplePage(spec types.ServiceSpec, srName string, nav stri
|
||||
b.WriteString("terraform {\n")
|
||||
b.WriteString(" required_providers {\n")
|
||||
b.WriteString(" nubes = {\n")
|
||||
b.WriteString(" source = \"registry.kube5s.ru/nubes-test/nubes\"\n")
|
||||
b.WriteString(fmt.Sprintf(" source = \"%s\"\n", providerSource))
|
||||
b.WriteString(fmt.Sprintf(" version = \"%s\"\n", version))
|
||||
b.WriteString(" }\n")
|
||||
b.WriteString(" }\n")
|
||||
|
||||
@@ -27,6 +27,7 @@ func main() {
|
||||
// ⛔ LEGACY DEFAULT (index.cfm) — переопределяется через NUBES_API_ENDPOINT в profile.env.
|
||||
// Никогда не использовать deck-api.ngcloud.ru напрямую.
|
||||
apiEndpointFlag := flag.String("api-endpoint", "https://lk-api-gateway.ngcloud.ru/api/v1/svc", "API endpoint for example block")
|
||||
providerSourceFlag := flag.String("provider-source", "registry.kube5s.ru/nubes-dev/nubes", "Provider source for example block")
|
||||
opsFlag := flag.Bool("ops", false, "Generate per-service operations docs (resources_ops_yaml → docs/.../operations)")
|
||||
flag.Parse()
|
||||
|
||||
@@ -51,6 +52,7 @@ func main() {
|
||||
panic("--version is required")
|
||||
}
|
||||
apiEndpoint := *apiEndpointFlag
|
||||
providerSource := *providerSourceFlag
|
||||
|
||||
servicesOrder := loadServicesList(servicesList)
|
||||
specs := loadSpecs(resourcesDir, servicesOrder)
|
||||
@@ -69,7 +71,7 @@ func main() {
|
||||
if excludeSet[spec.Name] {
|
||||
continue
|
||||
}
|
||||
writers.ResourceDocs(docsDir, spec, version, apiEndpoint)
|
||||
writers.ResourceDocs(docsDir, spec, version, apiEndpoint, providerSource)
|
||||
processedSpecs = append(processedSpecs, spec)
|
||||
}
|
||||
writers.IndexMD(docsDir, processedSpecs)
|
||||
|
||||
Reference in New Issue
Block a user