-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
AWS: codecommit set default_branch only if defined #5904
AWS: codecommit set default_branch only if defined #5904
Conversation
b42b4d3
to
77f6a31
Compare
@@ -104,7 +104,7 @@ func resourceAwsCodeCommitRepositoryCreate(d *schema.ResourceData, meta interfac | |||
func resourceAwsCodeCommitRepositoryUpdate(d *schema.ResourceData, meta interface{}) error { | |||
conn := meta.(*AWSClient).codecommitconn | |||
|
|||
if d.HasChange("default_branch") { | |||
if d.HasChange("default_branch") && len(d.Get("default_branch").(string)) > 0 { |
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.
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.
Not sure what you mean, because length bigger than 0 means the same than checking non-empty string.
Anyway, checking other code in terraform I found other examples where they use the method d.GetOK()
, so I refactored it to use that.
77f6a31
to
165b338
Compare
I also added a commit to check the remote repository before updating the default branch. If the default branch remotely is nil, that means that the repository has no branches and any branch update will fail. Effectively this means that |
@keymon thanks for the changes Will run some tests on this now before the merge :) |
@stack72 Hi. Thx, I have just added some tests around this. I wanted to test the case of creating a branch, but the only way to create a branch is using git itself to push. That is more complicated, I need to create credentials, a user, and depend on external commands. Are happy with this implementation and without a full test? |
@keymon thanks for adding the tests :) These are a useful addition and will be good! |
Do not try to update or reaad the AWS codecommit repository default branch if the resource definition is not set it or is an empty string. Fixes hashicorp#5641
In AWS codecommit the default branch must have a value unless there are no branches created, in which case it is not possible to set it to any value. We query the existing branches and do not update the default branch if there are none defined remotely. This solves the issue of the initial creation of the repository with a resource with `default_branch` defined.
The provider should, when working on a new repository without branches: * Able to create a new repository even with default_branch defined. * Able to create a new repository without default_branch, and do not fail if default_branch is defined.
@stack72 great, thank you. I will do a last update, to list the remote branches instead checking the remote default branch, and remove the [WIP]. |
dce658b
to
29c9b84
Compare
@keymon just give me a shout when you want me to re-run the tests pending merge |
@stack72 Please, go ahead, I won't touch it again. 👍 😄 |
Thanks @keymon - tests look great :)
|
Thx for merging. Only FYI and reference. I paste here some "manual acceptance tests cases" which I did not include, as commented, due the overhead of the required scaffolding (git, credentials, etc). Given this config:
|
Nice! This is a good indication of the fact it is working :) |
This isn't as big a jump as this individual commit suggests because we were already using a pre-release version of 0.6.15 in 57cc1a9. We are upgrading so that we no longer need to build from source to benefit from these fixes: - hashicorp/terraform#5774 - hashicorp/terraform#5904 The CHANGELOG doesn't mention any backwards-incompatible changes. New checksum has been taken from: - https://releases.hashicorp.com/terraform/0.6.15/terraform_0.6.15_SHA256SUMS
This isn't as big a jump as this individual commit suggests because we were already using a pre-release version of 0.6.15 in 57cc1a9. We are upgrading so that we no longer need to build from source to benefit from these fixes: - hashicorp/terraform#5774 - hashicorp/terraform#5904 The CHANGELOG doesn't mention any backwards-incompatible changes. New checksum has been taken from: - https://releases.hashicorp.com/terraform/0.6.15/terraform_0.6.15_SHA256SUMS
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Do not try to update the AWS codecommit repository default branch if the resource definition does not set it or is an empty string.
Fixes #5641
Note: Not sure if this is the best approach to handle the issue, as terraform reports changes all time. But it does not crash. Comments?