@@ -30,6 +30,7 @@ type projectResourceModel struct {
30
30
Id types.String `tfsdk:"id"`
31
31
Name types.String `tfsdk:"name"`
32
32
Description types.String `tfsdk:"description"`
33
+ Mode types.String `tfsdk:"mode"`
33
34
}
34
35
35
36
// Configure adds the provider configured client to the data source.
@@ -69,6 +70,13 @@ func (r *projectResource) Schema(_ context.Context, _ resource.SchemaRequest, re
69
70
Description : "A description of the project's purpose." ,
70
71
Optional : true ,
71
72
},
73
+ "mode" : schema.StringAttribute {
74
+ Description : "The project's collaboration mode. Determines whether non project members can submit " +
75
+ "change requests and the projects visibility to non members. Valid values are 'open', 'protected' and 'private'." +
76
+ " If a value is not set, the project will default to 'open'" ,
77
+ Computed : true ,
78
+ Optional : true ,
79
+ },
72
80
},
73
81
}
74
82
}
@@ -104,8 +112,25 @@ func (r *projectResource) Create(ctx context.Context, req resource.CreateRequest
104
112
return
105
113
}
106
114
115
+ mode , err := resolveRequestedMode (plan )
116
+ if err != nil {
117
+ resp .Diagnostics .AddError (err .Error (), "InvalidMode" )
118
+ return
119
+ }
120
+
121
+ updateProjectSettingsRequest := * unleash .NewUpdateProjectEnterpriseSettingsSchemaWithDefaults ()
122
+ updateProjectSettingsRequest .SetMode (mode )
123
+
124
+ updateSettingsResponse , err := r .client .ProjectsAPI .UpdateProjectEnterpriseSettings (context .Background (), * plan .Id .ValueStringPointer ()).UpdateProjectEnterpriseSettingsSchema (updateProjectSettingsRequest ).Execute ()
125
+
126
+ if ! ValidateApiResponse (updateSettingsResponse , 200 , & resp .Diagnostics , err ) {
127
+ return
128
+ }
129
+
107
130
plan .Id = types .StringValue (project .Id )
108
131
plan .Name = types .StringValue (project .Name )
132
+ plan .Mode = types .StringValue (mode )
133
+
109
134
if project .Description .IsSet () {
110
135
plan .Description = types .StringValue (* project .Description .Get ())
111
136
} else {
@@ -147,6 +172,8 @@ func (r *projectResource) Read(ctx context.Context, req resource.ReadRequest, re
147
172
state .Id = types .StringValue (fmt .Sprintf ("%v" , project .Id ))
148
173
state .Name = types .StringValue (fmt .Sprintf ("%v" , project .Name ))
149
174
175
+ setModelMode (project .Mode , & state )
176
+
150
177
if project .Description .IsSet () && project .Description .Get () != nil {
151
178
state .Description = types .StringValue (* project .Description .Get ())
152
179
} else {
@@ -172,6 +199,21 @@ func (r *projectResource) Update(ctx context.Context, req resource.UpdateRequest
172
199
updateProjectSchema .Description = state .Description .ValueStringPointer ()
173
200
}
174
201
202
+ mode , err := resolveRequestedMode (state )
203
+ if err != nil {
204
+ resp .Diagnostics .AddError (err .Error (), "InvalidMode" )
205
+ return
206
+ }
207
+
208
+ updateProjectSettingsRequest := * unleash .NewUpdateProjectEnterpriseSettingsSchemaWithDefaults ()
209
+ updateProjectSettingsRequest .SetMode (mode )
210
+
211
+ updateSettingsResponse , err := r .client .ProjectsAPI .UpdateProjectEnterpriseSettings (context .Background (), * state .Id .ValueStringPointer ()).UpdateProjectEnterpriseSettingsSchema (updateProjectSettingsRequest ).Execute ()
212
+
213
+ if ! ValidateApiResponse (updateSettingsResponse , 200 , & resp .Diagnostics , err ) {
214
+ return
215
+ }
216
+
175
217
req .State .Get (ctx , & state )
176
218
177
219
api_response , err := r .client .ProjectsAPI .UpdateProject (ctx , state .Id .ValueString ()).UpdateProjectSchema (updateProjectSchema ).Execute ()
@@ -196,6 +238,8 @@ func (r *projectResource) Update(ctx context.Context, req resource.UpdateRequest
196
238
state .Id = types .StringValue (fmt .Sprintf ("%v" , project .Id ))
197
239
state .Name = types .StringValue (fmt .Sprintf ("%v" , project .Name ))
198
240
241
+ setModelMode (project .Mode , & state )
242
+
199
243
if project .Description .IsSet () {
200
244
state .Description = types .StringValue (* project .Description .Get ())
201
245
} else {
@@ -225,3 +269,25 @@ func (r *projectResource) Delete(ctx context.Context, req resource.DeleteRequest
225
269
resp .State .RemoveResource (ctx )
226
270
tflog .Debug (ctx , "Deleted item resource" , map [string ]any {"success" : true })
227
271
}
272
+
273
+ func setModelMode (mode * string , model * projectResourceModel ) {
274
+ if mode != nil {
275
+ model .Mode = types .StringValue (* mode )
276
+ } else {
277
+ // From checking the API spec I don't believe this actually can happen but this gives us a nice
278
+ // chance to have some backwards compatibility with older versions of the API where open was the only mode
279
+ model .Mode = types .StringValue ("open" )
280
+ }
281
+ }
282
+
283
+ func resolveRequestedMode (plan projectResourceModel ) (string , error ) {
284
+ if ! plan .Mode .IsNull () && plan .Mode .ValueString () != "" && plan .Mode .ValueString () != "open" && plan .Mode .ValueString () != "protected" && plan .Mode .ValueString () != "private" {
285
+ return "" , fmt .Errorf ("project mode must be unset or set to 'open', 'protected' or 'private'. Got: '%s'" , plan .Mode .ValueString ())
286
+ }
287
+
288
+ if ! plan .Mode .IsNull () && plan .Mode .ValueString () != "" {
289
+ return plan .Mode .ValueString (), nil
290
+ } else {
291
+ return "open" , nil
292
+ }
293
+ }
0 commit comments