-
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
Add deployment policy resource #1530
Conversation
@kfcampbell I put this one up for early (tested locally via the new folder in examples and works as expected) review because, as mentioned in #922 I'm not a go expert 😅. Tests will follow soon. |
@limax the approach for documentation is manual unfortunately. The idea is to create a new .html.markdown file and link it in the github.erb file; you should be able to follow the pattern from other resources. Please let me know if you're having issues! |
Hey @ilmax are you still interested in getting your changes wrapped up here? We'd be glad to review them when ready! Also, let us know if you need more information on how to build out the docs for your change. Thanks again for making our community better by being involved! ❤️ |
Hey @nickfloyd sorry for the delay but didn't had time recently to move forward in this one, is still on my radar and I plan to finish it within next week. Sorry for the delay! |
@kfcampbell @nickfloyd I think this may be ready for review |
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.
I had a couple questions I'd like to hear about before getting this in. The tests and examples look good, thanks!
Read: resourceGithubRepositoryEnvironmentDeploymentPolicyRead, | ||
Update: resourceGithubRepositoryEnvironmentDeploymentPolicyUpdate, | ||
Delete: resourceGithubRepositoryEnvironmentDeploymentPolicyDelete, | ||
Schema: map[string]*schema.Schema{ |
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.
It looks like Import isn't implemented here. Is that an intentional omission?
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.
Preamble: Not an expert in implementing a terraform provider.
The GitHub api that exposes a get deployment branch policy requires an ID, this ID is not exposed anywhere in the UI so the user has no way (unless it's queries the GitHub api) to know such ID.
One option I was thinking about was to read all the deployment branch policies and then filter by branch pattern but I thought such an implementation to be overkill, especially because this resource only contains a branch name.
What are your thoughts?
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.
I think it's still worth implementing with an ID even if it's not clearly visible in the GitHub UI; there's still value in it.
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.
I just implemented support for import
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { |
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.
Confirming that integration tests are passing for me locally; thank you for the attention to testing.
Hey, @ilmax Let us know your thoughts on the questions from @kfcampbell and we'll get this merged in. Thanks again for the work here ❤️ |
Hey @nickfloyd sorry for the late reply, replied to the questions |
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.
Just some formatting suggestions :) would love to see this in the provider soon so I can get rid of my local-exec
cli step!
Hi, would you mind sharing your local-exec code? |
- Add the initial code to manage the resource - Add sample configuration used to test it TODO - Documentation - Tests
5e7b5a6
to
35321df
Compare
@kfcampbell @nickfloyd I implemented the import, removed the extra sample and rebased the PR, mind you taking another look? Thanks |
Sure @ivan-santos-eq, here you go: resource "github_repository_environment" "all" {
for_each = local.branches_and_envs
repository = local.repository_name
environment = each.value
deployment_branch_policy {
custom_branch_policies = true
protected_branches = false
}
# TODO: remove when https://github.com/integrations/terraform-provider-github/pull/1530 is merged
provisioner "local-exec" {
command = <<EOF
curl https://api.github.com/repos/${var.github_owner}/${local.repository_name}/environments/${each.value}/deployment-branch-policies \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer ${var.github_access_token}" \
-d '{"name":"${each.key}"}'
EOF
}
depends_on = [
github_repository.app
]
} |
Hello @kfcampbell @nickfloyd did you had a chance to review this one? |
@ilmax 😭 😭 😭 the tests are now failing for me with the following error:
I would imagine that there's supposed to be a value in between "for was" that describes a specific property, though I'm not sure how we ended up in this situation. Any thoughts? |
I'll try to look into this soon |
Is this still ongoing or stale? |
Hi, do you need help with getting it over the finish line? |
@kfcampbell @jjgriff93 @nickfloyd had some time and investigated. The issue was due to some double encoding of the I opened a PR containing the original author's work and my fix on top of it. Feel free to review and let me know if something else is needed. PR: #1799 |
Resolves #922
Behavior
Before the change?
Not possible to set environment deployment branch policies
After the change?
You can to set environment deployment branch policies
Other information
N/A
Additional info
Pull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!
Type: Breaking change
label)If
Yes
, what's the impact:Pull request type
Please add the corresponding label for change this PR introduces:
Type: Bug
Type: Feature
Type: Documentation
Type: Maintenance