Skip to content

Commit

Permalink
resource/repository: create from template fixes
Browse files Browse the repository at this point in the history
* Create a new resource if `template` changes
* Make required fields non-optional
* Remove unnecessary length check
* Defer bump to go 1.13
* Replace hard-coded test values with env vars
  • Loading branch information
Jeremy Udit committed Jan 7, 2020
1 parent d6a569c commit c5af1a6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
3 changes: 3 additions & 0 deletions github/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func testAccPreCheck(t *testing.T) {
if v := os.Getenv("GITHUB_TEST_COLLABORATOR"); v == "" {
t.Fatal("GITHUB_TEST_COLLABORATOR must be set for acceptance tests")
}
if v := os.Getenv("GITHUB_TEMPLATE_REPOSITORY"); v == "" {
t.Fatal("GITHUB_TEMPLATE_REPOSITORY must be set for acceptance tests")
}
}

func TestProvider_individual(t *testing.T) {
Expand Down
8 changes: 3 additions & 5 deletions github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,18 @@ func resourceGithubRepository() *schema.Resource {
"template": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"owner": {
Type: schema.TypeString,
Optional: true,
Optional: false,
Default: false,
},
"repository": {
Type: schema.TypeString,
Optional: true,
Optional: false,
Default: false,
},
},
Expand Down Expand Up @@ -203,9 +204,6 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er

if template, ok := d.GetOk("template"); ok {
templateConfigBlocks := template.([]interface{})
if len(templateConfigBlocks) > 1 {
return errors.New("cannot specify template more than once")
}

for _, templateConfigBlock := range templateConfigBlocks {
templateConfigMap, ok := templateConfigBlock.(map[string]interface{})
Expand Down
11 changes: 7 additions & 4 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,16 +883,19 @@ resource "github_repository" "foo" {
}

func testAccGithubRepositoryCreateFromTemplate(randString string) string {

owner := os.Getenv("GITHUB_ORGANIZATION")
repository := os.Getenv("GITHUB_TEMPLATE_REPOSITORY")

return fmt.Sprintf(`
resource "github_repository" "foo" {
name = "tf-acc-test-%s"
description = "Terraform acceptance tests %s"
homepage_url = "http://example.com/"
template {
# FIXME: Change this to something more suitable for CI runs
owner = "jcudit"
repository = "terraform-template-module"
owner = "%s"
repository = "%s"
}
# So that acceptance tests can be run in a github organization
Expand All @@ -907,7 +910,7 @@ resource "github_repository" "foo" {
has_downloads = true
}
`, randString, randString)
`, randString, randString, owner, repository)
}

func testAccGithubRepositoryConfigTopics(randString string, topicList string) string {
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ require (
github.com/terraform-providers/terraform-provider-tls v1.2.0
golang.org/x/oauth2 v0.0.0-20190604054615-0f29369cfe45
)

go 1.13

0 comments on commit c5af1a6

Please sign in to comment.