@@ -38,25 +38,28 @@ var resourceGitLabProjectSchema = map[string]*schema.Schema{
3838 "default_branch" : {
3939 Type : schema .TypeString ,
4040 Optional : true ,
41- DiffSuppressFunc : func (k , old , new string , d * schema.ResourceData ) bool {
42- // If the old default branch is empty, it means that the project does not
43- // have a default branch. This can only happen if the project does not have
44- // branches, i.e. it is an empty project. In that case it is useless to
45- // try setting a specific default branch (because no branch exists).
46- // This code will defer the setting of a default branch to a time when the
47- // project is no longer empty.
41+ DiffSuppressFunc : func (k , current , planned string , d * schema.ResourceData ) bool {
42+ old := current
43+ new := planned
44+
45+ log .Printf ("[DEBUG] default_branch DiffSuppressFunc old new" )
46+ log .Printf ("[DEBUG] (%T) %#v, (%T) %#v" , old , old , new , new )
47+
48+ // If there is no current default branch, it means that the project is
49+ // empty and does not have branches. Setting the default branch will fail
50+ // with 400 error. The check will defer the setting of a default branch
51+ // to a time when the repository is no longer empty.
4852 if old == "" {
4953 return true
5054 }
5155
52- // Once the initialize_with_readme attribute is set to true, Gitlab creates
53- // a master branch and sets it as default. If the Gitlab project resource
54- // doesn't have default_branch attribute specified, Terraform will
55- // force "master" => "" on the next run.
56- if v , ok := d .GetOk ("initialize_with_readme" ); ok {
57- if new == "" && v == true {
58- return true
59- }
56+ // For non-empty repositories GitLab automatically sets master as the
57+ // default branch. If the project resource doesn't specify default_branch
58+ // attribute, Terraform will force "master" => "" on the next run. This
59+ // check makes Terraform ignore default branch value until it is set in
60+ // .tf configuration. For schema.TypeString empty is equal to "".
61+ if new == "" {
62+ return true
6063 }
6164
6265 return old == new
0 commit comments