From c5af1a62948c588e4e62cdd8c1ef14a09025f402 Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Mon, 6 Jan 2020 20:47:57 -0500 Subject: [PATCH] resource/repository: create from template fixes * 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 --- github/provider_test.go | 3 +++ github/resource_github_repository.go | 8 +++----- github/resource_github_repository_test.go | 11 +++++++---- go.mod | 2 -- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/github/provider_test.go b/github/provider_test.go index 899484eb3f..b97f87f646 100644 --- a/github/provider_test.go +++ b/github/provider_test.go @@ -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) { diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 107f930961..b43c692cda 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -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, }, }, @@ -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{}) diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 622f8a172e..3ca4fabda7 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -883,6 +883,10 @@ 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" @@ -890,9 +894,8 @@ resource "github_repository" "foo" { 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 @@ -907,7 +910,7 @@ resource "github_repository" "foo" { has_downloads = true } -`, randString, randString) +`, randString, randString, owner, repository) } func testAccGithubRepositoryConfigTopics(randString string, topicList string) string { diff --git a/go.mod b/go.mod index c7b3b44a52..10eb37901d 100644 --- a/go.mod +++ b/go.mod @@ -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