From 1bab333d47b89cf11fac89e6f6c23236016181f6 Mon Sep 17 00:00:00 2001 From: guineveresaenger Date: Wed, 9 Oct 2024 10:55:21 -0700 Subject: [PATCH] Explain the need for the edit rule --- provider/resources.go | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/provider/resources.go b/provider/resources.go index 6cae163f..810475b6 100644 --- a/provider/resources.go +++ b/provider/resources.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "os" + "path" // embed is used to store bridge-metadata.json in the compiled binary _ "embed" @@ -424,27 +425,30 @@ func Provider() tfbridge.ProviderInfo { func editRules(defaults []tfbridge.DocsEdit) []tfbridge.DocsEdit { return append( defaults, - - tfbridge.DocsEdit{ - Path: "index.md", - Edit: func(_ string, content []byte) ([]byte, error) { - input, err := os.ReadFile("provider/installation-replaces/example-input.md") - if err != nil { - return nil, err - } - replace, err := os.ReadFile("provider/installation-replaces/example-desired.md") - if err != nil { - return nil, err - } - b := bytes.ReplaceAll( - content, - input, - replace) - return b, nil - }, - }, + fixInstallationExample, ) } +// In the upstream example, two providers are defined in the same code block. +// Pulumi Convert is not set up to handle this case, so this edit breaks the example up into two separate code blocks. +var fixInstallationExample = tfbridge.DocsEdit{ + Path: "index.md", + Edit: func(_ string, content []byte) ([]byte, error) { + input, err := os.ReadFile("provider/installation-replaces/example-input.md") + if err != nil { + return nil, err + } + replace, err := os.ReadFile("provider/installation-replaces/example-desired.md") + if err != nil { + return nil, err + } + b := bytes.ReplaceAll( + content, + input, + replace) + return b, nil + }, +} + //go:embed cmd/pulumi-resource-harness/bridge-metadata.json var metadata []byte