Skip to content

Commit 898ad43

Browse files
committed
Simplify import ID
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent e5106c5 commit 898ad43

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

github/data_source_github_repository_pages_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func TestAccGithubRepositoryPagesDataSource(t *testing.T) {
2929
}
3030
3131
resource "github_repository_pages" "test" {
32-
owner = "%s"
3332
repository = github_repository.test.name
3433
build_type = "legacy"
3534
source {
@@ -39,12 +38,11 @@ func TestAccGithubRepositoryPagesDataSource(t *testing.T) {
3938
}
4039
4140
data "github_repository_pages" "test" {
42-
owner = "%s"
4341
repository = github_repository.test.name
4442
4543
depends_on = [github_repository_pages.test]
4644
}
47-
`, repoName, baseRepoVisibility, testAccConf.owner, testAccConf.owner)
45+
`, repoName, baseRepoVisibility)
4846

4947
resource.Test(t, resource.TestCase{
5048
PreCheck: func() { skipUnauthenticated(t) },

github/resource_github_repository_pages.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net/http"
77
"strconv"
8+
"strings"
89

910
"github.com/google/go-github/v82/github"
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -276,9 +277,9 @@ func resourceGithubRepositoryPagesDelete(ctx context.Context, d *schema.Resource
276277
}
277278

278279
func resourceGithubRepositoryPagesImport(ctx context.Context, d *schema.ResourceData, m any) ([]*schema.ResourceData, error) {
279-
owner, repoName, err := parseID2(d.Id())
280-
if err != nil {
281-
return nil, fmt.Errorf("invalid ID specified: supplied ID must be written as <owner>:<repository>. Original error: %w", err)
280+
repoName := d.Id()
281+
if strings.Contains(repoName, " ") {
282+
return nil, fmt.Errorf("invalid ID specified: supplied ID must be the slug of the repository name")
282283
}
283284
// if err := d.Set("owner", owner); err != nil { // TODO: Add owner support
284285
// return nil, err
@@ -288,6 +289,7 @@ func resourceGithubRepositoryPagesImport(ctx context.Context, d *schema.Resource
288289
}
289290

290291
meta := m.(*Owner)
292+
owner := meta.name
291293
client := meta.v3client
292294

293295
repo, _, err := client.Repositories.Get(ctx, owner, repoName)

github/resource_github_repository_pages_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ source {
169169
{
170170
ResourceName: "github_repository_pages.test",
171171
ImportState: true,
172-
ImportStateId: fmt.Sprintf("%s:%s", testAccConf.owner, repoName),
172+
ImportStateId: repoName,
173173
},
174174
},
175175
})

website/docs/r/repository_pages.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ In addition to the above arguments, the following attributes are exported:
128128

129129
## Import
130130

131-
GitHub repository pages can be imported using the `owner:repository` format:
131+
GitHub repository pages can be imported using the `repository-slug`, e.g.
132132

133133
```sh
134-
terraform import github_repository_pages.example my-org:my-repo
134+
terraform import github_repository_pages.example my-repo
135135
```

0 commit comments

Comments
 (0)