Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions github/resource_github_repository_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func resourceGithubRepositoryFileCreate(ctx context.Context, d *schema.ResourceD
return diag.FromErr(err)
}

newResourceID, err := buildID(repo, file, branch)
newResourceID, err := buildID(repo, escapeIDPart(file), branch)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -392,7 +392,7 @@ func resourceGithubRepositoryFileUpdate(ctx context.Context, d *schema.ResourceD
}

if d.HasChanges("repository", "file", "branch") {
newResourceID, err := buildID(repo, file, branch)
newResourceID, err := buildID(repo, escapeIDPart(file), branch)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -468,7 +468,7 @@ func resourceGithubRepositoryFileImport(ctx context.Context, d *schema.ResourceD
return nil, err
}

newResourceID, err := buildID(repo, filePath, branch)
newResourceID, err := buildID(repo, escapeIDPart(filePath), branch)
if err != nil {
return nil, err
}
Expand Down
46 changes: 46 additions & 0 deletions github/resource_github_repository_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
)

func TestAccGithubRepositoryFile(t *testing.T) {
Expand Down Expand Up @@ -455,4 +458,47 @@ func TestAccGithubRepositoryFile(t *testing.T) {
},
})
})

t.Run("verify_that_id_can_contain_colon_in_file_path", func(t *testing.T) {
randomID := acctest.RandString(5)
repoName := fmt.Sprintf("%srepo-file-%s", testResourcePrefix, randomID)
filePathWithColon := "repro/example:one.yaml"
config := fmt.Sprintf(`

resource "github_repository" "test" {
name = "%s"
auto_init = true
vulnerability_alerts = true
}

resource "github_repository_file" "test" {
repository = github_repository.test.name
branch = "main"
file = "%s"
content = "bar"
commit_message = "Managed by Terraform"
commit_author = "Terraform User"
commit_email = "terraform@example.com"
}
`, repoName, filePathWithColon)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnauthenticated(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue("github_repository_file.test", tfjsonpath.New("id"), knownvalue.StringFunc(func(v string) error {
if strings.Contains(v, escapeIDPart(filePathWithColon)) {
return nil
}
return fmt.Errorf("expected id to contain escaped file path, got: %s", v)
})),
statecheck.ExpectKnownValue("github_repository_file.test", tfjsonpath.New("file"), knownvalue.StringExact(filePathWithColon)),
},
},
},
})
})
}
Loading