-
Notifications
You must be signed in to change notification settings - Fork 769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
visibility should be set on create and removed on update #680
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Repository Visibility with Org, type internal | ||
|
||
This demos various repository [visibility settings](https://help.github.com/en/github/administering-a-repository/setting-repository-visibility) for repositories. | ||
|
||
This example will create a repositories 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: | ||
|
||
```console | ||
export GITHUB_OWNER= | ||
export GITHUB_TOKEN= | ||
``` | ||
|
||
```console | ||
terraform apply \ | ||
-var "owner=${GITHUB_OWNER}" \ | ||
-var "github_token=${GITHUB_TOKEN}" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
provider_installation { | ||
filesystem_mirror { | ||
path = "/Users/jurgen.weber/checkouts/terraform/terraform-provider-github/examples/repo_org_internal/terraform.d/plugins" | ||
include = ["*/*/*"] | ||
} | ||
direct { | ||
exclude = ["*/*/*"] | ||
} | ||
} | ||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
resource github_repository internal { | ||
name = "mtribes-jurgen" | ||
description = "A internal-visible repository created by Terraform" | ||
visibility = "internal" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output internal_repository { | ||
description = "Example repository JSON blob" | ||
value = github_repository.internal | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
provider github { | ||
owner = var.owner | ||
token = var.github_token | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
variable owner { | ||
description = "GitHub owner used to configure the provider" | ||
type = string | ||
} | ||
|
||
variable github_token { | ||
description = "GitHub access token used to configure the provider" | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -271,11 +271,6 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er | |||||||||||||||||||||||
repoReq := resourceGithubRepositoryObject(d) | ||||||||||||||||||||||||
owner := meta.(*Owner).name | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
// Auth issues (403 You need admin access to the organization before adding a repository to it.) | ||||||||||||||||||||||||
// are encountered when the resources is created with the visibility parameter. As | ||||||||||||||||||||||||
// resourceGithubRepositoryUpdate is called immediately after, this is subsequently corrected. | ||||||||||||||||||||||||
repoReq.Visibility = nil | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
repoName := repoReq.GetName() | ||||||||||||||||||||||||
ctx := context.Background() | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
@@ -462,8 +457,15 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er | |||||||||||||||||||||||
|
||||||||||||||||||||||||
repoReq := resourceGithubRepositoryObject(d) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
// The endpoint will throw an error if trying to PATCH with a visibility value that is the same | ||||||||||||||||||||||||
if !d.HasChange("visibility") { | ||||||||||||||||||||||||
if d.HasChange("visibility") { | ||||||||||||||||||||||||
// The endpoint will throw an error if this repo is being created and the old value is "" | ||||||||||||||||||||||||
o, n := d.GetChange("visibility") | ||||||||||||||||||||||||
log.Printf("[DEBUG] Old Value %v New Value %v", o, n) | ||||||||||||||||||||||||
if o.(string) == "" { | ||||||||||||||||||||||||
repoReq.Visibility = nil | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||
// The endpoint will throw an error if trying to PATCH with a visibility value that is the same | ||||||||||||||||||||||||
Comment on lines
+460
to
+468
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kfcampbell, if you're looking at this today, you might find this simplification useful. |
||||||||||||||||||||||||
repoReq.Visibility = nil | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this more general by pointing to docs in the repo?