@@ -43,24 +43,30 @@ var resourceGitLabProjectSchema = map[string]*schema.Schema{
4343 Type : schema .TypeString ,
4444 Optional : true ,
4545 DiffSuppressFunc : func (k , old , new string , d * schema.ResourceData ) bool {
46- // If the old default branch is empty, it means that the project does not
47- // have a default branch. This can only happen if the project does not have
48- // branches, i.e. it is an empty project. In that case it is useless to
49- // try setting a specific default branch (because no branch exists).
50- // This code will defer the setting of a default branch to a time when the
51- // project is no longer empty.
46+ // `old` is the current value on GitLab side
47+ // `new` is the value that Terraform plans to set there
48+
49+ log .Printf ("[DEBUG] default_branch DiffSuppressFunc old new" )
50+ log .Printf ("[DEBUG] (%T) %#v, (%T) %#v" , old , old , new , new )
51+
52+ // If there is no current default branch, it means that the project is
53+ // empty and does not have branches. Setting the default branch will fail
54+ // with 400 error. The check will defer the setting of a default branch
55+ // to a time when the repository is no longer empty.
5256 if old == "" {
57+ if new != "" {
58+ log .Printf ("[WARN] not setting default_branch %#v on empty repo" , new )
59+ }
5360 return true
5461 }
5562
56- // Once the initialize_with_readme attribute is set to true, Gitlab creates
57- // a master branch and sets it as default. If the Gitlab project resource
58- // doesn't have default_branch attribute specified, Terraform will
59- // force "master" => "" on the next run.
60- if v , ok := d .GetOk ("initialize_with_readme" ); ok {
61- if new == "" && v == true {
62- return true
63- }
63+ // For non-empty repositories GitLab automatically sets master as the
64+ // default branch. If the project resource doesn't specify default_branch
65+ // attribute, Terraform will force "master" => "" on the next run. This
66+ // check makes Terraform ignore default branch value until it is set in
67+ // .tf configuration. For schema.TypeString empty is equal to "".
68+ if new == "" {
69+ return true
6470 }
6571
6672 return old == new
0 commit comments