diff --git a/github/data_source_github_actions_environment_secrets.go b/github/data_source_github_actions_environment_secrets.go index fe1fb5a1e2..05556162e3 100644 --- a/github/data_source_github_actions_environment_secrets.go +++ b/github/data_source_github_actions_environment_secrets.go @@ -3,6 +3,7 @@ package github import ( "context" "fmt" + "net/url" "github.com/google/go-github/v55/github" @@ -59,7 +60,8 @@ func dataSourceGithubActionsEnvironmentSecretsRead(d *schema.ResourceData, meta owner := meta.(*Owner).name var repoName string - env := d.Get("environment").(string) + envName := d.Get("environment").(string) + escapedEnvName := url.PathEscape(envName) if fullName, ok := d.GetOk("full_name"); ok { var err error @@ -88,7 +90,7 @@ func dataSourceGithubActionsEnvironmentSecretsRead(d *schema.ResourceData, meta var all_secrets []map[string]string for { - secrets, resp, err := client.Actions.ListEnvSecrets(context.TODO(), int(repo.GetID()), env, &options) + secrets, resp, err := client.Actions.ListEnvSecrets(context.TODO(), int(repo.GetID()), escapedEnvName, &options) if err != nil { return err } @@ -106,7 +108,7 @@ func dataSourceGithubActionsEnvironmentSecretsRead(d *schema.ResourceData, meta options.Page = resp.NextPage } - d.SetId(buildTwoPartID(repoName, env)) + d.SetId(buildTwoPartID(repoName, envName)) d.Set("secrets", all_secrets) return nil diff --git a/github/data_source_github_actions_environment_secrets_test.go b/github/data_source_github_actions_environment_secrets_test.go index 5e1cb87113..cef983779b 100644 --- a/github/data_source_github_actions_environment_secrets_test.go +++ b/github/data_source_github_actions_environment_secrets_test.go @@ -21,7 +21,7 @@ func TestAccGithubActionsEnvironmentSecretsDataSource(t *testing.T) { resource "github_repository_environment" "test" { repository = github_repository.test.name - environment = "test_environment_name" + environment = "environment/test" } resource "github_actions_environment_secret" "test" { diff --git a/github/data_source_github_actions_environment_variables.go b/github/data_source_github_actions_environment_variables.go index cc4e9bcf62..e689ef576d 100644 --- a/github/data_source_github_actions_environment_variables.go +++ b/github/data_source_github_actions_environment_variables.go @@ -3,6 +3,7 @@ package github import ( "context" "fmt" + "net/url" "github.com/google/go-github/v55/github" @@ -63,7 +64,8 @@ func dataSourceGithubActionsEnvironmentVariablesRead(d *schema.ResourceData, met owner := meta.(*Owner).name var repoName string - env := d.Get("environment").(string) + envName := d.Get("environment").(string) + escapedEnvName := url.PathEscape(envName) if fullName, ok := d.GetOk("full_name"); ok { var err error @@ -92,7 +94,7 @@ func dataSourceGithubActionsEnvironmentVariablesRead(d *schema.ResourceData, met var all_variables []map[string]string for { - variables, resp, err := client.Actions.ListEnvVariables(context.TODO(), int(repo.GetID()), env, &options) + variables, resp, err := client.Actions.ListEnvVariables(context.TODO(), int(repo.GetID()), escapedEnvName, &options) if err != nil { return err } @@ -111,7 +113,7 @@ func dataSourceGithubActionsEnvironmentVariablesRead(d *schema.ResourceData, met options.Page = resp.NextPage } - d.SetId(buildTwoPartID(repoName, env)) + d.SetId(buildTwoPartID(repoName, envName)) d.Set("variables", all_variables) return nil diff --git a/github/data_source_github_actions_environment_variables_test.go b/github/data_source_github_actions_environment_variables_test.go index 05ebf8b83e..c545f65cad 100644 --- a/github/data_source_github_actions_environment_variables_test.go +++ b/github/data_source_github_actions_environment_variables_test.go @@ -21,7 +21,7 @@ func TestAccGithubActionsEnvironmentVariablesDataSource(t *testing.T) { resource "github_repository_environment" "test" { repository = github_repository.test.name - environment = "test_environment_name" + environment = "environment/test" } resource "github_actions_environment_variable" "variable" { diff --git a/github/resource_github_actions_environment_secret.go b/github/resource_github_actions_environment_secret.go index 21b7a06ae5..c27c4964cc 100644 --- a/github/resource_github_actions_environment_secret.go +++ b/github/resource_github_actions_environment_secret.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "log" "net/http" + "net/url" "github.com/google/go-github/v55/github" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -75,6 +76,7 @@ func resourceGithubActionsEnvironmentSecretCreateOrUpdate(d *schema.ResourceData repoName := d.Get("repository").(string) envName := d.Get("environment").(string) + escapedEnvName := url.PathEscape(envName) secretName := d.Get("secret_name").(string) plaintextValue := d.Get("plaintext_value").(string) var encryptedValue string @@ -84,7 +86,7 @@ func resourceGithubActionsEnvironmentSecretCreateOrUpdate(d *schema.ResourceData return err } - keyId, publicKey, err := getEnvironmentPublicKeyDetails(repo.GetID(), envName, meta) + keyId, publicKey, err := getEnvironmentPublicKeyDetails(repo.GetID(), escapedEnvName, meta) if err != nil { return err } @@ -124,13 +126,14 @@ func resourceGithubActionsEnvironmentSecretRead(d *schema.ResourceData, meta int if err != nil { return err } + escapedEnvName := url.PathEscape(envName) repo, _, err := client.Repositories.Get(ctx, owner, repoName) if err != nil { return err } - secret, _, err := client.Actions.GetEnvSecret(ctx, int(repo.GetID()), envName, secretName) + secret, _, err := client.Actions.GetEnvSecret(ctx, int(repo.GetID()), escapedEnvName, secretName) if err != nil { if ghErr, ok := err.(*github.ErrorResponse); ok { if ghErr.Response.StatusCode == http.StatusNotFound { @@ -181,12 +184,13 @@ func resourceGithubActionsEnvironmentSecretDelete(d *schema.ResourceData, meta i if err != nil { return err } + escapedEnvName := url.PathEscape(envName) repo, _, err := client.Repositories.Get(ctx, owner, repoName) if err != nil { return err } log.Printf("[INFO] Deleting environment secret: %s", d.Id()) - _, err = client.Actions.DeleteEnvSecret(ctx, int(repo.GetID()), envName, secretName) + _, err = client.Actions.DeleteEnvSecret(ctx, int(repo.GetID()), escapedEnvName, secretName) return err } diff --git a/github/resource_github_actions_environment_secret_test.go b/github/resource_github_actions_environment_secret_test.go index 0238b4fa2c..3125ae72fe 100644 --- a/github/resource_github_actions_environment_secret_test.go +++ b/github/resource_github_actions_environment_secret_test.go @@ -26,7 +26,7 @@ func TestAccGithubActionsEnvironmentSecret(t *testing.T) { resource "github_repository_environment" "test" { repository = github_repository.test.name - environment = "test_environment_name" + environment = "environment/test" } resource "github_actions_environment_secret" "plaintext_secret" { @@ -122,7 +122,7 @@ func TestAccGithubActionsEnvironmentSecret(t *testing.T) { resource "github_repository_environment" "test" { repository = github_repository.test.name - environment = "test_environment_name" + environment = "environment/test" } resource "github_actions_environment_secret" "plaintext_secret" { diff --git a/github/resource_github_actions_environment_variable.go b/github/resource_github_actions_environment_variable.go index ae021c36ab..7ae9634f80 100644 --- a/github/resource_github_actions_environment_variable.go +++ b/github/resource_github_actions_environment_variable.go @@ -4,6 +4,7 @@ import ( "context" "log" "net/http" + "net/url" "github.com/google/go-github/v55/github" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -63,7 +64,8 @@ func resourceGithubActionsEnvironmentVariableCreate(d *schema.ResourceData, meta ctx := context.Background() repoName := d.Get("repository").(string) - env := d.Get("environment").(string) + envName := d.Get("environment").(string) + escapedEnvName := url.PathEscape(envName) name := d.Get("variable_name").(string) variable := &github.ActionsVariable{ @@ -76,12 +78,12 @@ func resourceGithubActionsEnvironmentVariableCreate(d *schema.ResourceData, meta return err } - _, err = client.Actions.CreateEnvVariable(ctx, int(repo.GetID()), env, variable) + _, err = client.Actions.CreateEnvVariable(ctx, int(repo.GetID()), escapedEnvName, variable) if err != nil { return err } - d.SetId(buildThreePartID(repoName, env, name)) + d.SetId(buildThreePartID(repoName, envName, name)) return resourceGithubActionsEnvironmentVariableRead(d, meta) } @@ -91,7 +93,8 @@ func resourceGithubActionsEnvironmentVariableUpdate(d *schema.ResourceData, meta ctx := context.Background() repoName := d.Get("repository").(string) - env := d.Get("environment").(string) + envName := d.Get("environment").(string) + escapedEnvName := url.PathEscape(envName) name := d.Get("variable_name").(string) variable := &github.ActionsVariable{ @@ -103,12 +106,12 @@ func resourceGithubActionsEnvironmentVariableUpdate(d *schema.ResourceData, meta if err != nil { return err } - _, err = client.Actions.UpdateEnvVariable(ctx, int(repo.GetID()), env, variable) + _, err = client.Actions.UpdateEnvVariable(ctx, int(repo.GetID()), escapedEnvName, variable) if err != nil { return err } - d.SetId(buildThreePartID(repoName, env, name)) + d.SetId(buildThreePartID(repoName, envName, name)) return resourceGithubActionsEnvironmentVariableRead(d, meta) } @@ -117,17 +120,18 @@ func resourceGithubActionsEnvironmentVariableRead(d *schema.ResourceData, meta i owner := meta.(*Owner).name ctx := context.Background() - repoName, env, name, err := parseThreePartID(d.Id(), "repository", "environment", "variable_name") + repoName, envName, name, err := parseThreePartID(d.Id(), "repository", "environment", "variable_name") if err != nil { return err } + escapedEnvName := url.PathEscape(envName) repo, _, err := client.Repositories.Get(ctx, owner, repoName) if err != nil { return err } - variable, _, err := client.Actions.GetEnvVariable(ctx, int(repo.GetID()), env, name) + variable, _, err := client.Actions.GetEnvVariable(ctx, int(repo.GetID()), escapedEnvName, name) if err != nil { if ghErr, ok := err.(*github.ErrorResponse); ok { if ghErr.Response.StatusCode == http.StatusNotFound { @@ -141,7 +145,7 @@ func resourceGithubActionsEnvironmentVariableRead(d *schema.ResourceData, meta i } d.Set("repository", repoName) - d.Set("environment", env) + d.Set("environment", envName) d.Set("variable_name", name) d.Set("value", variable.Value) d.Set("created_at", variable.CreatedAt.String()) @@ -155,17 +159,18 @@ func resourceGithubActionsEnvironmentVariableDelete(d *schema.ResourceData, meta owner := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) - repoName, env, name, err := parseThreePartID(d.Id(), "repository", "environment", "variable_name") + repoName, envName, name, err := parseThreePartID(d.Id(), "repository", "environment", "variable_name") if err != nil { return err } + escapedEnvName := url.QueryEscape(envName) repo, _, err := client.Repositories.Get(ctx, owner, repoName) if err != nil { return err } - _, err = client.Actions.DeleteEnvVariable(ctx, int(repo.GetID()), env, name) + _, err = client.Actions.DeleteEnvVariable(ctx, int(repo.GetID()), escapedEnvName, name) return err } diff --git a/github/resource_github_actions_environment_variable_test.go b/github/resource_github_actions_environment_variable_test.go index 9dd2857e90..1b23847e36 100644 --- a/github/resource_github_actions_environment_variable_test.go +++ b/github/resource_github_actions_environment_variable_test.go @@ -25,7 +25,7 @@ func TestAccGithubActionsEnvironmentVariable(t *testing.T) { resource "github_repository_environment" "test" { repository = github_repository.test.name - environment = "test_environment_name" + environment = "environment/test" } resource "github_actions_environment_variable" "variable" { @@ -103,7 +103,7 @@ func TestAccGithubActionsEnvironmentVariable(t *testing.T) { resource "github_repository_environment" "test" { repository = github_repository.test.name - environment = "test_environment_name" + environment = "environment/test" } resource "github_actions_environment_variable" "variable" { @@ -143,7 +143,7 @@ func TestAccGithubActionsEnvironmentVariable(t *testing.T) { t.Run("imports environment variables without error", func(t *testing.T) { value := "my_variable_value" - envName := "test_environment_name" + envName := "environment/test" varName := "test_variable" config := fmt.Sprintf(`