Skip to content

Commit 1d40ad2

Browse files
authored
fix: Replace \n strings with new lines in pem_file (#931)
* fix: Replace `\n` strings with new lines in pem_file * chore: Format imports using alphabetical ordering * docs: Describe replacement of `\n` with new lines in PEM file * style: Remove erroneous trailing whitespace
1 parent f1b749d commit 1d40ad2

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

github/provider.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package github
33
import (
44
"fmt"
55
"log"
6+
"strings"
67
"time"
78

89
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
@@ -220,7 +221,14 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
220221
}
221222

222223
if v, ok := appAuthAttr["pem_file"].(string); ok && v != "" {
223-
appPemFile = v
224+
// The Go encoding/pem package only decodes PEM formatted blocks
225+
// that contain new lines. Some platforms, like Terraform Cloud,
226+
// do not support new lines within Environment Variables.
227+
// Any occurrence of \n in the `pem_file` argument's value
228+
// (explicit value, or default value taken from
229+
// GITHUB_APP_PEM_FILE Environment Variable) is replaced with an
230+
// actual new line character before decoding.
231+
appPemFile = strings.Replace(v, `\n`, "\n", -1)
224232
} else {
225233
return nil, fmt.Errorf("app_auth.pem_file must be set and contain a non-empty value")
226234
}

website/docs/index.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ The following arguments are supported in the `provider` block:
105105
* `app_auth` - (Optional) Configuration block to use GitHub App installation token. When not provided, the provider can only access resources available anonymously.
106106
* `id` - (Required) This is the ID of the GitHub App. It can sourced from the `GITHUB_APP_ID` environment variable.
107107
* `installation_id` - (Required) This is the ID of the GitHub App installation. It can sourced from the `GITHUB_APP_INSTALLATION_ID` environment variable.
108-
* `pem_file` - (Required) This is the contents of the GitHub App private key PEM file. It can also be sourced from the `GITHUB_APP_PEM_FILE` environment variable.
108+
* `pem_file` - (Required) This is the contents of the GitHub App private key PEM file. It can also be sourced from the `GITHUB_APP_PEM_FILE` environment variable and may use `\n` instead of actual new lines.
109109

110110
* `write_delay_ms` - (Optional) The number of milliseconds to sleep in between write operations in order to satisfy the GitHub API rate limits. Defaults to 1000ms or 1 second if not provided.
111111

0 commit comments

Comments
 (0)