@@ -71,6 +71,11 @@ func resourceCDLResearchStudy() *schema.Resource {
7171 "data_scientist" : permissionSchema (),
7272 "monitor" : permissionSchema (),
7373 "uploader" : permissionSchema (),
74+ "data_protected_from_deletion" : {
75+ Type : schema .TypeBool ,
76+ Optional : true ,
77+ Default : false ,
78+ },
7479 },
7580 }
7681}
@@ -145,14 +150,16 @@ func resourceCDLResearchStudyCreate(ctx context.Context, d *schema.ResourceData,
145150 description := d .Get ("description" ).(string )
146151 endsAt := d .Get ("ends_at" ).(string )
147152 studyOwner := d .Get ("study_owner" ).(string )
153+ dataProtectedFromDeletion := d .Get ("data_protected_from_deletion" ).(bool )
148154
149155 createdStudy , resp , err := client .Study .CreateStudy (cdl.Study {
150156 Title : title ,
151157 Description : description ,
152158 Period : cdl.Period {
153159 End : endsAt ,
154160 },
155- StudyOwner : studyOwner ,
161+ StudyOwner : studyOwner ,
162+ DataProtectedFromDeletion : dataProtectedFromDeletion ,
156163 })
157164 if err != nil {
158165 if resp == nil {
@@ -169,6 +176,14 @@ func resourceCDLResearchStudyCreate(ctx context.Context, d *schema.ResourceData,
169176 matchFound := false
170177 for _ , study := range studies {
171178 if study .Title == title && study .StudyOwner == studyOwner { // TODO: check if this is sufficient for a good match
179+ if study .DataProtectedFromDeletion != dataProtectedFromDeletion ||
180+ study .Description != description ||
181+ study .Period .End != endsAt { // Update if needed
182+ study .DataProtectedFromDeletion = dataProtectedFromDeletion
183+ study .Description = description
184+ study .Period .End = endsAt
185+ _ , _ , _ = client .Study .UpdateStudy (study )
186+ }
172187 d .SetId (study .ID )
173188 matchFound = true
174189 break
@@ -266,11 +281,12 @@ func resourceCDLResearchStudyUpdate(_ context.Context, d *schema.ResourceData, m
266281 }
267282
268283 if d .HasChange ("title" ) || d .HasChange ("description" ) ||
269- d .HasChange ("ends_at" ) || d .HasChange ("study_owner" ) {
284+ d .HasChange ("ends_at" ) || d .HasChange ("study_owner" ) || d . HasChange ( "data_protected_from_deletion" ) {
270285 study .Title = d .Get ("title" ).(string )
271286 study .Description = d .Get ("description" ).(string )
272287 study .Period .End = d .Get ("ends_at" ).(string )
273288 study .StudyOwner = d .Get ("study_owner" ).(string )
289+ study .DataProtectedFromDeletion = d .Get ("data_protected_from_deletion" ).(bool )
274290
275291 _ , _ , err = client .Study .UpdateStudy (* study )
276292 if err != nil {
0 commit comments