Skip to content
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

resource/repository: add create from template #309

Merged
merged 3 commits into from
Jan 14, 2020
Merged

Conversation

jcudit
Copy link
Contributor

@jcudit jcudit commented Dec 23, 2019

Overview

This PR adds the ability to create a repository using a repository template.

Fixes https://github.com/terraform-providers/terraform-provider-github/issues/254.

$ go test -v -timeout 30m  ./... -run TestAccGithubRepository_createFromTemplate
?   	github.com/terraform-providers/terraform-provider-github	[no test files]
=== RUN   TestAccGithubRepository_createFromTemplate
=== PAUSE TestAccGithubRepository_createFromTemplate
=== CONT  TestAccGithubRepository_createFromTemplate
--- PASS: TestAccGithubRepository_createFromTemplate (8.77s)
PASS
ok  	github.com/terraform-providers/terraform-provider-github/github	9.041s

NOTE: There is an outstanding FIXME that I've called out inline.

Progress

  • Update website/docs/r/repository.html.markdown
  • Add a new template configuration block
  • Call CreateFromTemplate when template configuration is present
  • Test creating a templated repo by verifying that isTemplate is true

@ghost ghost added size/L Type: Documentation Improvements or additions to documentation labels Dec 23, 2019

template {
# FIXME: Change this to something more suitable for CI runs
owner = "jcudit"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paultyng - If there is a better repository or organization to use, please let me know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally try to avoid hard-coding organization or user names into the test suite, because that prevents anyone outside of the current team of maintainers from running these tests as they wouldn't have access to that organization or user.

We can leverage environment variables:
https://github.com/terraform-providers/terraform-provider-github/blob/2c03b951bb0aadc56d5f3e9a254f464d5ee018b8/github/provider_test.go#L58-L66

In this case I suppose we could leverage GITHUB_ORGANIZATION and introduce a new variable, say GITHUB_TEMPLATE_REPOSITORY?

@jcudit jcudit marked this pull request as ready for review December 23, 2019 20:28
@jcudit jcudit self-assigned this Dec 23, 2019
Copy link
Contributor

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, I left you some comments inline. Feel free to request me directly for reviews in the future.

github/resource_github_repository.go Show resolved Hide resolved
github/resource_github_repository.go Outdated Show resolved Hide resolved
github/resource_github_repository.go Outdated Show resolved Hide resolved

template {
# FIXME: Change this to something more suitable for CI runs
owner = "jcudit"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally try to avoid hard-coding organization or user names into the test suite, because that prevents anyone outside of the current team of maintainers from running these tests as they wouldn't have access to that organization or user.

We can leverage environment variables:
https://github.com/terraform-providers/terraform-provider-github/blob/2c03b951bb0aadc56d5f3e9a254f464d5ee018b8/github/provider_test.go#L58-L66

In this case I suppose we could leverage GITHUB_ORGANIZATION and introduce a new variable, say GITHUB_TEMPLATE_REPOSITORY?

go.mod Outdated Show resolved Hide resolved
@jcudit
Copy link
Contributor Author

jcudit commented Jan 7, 2020

@radeksimko thanks for the wisdom so far. I've pushed a commit to address your feedback but am still working through build errors.

Following up on your suggestion around environment variable use:

  • Where can I supply environment variables for the CI builds? I checked the Travis CI UI and .travis.yml but could not find declarations for the existing variables that follow this pattern.
  • Is there a more suitable repository than jcudit/terraform-template-module that can be used during CI runs?

EDIT: After sleeping on it, it occurred to me that the acceptance tests are not run in CI. I will verify the change locally instead and push a couple of other documentation and logging edits before re-requesting review. Let me know if I’ve gotten this wrong.

@peimanja
Copy link

peimanja commented Jan 8, 2020

Really interested to see this PR get merged.

@radeksimko
Copy link
Contributor

@jcudit

After sleeping on it, it occurred to me that the acceptance tests are not run in CI.

We run acceptance tests for most providers (including GitHub) in TeamCity currently. Apologies if you were not briefed about this as part of our on-boarding process! 🙈

I sent you some details via Slack as the instance isn't available for public, although we do have some plans in that area (making acceptance testing more accessible and easier for all providers).

btw. We all internally use https://github.com/terraformtesting for these purposes - I also added you there as member, so you don't need to create any new org just to run these tests locally.

* 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
@jcudit
Copy link
Contributor Author

jcudit commented Jan 13, 2020

[TestAccGithubRepository_createFromTemplate] [Test Output]
=== RUN   TestAccGithubRepository_createFromTemplate
=== PAUSE TestAccGithubRepository_createFromTemplate
=== CONT  TestAccGithubRepository_createFromTemplate
--- PASS: TestAccGithubRepository_createFromTemplate (7.95s)
PASS

The associated acceptance test is now passing alongside the unit tests for this change. I will re-request review at this time.

@jcudit jcudit requested a review from radeksimko January 13, 2020 14:53
Copy link
Contributor

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

* Create two topics within the repo named `test-topic` and `second-test-topic`
* In the repo settings, make sure all features and merge button options are enabled.
* `test-repo-template`
* Configure the repository to be a [Template repository](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-template-repository)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for updating these instructions! ❤️

@jcudit jcudit merged commit bb46449 into master Jan 14, 2020
@jcudit jcudit deleted the template-repos branch January 14, 2020 18:15
jcudit pushed a commit that referenced this pull request Jan 14, 2020
jcudit pushed a commit that referenced this pull request Jan 14, 2020
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this pull request Jul 26, 2022
…-repos

resource/repository: add create from template
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this pull request Jul 26, 2022
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this pull request Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L Type: Documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Create repo from template repo
3 participants