From a905e766b3cc37e2066d126144ee51940d984783 Mon Sep 17 00:00:00 2001 From: guineveresaenger Date: Wed, 18 Sep 2024 12:36:34 -0700 Subject: [PATCH] Add various replacements --- pkg/tfgen/installation_docs.go | 4 +++ pkg/tfgen/installation_docs_test.go | 26 +++++++++++++++++++ .../replace-provider-block/expected.md | 3 +++ .../test_data/replace-provider-block/input.md | 3 +++ .../expected.md | 14 ++++++++++ .../input.md | 14 ++++++++++ .../rewrite-tf-init-to-pulumi-up/expected.md | 5 ++++ .../rewrite-tf-init-to-pulumi-up/input.md | 5 ++++ 8 files changed, 74 insertions(+) create mode 100644 pkg/tfgen/test_data/replace-provider-block/expected.md create mode 100644 pkg/tfgen/test_data/replace-provider-block/input.md create mode 100644 pkg/tfgen/test_data/rewrite-providers-tf-to-pulumi-yaml/expected.md create mode 100644 pkg/tfgen/test_data/rewrite-providers-tf-to-pulumi-yaml/input.md create mode 100644 pkg/tfgen/test_data/rewrite-tf-init-to-pulumi-up/expected.md create mode 100644 pkg/tfgen/test_data/rewrite-tf-init-to-pulumi-up/input.md diff --git a/pkg/tfgen/installation_docs.go b/pkg/tfgen/installation_docs.go index 43ead1cc3..abab171c6 100644 --- a/pkg/tfgen/installation_docs.go +++ b/pkg/tfgen/installation_docs.go @@ -114,6 +114,9 @@ func applyEditRules(contentBytes []byte, docFile string, g *Generator) ([]byte, edits = append(edits, skipSectionHeadersEdit(docFile), removeTfVersionMentions(docFile), + //Replace "providers.tf" with "Pulumi.yaml" + reReplace(`providers.tf`, `Pulumi.yaml`), + reReplace(`terraform init`, `pulumi up`), // Replace all "T/terraform" with "P/pulumi" reReplace(`Terraform`, `Pulumi`), reReplace(`terraform`, `pulumi`), @@ -130,6 +133,7 @@ func applyEditRules(contentBytes []byte, docFile string, g *Generator) ([]byte, reReplace("### Optional\n", ""), reReplace(`block contains the following arguments`, `input has the following nested fields`), + reReplace(`provider block`, `provider configuration`), ) contentBytes, err := edits.apply(docFile, contentBytes) if err != nil { diff --git a/pkg/tfgen/installation_docs_test.go b/pkg/tfgen/installation_docs_test.go index c60bd3f9d..091d5aadb 100644 --- a/pkg/tfgen/installation_docs_test.go +++ b/pkg/tfgen/installation_docs_test.go @@ -306,11 +306,37 @@ func TestApplyEditRules(t *testing.T) { }, expected: []byte(readfile(t, "test_data/replace-terraform-version/expected.md")), }, + { + // Found in linode + name: "Rewrites providers.tf to Pulumi.yaml", + docFile: DocFile{ + Content: []byte(readfile(t, "test_data/rewrite-providers-tf-to-pulumi-yaml/input.md")), + }, + expected: []byte(readfile(t, "test_data/rewrite-providers-tf-to-pulumi-yaml/expected.md")), + }, + { + name: "Rewrites terraform init to pulumi up", + docFile: DocFile{ + Content: []byte(readfile(t, "test_data/rewrite-tf-init-to-pulumi-up/input.md")), + }, + expected: []byte(readfile(t, "test_data/rewrite-tf-init-to-pulumi-up/expected.md")), + }, + { + // Found in linode + name: "Replaces provider block with provider configuration", + docFile: DocFile{ + Content: []byte(readfile(t, "test_data/replace-provider-block/input.md")), + }, + expected: []byte(readfile(t, "test_data/replace-provider-block/expected.md")), + }, } for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() + if runtime.GOOS == "windows" { + t.Skipf("Skipping on Windows due to a newline handling issue") + } g := &Generator{ sink: mockSink{t}, editRules: defaultEditRules(), diff --git a/pkg/tfgen/test_data/replace-provider-block/expected.md b/pkg/tfgen/test_data/replace-provider-block/expected.md new file mode 100644 index 000000000..548cead5e --- /dev/null +++ b/pkg/tfgen/test_data/replace-provider-block/expected.md @@ -0,0 +1,3 @@ +### Configuring the Target API Version + +The `api_version` can be set on the provider configuration like so: diff --git a/pkg/tfgen/test_data/replace-provider-block/input.md b/pkg/tfgen/test_data/replace-provider-block/input.md new file mode 100644 index 000000000..7efbb898e --- /dev/null +++ b/pkg/tfgen/test_data/replace-provider-block/input.md @@ -0,0 +1,3 @@ +### Configuring the Target API Version + +The `api_version` can be set on the provider block like so: diff --git a/pkg/tfgen/test_data/rewrite-providers-tf-to-pulumi-yaml/expected.md b/pkg/tfgen/test_data/rewrite-providers-tf-to-pulumi-yaml/expected.md new file mode 100644 index 000000000..817fd5298 --- /dev/null +++ b/pkg/tfgen/test_data/rewrite-providers-tf-to-pulumi-yaml/expected.md @@ -0,0 +1,14 @@ +## Using Configuration Files + +Configuration files can be used to specify Linode client configuration options across various Linode integrations. + +For example: + +`~/.config/linode` + +```ini +[default] +token = mylinodetoken +``` + +`Pulumi.yaml` \ No newline at end of file diff --git a/pkg/tfgen/test_data/rewrite-providers-tf-to-pulumi-yaml/input.md b/pkg/tfgen/test_data/rewrite-providers-tf-to-pulumi-yaml/input.md new file mode 100644 index 000000000..e473d2cd4 --- /dev/null +++ b/pkg/tfgen/test_data/rewrite-providers-tf-to-pulumi-yaml/input.md @@ -0,0 +1,14 @@ +## Using Configuration Files + +Configuration files can be used to specify Linode client configuration options across various Linode integrations. + +For example: + +`~/.config/linode` + +```ini +[default] +token = mylinodetoken +``` + +`providers.tf` \ No newline at end of file diff --git a/pkg/tfgen/test_data/rewrite-tf-init-to-pulumi-up/expected.md b/pkg/tfgen/test_data/rewrite-tf-init-to-pulumi-up/expected.md new file mode 100644 index 000000000..5463c6c03 --- /dev/null +++ b/pkg/tfgen/test_data/rewrite-tf-init-to-pulumi-up/expected.md @@ -0,0 +1,5 @@ +Note: Fully qualified `secret_name` ARN as input is REQUIRED for cross-AWS account secrets. + +Note: `sts_endpoint` parameter is REQUIRED for cross-AWS region or cross-AWS account secrets. + +In terminal, `pulumi up` \ No newline at end of file diff --git a/pkg/tfgen/test_data/rewrite-tf-init-to-pulumi-up/input.md b/pkg/tfgen/test_data/rewrite-tf-init-to-pulumi-up/input.md new file mode 100644 index 000000000..6edc7e111 --- /dev/null +++ b/pkg/tfgen/test_data/rewrite-tf-init-to-pulumi-up/input.md @@ -0,0 +1,5 @@ +Note: Fully qualified `secret_name` ARN as input is REQUIRED for cross-AWS account secrets. + +Note: `sts_endpoint` parameter is REQUIRED for cross-AWS region or cross-AWS account secrets. + +In terminal, `terraform init` \ No newline at end of file