@@ -16,6 +16,7 @@ func resourceGitlabBranchProtection() *schema.Resource {
16
16
return & schema.Resource {
17
17
Create : resourceGitlabBranchProtectionCreate ,
18
18
Read : resourceGitlabBranchProtectionRead ,
19
+ Update : resourceGitlabBranchProtectionUpdate ,
19
20
Delete : resourceGitlabBranchProtectionDelete ,
20
21
Schema : map [string ]* schema.Schema {
21
22
"project" : {
@@ -43,7 +44,7 @@ func resourceGitlabBranchProtection() *schema.Resource {
43
44
"code_owner_approval_required" : {
44
45
Type : schema .TypeBool ,
45
46
Optional : true ,
46
- ForceNew : true ,
47
+ Computed : true ,
47
48
},
48
49
},
49
50
}
@@ -112,6 +113,30 @@ func resourceGitlabBranchProtectionRead(d *schema.ResourceData, meta interface{}
112
113
return nil
113
114
}
114
115
116
+ func resourceGitlabBranchProtectionUpdate (d * schema.ResourceData , meta interface {}) error {
117
+ // NOTE: At the time of writing, the only value that does not force re-creation is code_owner_approval_required,
118
+ // so therefore that is the only update that needs to be handled.
119
+
120
+ client := meta .(* gitlab.Client )
121
+ project := d .Get ("project" ).(string )
122
+ branch := d .Get ("branch" ).(string )
123
+ codeOwnerApprovalRequired := getOptionalBool (d , "code_owner_approval_required" )
124
+
125
+ log .Printf ("[DEBUG] update gitlab branch protection for project %s, branch %s" , project , branch )
126
+
127
+ options := & gitlab.RequireCodeOwnerApprovalsOptions {
128
+ CodeOwnerApprovalRequired : codeOwnerApprovalRequired ,
129
+ }
130
+
131
+ if _ , err := client .ProtectedBranches .RequireCodeOwnerApprovals (project , branch , options ); err != nil {
132
+ return err
133
+ }
134
+
135
+ d .SetId (buildTwoPartID (& project , & branch ))
136
+
137
+ return resourceGitlabBranchProtectionRead (d , meta )
138
+ }
139
+
115
140
func resourceGitlabBranchProtectionDelete (d * schema.ResourceData , meta interface {}) error {
116
141
client := meta .(* gitlab.Client )
117
142
project := d .Get ("project" ).(string )
0 commit comments