From 3de4d8c1291805a9678829c1113356726fa61028 Mon Sep 17 00:00:00 2001 From: Angie Pinilla Date: Tue, 2 Jun 2020 00:12:27 -0400 Subject: [PATCH 01/17] add disappears logic and test --- github/resource_github_actions_secret.go | 10 ++++- github/resource_github_actions_secret_test.go | 39 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/github/resource_github_actions_secret.go b/github/resource_github_actions_secret.go index 8050649d87..6fa59fe604 100644 --- a/github/resource_github_actions_secret.go +++ b/github/resource_github_actions_secret.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "golang.org/x/crypto/nacl/box" "log" + "net/http" ) func resourceGithubActionsSecret() *schema.Resource { @@ -101,7 +102,14 @@ func resourceGithubActionsSecretRead(d *schema.ResourceData, meta interface{}) e secret, _, err := client.Actions.GetSecret(ctx, owner, repoName, secretName) if err != nil { - d.SetId("") + if ghErr, ok := err.(*github.ErrorResponse); ok { + if ghErr.Response.StatusCode == http.StatusNotFound { + log.Printf("[WARN] Removing actions secret %s from state because it no longer exists in GitHub", + d.Id()) + d.SetId("") + return nil + } + } return err } diff --git a/github/resource_github_actions_secret_test.go b/github/resource_github_actions_secret_test.go index 47b9468a42..6020064d66 100644 --- a/github/resource_github_actions_secret_test.go +++ b/github/resource_github_actions_secret_test.go @@ -45,6 +45,28 @@ func TestAccGithubActionsSecret_basic(t *testing.T) { }) } +func TestAccGithubActionsSecret_disappears(t *testing.T) { + repo := os.Getenv("GITHUB_TEMPLATE_REPOSITORY") + secretResourceName := "github_actions_secret.test_secret" + secretValue := "super_secret_value" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckGithubActionsSecretDestroy, + Steps: []resource.TestStep{ + { + Config: testAccGithubActionsSecretFullConfig(repo, secretValue), + Check: resource.ComposeTestCheckFunc( + testAccCheckGithubActionsSecretExists(secretResourceName, "test_secret_name", t), + testAccCheckGithubActionsSecretDisappears(secretResourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + func testAccGithubActionsSecretFullConfig(repoName, plaintext string) string { // Take resources from other tests to avoid manual creation of secrets / repos @@ -88,6 +110,23 @@ func testAccCheckGithubActionsSecretExists(resourceName, secretName string, t *t } } +func testAccCheckGithubActionsSecretDisappears(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + conn := testAccProvider.Meta().(*Organization).v3client + owner := testAccProvider.Meta().(*Organization).name + repoName, secretName, err := parseTwoPartID(rs.Primary.ID, "repository", "secret_name") + if err != nil { + return err + } + _, err = conn.Actions.DeleteSecret(context.TODO(), owner, repoName, secretName) + return err + } +} + func testAccCheckGithubActionsSecretDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*Organization).v3client From f0bab3dbd76d02a94516330ae4d27e3e3c70062b Mon Sep 17 00:00:00 2001 From: Angie Pinilla Date: Tue, 2 Jun 2020 00:40:15 -0400 Subject: [PATCH 02/17] refactor tests to not re-use resources --- github/resource_github_actions_secret_test.go | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/github/resource_github_actions_secret_test.go b/github/resource_github_actions_secret_test.go index 6020064d66..ebf081c673 100644 --- a/github/resource_github_actions_secret_test.go +++ b/github/resource_github_actions_secret_test.go @@ -3,7 +3,7 @@ package github import ( "context" "fmt" - "os" + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -11,7 +11,7 @@ import ( ) func TestAccGithubActionsSecret_basic(t *testing.T) { - repo := os.Getenv("GITHUB_TEMPLATE_REPOSITORY") + repo := acctest.RandomWithPrefix("tf-acc-test") secretResourceName := "github_actions_secret.test_secret" secretValue := "super_secret_value" @@ -46,11 +46,11 @@ func TestAccGithubActionsSecret_basic(t *testing.T) { } func TestAccGithubActionsSecret_disappears(t *testing.T) { - repo := os.Getenv("GITHUB_TEMPLATE_REPOSITORY") + repo := acctest.RandomWithPrefix("tf-acc-test") secretResourceName := "github_actions_secret.test_secret" secretValue := "super_secret_value" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckGithubActionsSecretDestroy, @@ -68,22 +68,24 @@ func TestAccGithubActionsSecret_disappears(t *testing.T) { } func testAccGithubActionsSecretFullConfig(repoName, plaintext string) string { + // To allow tests to run in parallel and prevent re-using resources defined across the + // codebase, we create a repository resource and define it's actions public key here + // alongside the new actions secret resource + return fmt.Sprintf(` +data "github_actions_public_key" "test_pk" { + repository = github_repository.test.name +} - // Take resources from other tests to avoid manual creation of secrets / repos - githubPKData := testAccCheckGithubActionsPublicKeyDataSourceConfig(repoName) - githubActionsSecretResource := testAccGithubActionsSecretConfig(repoName, plaintext) - - return fmt.Sprintf("%s%s", githubPKData, githubActionsSecretResource) +resource "github_repository" "test" { + name = "%s" } -func testAccGithubActionsSecretConfig(repo, plaintext string) string { - return fmt.Sprintf(` resource "github_actions_secret" "test_secret" { - repository = "%s" + repository = github_repository.test.name secret_name = "test_secret_name" plaintext_value = "%s" } -`, repo, plaintext) +`, repoName, plaintext) } func testAccCheckGithubActionsSecretExists(resourceName, secretName string, t *testing.T) resource.TestCheckFunc { From f9315b534f37b9094db09c76ceb580b96acf6e95 Mon Sep 17 00:00:00 2001 From: Angie Pinilla Date: Mon, 25 May 2020 16:26:14 -0400 Subject: [PATCH 03/17] generate ssh key per test --- github/resource_github_repository_deploy_key_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/github/resource_github_repository_deploy_key_test.go b/github/resource_github_repository_deploy_key_test.go index fbb7a4d4ed..2b41786440 100644 --- a/github/resource_github_repository_deploy_key_test.go +++ b/github/resource_github_repository_deploy_key_test.go @@ -3,6 +3,8 @@ package github import ( "context" "fmt" + "os" + "os/exec" "path/filepath" "regexp" "strconv" @@ -51,6 +53,15 @@ func TestSuppressDeployKeyDiff(t *testing.T) { } func TestAccGithubRepositoryDeployKey_basic(t *testing.T) { + testUserEmail := os.Getenv("GITHUB_TEST_USER_EMAIL") + if testUserEmail == "" { + t.Skip("Skipping because `GITHUB_TEST_USER_EMAIL` is not set") + } + cmd := exec.Command("bash", "-c", fmt.Sprintf("ssh-keygen -t rsa -b 4096 -C %s -N '' -f test-fixtures/id_rsa>/dev/null <<< y >/dev/null", testUserEmail)) + if err := cmd.Run(); err != nil { + t.Fatal(err) + } + rn := "github_repository_deploy_key.test_repo_deploy_key" rs := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) repositoryName := fmt.Sprintf("acctest-%s", rs) From 97b943c9b3a344267c0b0d8fcecd5fe0203de6ff Mon Sep 17 00:00:00 2001 From: Ben Abrams Date: Sun, 5 Jan 2020 14:11:26 -0800 Subject: [PATCH 04/17] Fix issues with auto_init destroying repositories From github API perspective setting or modifying `auto_init` only makes sense in the context of creating a new repository. Changing it after is ignored by the github API which is the behavior we should (and use to) match. The only scenario where this makes sense to assume that changing this intends on a destructive action (blowing up a github repo is not something that should be easy accidentally) is when you use the `terraform taint` command but for very different reasons. This change is related to several PRs that subverts the communities expectations with no real or perceived value. Signed-off-by: Ben Abrams --- github/resource_github_repository.go | 2 +- github/resource_github_repository_test.go | 67 ----------------------- 2 files changed, 1 insertion(+), 68 deletions(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 2fc6ef0f4b..7c4d8eb77f 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -87,7 +87,7 @@ func resourceGithubRepository() *schema.Resource { "auto_init": { Type: schema.TypeBool, Optional: true, - ForceNew: true, + ForceNew: false, }, "default_branch": { Type: schema.TypeString, diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 252075d5e0..6b28be0bf2 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -451,48 +451,6 @@ func TestAccGithubRepository_topics(t *testing.T) { }) } -func TestAccGithubRepository_autoInitForceNew(t *testing.T) { - var repo github.Repository - - rn := "github_repository.foo" - randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) - name := fmt.Sprintf("tf-acc-test-%s", randString) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckGithubRepositoryDestroy, - Steps: []resource.TestStep{ - { - Config: testAccGithubRepositoryConfigAutoInitForceNew(randString), - Check: resource.ComposeTestCheckFunc( - testAccCheckGithubRepositoryExists(rn, &repo), - resource.TestCheckResourceAttr(rn, "name", name), - resource.TestCheckResourceAttr(rn, "auto_init", "false"), - ), - }, - { - Config: testAccGithubRepositoryConfigAutoInitForceNewUpdate(randString), - Check: resource.ComposeTestCheckFunc( - testAccCheckGithubRepositoryExists(rn, &repo), - resource.TestCheckResourceAttr(rn, "name", name), - resource.TestCheckResourceAttr(rn, "auto_init", "true"), - resource.TestCheckResourceAttr(rn, "license_template", "mpl-2.0"), - resource.TestCheckResourceAttr(rn, "gitignore_template", "Go"), - ), - }, - { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "auto_init", "license_template", "gitignore_template", - }, - }, - }, - }) -} - func TestAccGithubRepository_createFromTemplate(t *testing.T) { var repo github.Repository @@ -940,28 +898,3 @@ resource "github_repository" "foo" { } `, randString, randString, topicList) } - -func testAccGithubRepositoryConfigAutoInitForceNew(randString string) string { - return fmt.Sprintf(` -resource "github_repository" "foo" { - name = "tf-acc-test-%s" - auto_init = false -} -`, randString) -} - -func testAccGithubRepositoryConfigAutoInitForceNewUpdate(randString string) string { - return fmt.Sprintf(` -resource "github_repository" "foo" { - name = "tf-acc-test-%s" - auto_init = true - license_template = "mpl-2.0" - gitignore_template = "Go" -} - -resource "github_branch_protection" "repo_name_master" { - repository = "${github_repository.foo.name}" - branch = "master" -} -`, randString) -} From 399b54aeaf84454d134ebcafdb1cb486fd38fa04 Mon Sep 17 00:00:00 2001 From: Ben Abrams Date: Mon, 25 May 2020 16:22:48 -0700 Subject: [PATCH 05/17] remove `ForceNew` attribute all together since by default it's not set in a resource --- github/resource_github_repository.go | 1 - 1 file changed, 1 deletion(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 7c4d8eb77f..fead0eeafa 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -87,7 +87,6 @@ func resourceGithubRepository() *schema.Resource { "auto_init": { Type: schema.TypeBool, Optional: true, - ForceNew: false, }, "default_branch": { Type: schema.TypeString, From 244eccb709fb736b638af7094a40207610bf6561 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Mon, 18 May 2020 14:13:01 +0200 Subject: [PATCH 06/17] Set commit info using create or update Due to how the read func was written Terraform will try to find the commit info each time it does a refresh. As you cannot get this info easily from the GitHub API, the provider would loop through commits until it found one containing the file in question. When the commit is a a distant memory, it can incur many API requests and, when managing many files across many repositories, could result in being rate limited. To address this instead we now set this info when the file is created or updated and not during the refresh. This is pretty safe as for this info to change upstream it would mean changing the file contents, which would trigger Terraform to update the file again (to enforce desired state). Signed-off-by: Stephen Hoekstra --- github/resource_github_repository_file.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/github/resource_github_repository_file.go b/github/resource_github_repository_file.go index adcaf9577a..9a9acdee40 100644 --- a/github/resource_github_repository_file.go +++ b/github/resource_github_repository_file.go @@ -162,11 +162,14 @@ func resourceGithubRepositoryFileCreate(d *schema.ResourceData, meta interface{} } log.Printf("[DEBUG] Creating repository file: %s/%s/%s in branch: %s", org, repo, file, branch) - _, _, err = client.Repositories.CreateFile(ctx, org, repo, file, opts) + resp, _, err := client.Repositories.CreateFile(ctx, org, repo, file, opts) if err != nil { return err } + d.Set("commit_author", resp.GetCommitter().GetName()) + d.Set("commit_email", resp.GetCommitter().GetEmail()) + d.Set("commit_message", resp.GetMessage()) d.SetId(fmt.Sprintf("%s/%s", repo, file)) return resourceGithubRepositoryFileRead(d, meta) @@ -209,16 +212,6 @@ func resourceGithubRepositoryFileRead(d *schema.ResourceData, meta interface{}) d.Set("file", file) d.Set("sha", fc.GetSHA()) - log.Printf("[DEBUG] Fetching commit info for repository file: %s/%s/%s", org, repo, file) - commit, err := getFileCommit(client, org, repo, file, branch) - if err != nil { - return err - } - - d.Set("commit_author", commit.GetCommit().GetCommitter().GetName()) - d.Set("commit_email", commit.GetCommit().GetCommitter().GetEmail()) - d.Set("commit_message", commit.GetCommit().GetMessage()) - return nil } @@ -250,11 +243,15 @@ func resourceGithubRepositoryFileUpdate(d *schema.ResourceData, meta interface{} } log.Printf("[DEBUG] Updating content in repository file: %s/%s/%s", org, repo, file) - _, _, err = client.Repositories.CreateFile(ctx, org, repo, file, opts) + resp, _, err := client.Repositories.CreateFile(ctx, org, repo, file, opts) if err != nil { return err } + d.Set("commit_author", resp.GetCommitter().GetName()) + d.Set("commit_email", resp.GetCommitter().GetEmail()) + d.Set("commit_message", resp.GetMessage()) + return resourceGithubRepositoryFileRead(d, meta) } From f14c448c025381504cb2077efead851b3ca531b5 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Mon, 18 May 2020 14:19:58 +0200 Subject: [PATCH 07/17] Move getFileCommit to util.go Signed-off-by: Stephen Hoekstra --- github/resource_github_repository_file.go | 45 --------------------- github/util.go | 49 +++++++++++++++++++++++ 2 files changed, 49 insertions(+), 45 deletions(-) diff --git a/github/resource_github_repository_file.go b/github/resource_github_repository_file.go index 9a9acdee40..3f36862e52 100644 --- a/github/resource_github_repository_file.go +++ b/github/resource_github_repository_file.go @@ -314,48 +314,3 @@ func checkRepositoryFileExists(client *github.Client, org, repo, file, branch st return nil } - -func getFileCommit(client *github.Client, org, repo, file, branch string) (*github.RepositoryCommit, error) { - ctx := context.WithValue(context.Background(), ctxId, fmt.Sprintf("%s/%s", repo, file)) - opts := &github.CommitsListOptions{ - SHA: branch, - } - allCommits := []*github.RepositoryCommit{} - for { - commits, resp, err := client.Repositories.ListCommits(ctx, org, repo, opts) - if err != nil { - return nil, err - } - - allCommits = append(allCommits, commits...) - - if resp.NextPage == 0 { - break - } - - opts.Page = resp.NextPage - } - - for _, c := range allCommits { - sha := c.GetSHA() - - // Skip merge commits - if strings.Contains(c.Commit.GetMessage(), "Merge branch") { - continue - } - - rc, _, err := client.Repositories.GetCommit(ctx, org, repo, sha) - if err != nil { - return nil, err - } - - for _, f := range rc.Files { - if f.GetFilename() == file && f.GetStatus() != "removed" { - log.Printf("[DEBUG] Found file: %s in commit: %s", file, sha) - return rc, nil - } - } - } - - return nil, fmt.Errorf("Cannot find file %s in repo %s/%s", file, org, repo) -} diff --git a/github/util.go b/github/util.go index ce519aaa3e..95f0cc8ae8 100644 --- a/github/util.go +++ b/github/util.go @@ -1,10 +1,13 @@ package github import ( + "context" "fmt" + "log" "strconv" "strings" + "github.com/google/go-github/github" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) @@ -110,3 +113,49 @@ func splitRepoFilePath(path string) (string, string) { parts := strings.Split(path, "/") return parts[0], strings.Join(parts[1:], "/") } + +// getFileCommit will return the commit in which the file specified was last updated. +func getFileCommit(client *github.Client, org, repo, file, branch string) (*github.RepositoryCommit, error) { + ctx := context.WithValue(context.Background(), ctxId, fmt.Sprintf("%s/%s", repo, file)) + opts := &github.CommitsListOptions{ + SHA: branch, + } + allCommits := []*github.RepositoryCommit{} + for { + commits, resp, err := client.Repositories.ListCommits(ctx, org, repo, opts) + if err != nil { + return nil, err + } + + allCommits = append(allCommits, commits...) + + if resp.NextPage == 0 { + break + } + + opts.Page = resp.NextPage + } + + for _, c := range allCommits { + sha := c.GetSHA() + + // Skip merge commits + if strings.Contains(c.Commit.GetMessage(), "Merge branch") { + continue + } + + rc, _, err := client.Repositories.GetCommit(ctx, org, repo, sha) + if err != nil { + return nil, err + } + + for _, f := range rc.Files { + if f.GetFilename() == file && f.GetStatus() != "removed" { + log.Printf("[DEBUG] Found file: %s in commit: %s", file, sha) + return rc, nil + } + } + } + + return nil, fmt.Errorf("Cannot find file %s in repo %s/%s", file, org, repo) +} From d8f42c11a5919e4bc7c7a117456a550b078bae87 Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Sat, 30 May 2020 09:14:18 -0400 Subject: [PATCH 08/17] Add Example Directory And Collaboration Example --- examples/README.md | 17 ++++++++++++++ examples/repository_collaborator/README.md | 22 +++++++++++++++++++ examples/repository_collaborator/main.tf | 11 ++++++++++ examples/repository_collaborator/outputs.tf | 4 ++++ examples/repository_collaborator/providers.tf | 5 +++++ examples/repository_collaborator/variables.tf | 19 ++++++++++++++++ 6 files changed, 78 insertions(+) create mode 100644 examples/README.md create mode 100644 examples/repository_collaborator/README.md create mode 100644 examples/repository_collaborator/main.tf create mode 100644 examples/repository_collaborator/outputs.tf create mode 100644 examples/repository_collaborator/providers.tf create mode 100644 examples/repository_collaborator/variables.tf diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000000..708a292f91 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,17 @@ +# GitHub Provider Examples + +This directory contains a set of examples of using various GitHub services with +Terraform. The examples each have their own README containing more details +on what the example does. + +To run any example, clone the repository and run `terraform apply` within +the example's own directory. + +For example: + +``` +$ git clone https://github.com/terraform-providers/terraform-provider-github +$ cd terraform-provider-github/examples/repository_collaborator +$ terraform apply +... +``` diff --git a/examples/repository_collaborator/README.md b/examples/repository_collaborator/README.md new file mode 100644 index 0000000000..b11bc9b156 --- /dev/null +++ b/examples/repository_collaborator/README.md @@ -0,0 +1,22 @@ +# Repository Collaborator + +This provides a template for managing [repository collaborators](https://help.github.com/en/github/setting-up-and-managing-your-github-user-account/inviting-collaborators-to-a-personal-repository). + +This example will also create a repository in the specified `owner` organization or a personal account. See https://www.terraform.io/docs/providers/github/index.html for details on configuring [`providers.tf`](./providers.tf) accordingly. + +Alternatively, you may use variables passed via command line: + +```console +export GITHUB_ORG= +export GITHUB_TOKEN= +export COLLABORATOR_USERNAME= +export COLLABORATOR_PERMISSION= +``` + +```console +terraform apply \ + -var "organization=${GITHUB_ORG}" \ + -var "github_token=${GITHUB_TOKEN}" \ + -var "username=${COLLABORATOR_USERNAME}" \ + -var "permission=${COLLABORATOR_PERMISSION}" +``` diff --git a/examples/repository_collaborator/main.tf b/examples/repository_collaborator/main.tf new file mode 100644 index 0000000000..5b0718e6a5 --- /dev/null +++ b/examples/repository_collaborator/main.tf @@ -0,0 +1,11 @@ +resource "github_repository" "collaboration" { + name = "collaboration" + private = true + description = "A collaborative repository" +} + +resource "github_repository_collaborator" "collaborator" { + repository = github_repository.collaboration.name + username = var.username + permission = var.permission +} diff --git a/examples/repository_collaborator/outputs.tf b/examples/repository_collaborator/outputs.tf new file mode 100644 index 0000000000..d5155451e1 --- /dev/null +++ b/examples/repository_collaborator/outputs.tf @@ -0,0 +1,4 @@ +output "repository" { + description = "Collaborative repository JSON blob" + value = github_repository.collaboration +} diff --git a/examples/repository_collaborator/providers.tf b/examples/repository_collaborator/providers.tf new file mode 100644 index 0000000000..2ba0931912 --- /dev/null +++ b/examples/repository_collaborator/providers.tf @@ -0,0 +1,5 @@ +provider "github" { + version = "2.8.0" + organization = var.organization + token = var.github_token +} diff --git a/examples/repository_collaborator/variables.tf b/examples/repository_collaborator/variables.tf new file mode 100644 index 0000000000..ee1013bf2f --- /dev/null +++ b/examples/repository_collaborator/variables.tf @@ -0,0 +1,19 @@ +variable "username" { + description = "Username of a collaborator" + type = string +} + +variable "permission" { + description = "Permission level for a collaborator" + type = string +} + +variable "organization" { + description = "GitHub organization used to configure the provider" + type = string +} + +variable "github_token" { + description = "GitHub access token used to configure the provider" + type = string +} From c23e0ca90b5c096fdc538fa2d1c90416dbb9b6a8 Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Tue, 9 Jun 2020 11:19:50 -0400 Subject: [PATCH 09/17] Update examples/repository_collaborator/README.md --- examples/repository_collaborator/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/repository_collaborator/README.md b/examples/repository_collaborator/README.md index b11bc9b156..2bff32ee3a 100644 --- a/examples/repository_collaborator/README.md +++ b/examples/repository_collaborator/README.md @@ -2,7 +2,7 @@ This provides a template for managing [repository collaborators](https://help.github.com/en/github/setting-up-and-managing-your-github-user-account/inviting-collaborators-to-a-personal-repository). -This example will also create a repository in the specified `owner` organization or a personal account. See https://www.terraform.io/docs/providers/github/index.html for details on configuring [`providers.tf`](./providers.tf) accordingly. +This example will also create a repository in the specified `owner` organization. See https://www.terraform.io/docs/providers/github/index.html for details on configuring [`providers.tf`](./providers.tf) accordingly. Alternatively, you may use variables passed via command line: From 187a28034dcd92c6226a30985ce6bec75c26c380 Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Tue, 9 Jun 2020 11:25:12 -0400 Subject: [PATCH 10/17] Apply suggestions from code review --- examples/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index 708a292f91..38a9a050f7 100644 --- a/examples/README.md +++ b/examples/README.md @@ -4,7 +4,7 @@ This directory contains a set of examples of using various GitHub services with Terraform. The examples each have their own README containing more details on what the example does. -To run any example, clone the repository and run `terraform apply` within +To run any example, clone the repository and run `terraform init`, `terraform plan`, and `terraform apply` within the example's own directory. For example: @@ -12,6 +12,8 @@ For example: ``` $ git clone https://github.com/terraform-providers/terraform-provider-github $ cd terraform-provider-github/examples/repository_collaborator +$ terraform init +$ terraform plan $ terraform apply ... ``` From 7029e7ec5a19d26e91a992fedb7cc199e6de1555 Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Sat, 30 May 2020 10:56:44 -0400 Subject: [PATCH 11/17] Add `delete_branch_on_merge` Example --- .../README.md | 18 ++++++++++++++++++ .../repository_delete_branch_on_merge/main.tf | 7 +++++++ .../outputs.tf | 4 ++++ .../providers.tf | 5 +++++ .../variables.tf | 9 +++++++++ 5 files changed, 43 insertions(+) create mode 100644 examples/repository_delete_branch_on_merge/README.md create mode 100644 examples/repository_delete_branch_on_merge/main.tf create mode 100644 examples/repository_delete_branch_on_merge/outputs.tf create mode 100644 examples/repository_delete_branch_on_merge/providers.tf create mode 100644 examples/repository_delete_branch_on_merge/variables.tf diff --git a/examples/repository_delete_branch_on_merge/README.md b/examples/repository_delete_branch_on_merge/README.md new file mode 100644 index 0000000000..db3ef40f6e --- /dev/null +++ b/examples/repository_delete_branch_on_merge/README.md @@ -0,0 +1,18 @@ +# Repository `delete_branch_on_merge` Example + +This displays configurability of the `delete_branch_on_merge` feature for GitHub repositories. + +This example will create a repository in the specified `owner` organization or a personal account. See https://www.terraform.io/docs/providers/github/index.html for details on configuring [`providers.tf`](./providers.tf) accordingly. + +Alternatively, you may use variables passed via command line: + +```console +export GITHUB_ORG= +export GITHUB_TOKEN= +``` + +```console +terraform apply \ + -var "organization=${GITHUB_ORG}" \ + -var "github_token=${GITHUB_TOKEN}" +``` diff --git a/examples/repository_delete_branch_on_merge/main.tf b/examples/repository_delete_branch_on_merge/main.tf new file mode 100644 index 0000000000..948de8db47 --- /dev/null +++ b/examples/repository_delete_branch_on_merge/main.tf @@ -0,0 +1,7 @@ +resource "github_repository" "delete_branch_on_merge" { + name = "delete_branch_on_merge" + description = "A repository with delete-branch-on-merge configured" + default_branch = "master" + private = true + delete_branch_on_merge = true +} diff --git a/examples/repository_delete_branch_on_merge/outputs.tf b/examples/repository_delete_branch_on_merge/outputs.tf new file mode 100644 index 0000000000..177b288c78 --- /dev/null +++ b/examples/repository_delete_branch_on_merge/outputs.tf @@ -0,0 +1,4 @@ +output "repository" { + description = "Example repository JSON blob" + value = github_repository.delete_branch_on_merge +} diff --git a/examples/repository_delete_branch_on_merge/providers.tf b/examples/repository_delete_branch_on_merge/providers.tf new file mode 100644 index 0000000000..2ba0931912 --- /dev/null +++ b/examples/repository_delete_branch_on_merge/providers.tf @@ -0,0 +1,5 @@ +provider "github" { + version = "2.8.0" + organization = var.organization + token = var.github_token +} diff --git a/examples/repository_delete_branch_on_merge/variables.tf b/examples/repository_delete_branch_on_merge/variables.tf new file mode 100644 index 0000000000..29f535031b --- /dev/null +++ b/examples/repository_delete_branch_on_merge/variables.tf @@ -0,0 +1,9 @@ +variable "organization" { + description = "GitHub organization used to configure the provider" + type = string +} + +variable "github_token" { + description = "GitHub access token used to configure the provider" + type = string +} From 7fb0b652c910bf98251e9e01ea69ec0cae232353 Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Sat, 30 May 2020 17:37:41 -0400 Subject: [PATCH 12/17] Add `github_release` Example --- examples/release/README.md | 23 +++++++++++++++++++++++ examples/release/main.tf | 6 ++++++ examples/release/outputs.tf | 4 ++++ examples/release/providers.tf | 5 +++++ examples/release/variables.tf | 24 ++++++++++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 examples/release/README.md create mode 100644 examples/release/main.tf create mode 100644 examples/release/outputs.tf create mode 100644 examples/release/providers.tf create mode 100644 examples/release/variables.tf diff --git a/examples/release/README.md b/examples/release/README.md new file mode 100644 index 0000000000..573afe0891 --- /dev/null +++ b/examples/release/README.md @@ -0,0 +1,23 @@ +# Release Example + +This displays retrieval of a GitHub release. + +This example will look up a GitHub release available to the specified `owner` organization or a personal account. See https://www.terraform.io/docs/providers/github/index.html for details on configuring [`providers.tf`](./providers.tf) accordingly. + +Alternatively, you may use variables passed via command line: + +```console +export GITHUB_ORG= +export GITHUB_TOKEN= +export RELEASE_OWNER= +export RELEASE_REPOSITORY= +export RELEASE_TAG= +``` +```console +terraform apply \ + -var "organization=${GITHUB_ORG}" \ + -var "github_token=${GITHUB_TOKEN}" \ + -var "owner=${RELEASE_OWNER}" \ + -var "repository=${RELEASE_REPOSITORY}" \ + -var "release_tag=${RELEASE_TAG}" +``` diff --git a/examples/release/main.tf b/examples/release/main.tf new file mode 100644 index 0000000000..2d35a0ba65 --- /dev/null +++ b/examples/release/main.tf @@ -0,0 +1,6 @@ +data "github_release" "by_tag" { + repository = var.repository + owner = var.owner + release_tag = var.release_tag + retrieve_by = "tag" +} diff --git a/examples/release/outputs.tf b/examples/release/outputs.tf new file mode 100644 index 0000000000..785f35723c --- /dev/null +++ b/examples/release/outputs.tf @@ -0,0 +1,4 @@ +output "github_release_assets_url" { + description = "Asset URL of a GitHub release" + value = data.github_release.by_tag.asserts_url +} diff --git a/examples/release/providers.tf b/examples/release/providers.tf new file mode 100644 index 0000000000..2ba0931912 --- /dev/null +++ b/examples/release/providers.tf @@ -0,0 +1,5 @@ +provider "github" { + version = "2.8.0" + organization = var.organization + token = var.github_token +} diff --git a/examples/release/variables.tf b/examples/release/variables.tf new file mode 100644 index 0000000000..12b74c5e59 --- /dev/null +++ b/examples/release/variables.tf @@ -0,0 +1,24 @@ +variable "organization" { + description = "GitHub organization used to configure the provider" + type = string +} + +variable "github_token" { + description = "GitHub access token used to configure the provider" + type = string +} + +variable "owner" { + description = "GitHub owner of a release to query" + type = string +} + +variable "repository" { + description = "GitHub repository of a release to query" + type = string +} + +variable "release_tag" { + description = "Tag of a release to query" + type = string +} From 7dc5d74ddfc9298c94fea6dfec2cfdadb1b636ea Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Tue, 9 Jun 2020 11:16:23 -0400 Subject: [PATCH 13/17] Update examples/repository_delete_branch_on_merge/README.md --- examples/repository_delete_branch_on_merge/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/repository_delete_branch_on_merge/README.md b/examples/repository_delete_branch_on_merge/README.md index db3ef40f6e..0d42a2c731 100644 --- a/examples/repository_delete_branch_on_merge/README.md +++ b/examples/repository_delete_branch_on_merge/README.md @@ -2,7 +2,7 @@ This displays configurability of the `delete_branch_on_merge` feature for GitHub repositories. -This example will create a repository in the specified `owner` organization or a personal account. See https://www.terraform.io/docs/providers/github/index.html for details on configuring [`providers.tf`](./providers.tf) accordingly. +This example will create a repository in the specified `owner` organization. See https://www.terraform.io/docs/providers/github/index.html for details on configuring [`providers.tf`](./providers.tf) accordingly. Alternatively, you may use variables passed via command line: From f2d2a7f247b8dcbf460d13bd97f1446380835ad8 Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Tue, 9 Jun 2020 11:50:04 -0400 Subject: [PATCH 14/17] Update CHANGELOG.md --- CHANGELOG.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 625b274ac3..c9e8c064d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,13 @@ -## 2.9.0 (Unreleased) +## 2.8.1 (Unreleased) + +BUG FIXES: + +* resource/github_repository_file: Reduce API requests when looping through commits ([GH-466]) +* resource/github_repository: Fix `auto_init` Destroying Repositories ([GH-317]) +* resource/github_repository_deploy_key: Fix acceptance test approach ([GH-471]) +* resource/github_actions_secret: Fix Case Where Secret Removed Outside Of Terraform ([GH-482]) +* Documentation Addition Of `examples/` Directory + ## 2.8.0 (May 15, 2020) BUG FIXES: From d6d6132a7ad6b0022a21c359e9b3d85a284e2578 Mon Sep 17 00:00:00 2001 From: Angie Pinilla Date: Tue, 9 Jun 2020 12:49:10 -0400 Subject: [PATCH 15/17] update go-github import --- github/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/util.go b/github/util.go index 95f0cc8ae8..da627a30cd 100644 --- a/github/util.go +++ b/github/util.go @@ -7,7 +7,7 @@ import ( "strconv" "strings" - "github.com/google/go-github/github" + "github.com/google/go-github/v31/github" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) From 12d6b0faebd8356f5c8d260548154fbe1f8cb4f5 Mon Sep 17 00:00:00 2001 From: tf-release-bot Date: Tue, 9 Jun 2020 17:09:23 +0000 Subject: [PATCH 16/17] v2.8.1 --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9e8c064d0..d51063d6f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,11 @@ -## 2.8.1 (Unreleased) +## 2.8.1 (June 09, 2020) BUG FIXES: -* resource/github_repository_file: Reduce API requests when looping through commits ([GH-466]) -* resource/github_repository: Fix `auto_init` Destroying Repositories ([GH-317]) -* resource/github_repository_deploy_key: Fix acceptance test approach ([GH-471]) -* resource/github_actions_secret: Fix Case Where Secret Removed Outside Of Terraform ([GH-482]) +* resource/github_repository_file: Reduce API requests when looping through commits ([[#466](https://github.com/terraform-providers/terraform-provider-github/issues/466)]) +* resource/github_repository: Fix `auto_init` Destroying Repositories ([[#317](https://github.com/terraform-providers/terraform-provider-github/issues/317)]) +* resource/github_repository_deploy_key: Fix acceptance test approach ([[#471](https://github.com/terraform-providers/terraform-provider-github/issues/471)]) +* resource/github_actions_secret: Fix Case Where Secret Removed Outside Of Terraform ([[#482](https://github.com/terraform-providers/terraform-provider-github/issues/482)]) * Documentation Addition Of `examples/` Directory ## 2.8.0 (May 15, 2020) From 60fff96c2f1613943a839b147580cb2ca1533b32 Mon Sep 17 00:00:00 2001 From: tf-release-bot Date: Tue, 9 Jun 2020 17:20:17 +0000 Subject: [PATCH 17/17] Cleanup after v2.8.1 release --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d51063d6f1..a5f61f00b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +## 2.9.0 (Unreleased) ## 2.8.1 (June 09, 2020) BUG FIXES: