Skip to content

Commit 56a8783

Browse files
committed
Implement 'data_protected_from_deletion'. Fixes #97
Signed-off-by: Andy Lo-A-Foe <andy.loafoe@gmail.com>
1 parent a41d85e commit 56a8783

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

docs/data-sources/cdl_research_study.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ In addition to all arguments above, the following attributes are exported:
3535
* `monitors` - The list of IAM users who have role MONITOR
3636
* `study_managers` - The list of IAM users who have role STUDYMANAGER
3737
* `research_scientists` - The list of IAM users who have role RESEARCHSCIENTIST
38+
* `data_protected_from_deletion` - Is data protected from deletion
3839

docs/resources/cdl_research_study.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ resource "hsdp_cdl_research_study" "study_a" {
4141
user_id = data.hsdp_iam_user.study_manager.id
4242
email = data.hsdp_iam_user.study_manager.email_address
4343
}
44+
45+
data_protected_from_deletion = false
4446
}
4547
```
4648

@@ -69,6 +71,7 @@ The following arguments are supported:
6971
* `user_id` (Required) The IAM user ID of the study manager
7072
* `email` - (Required) The email address for this study manager (for display purposes)
7173
* `institute_id` - (Optional) The institute ID associated with this role
74+
* `data_protected_from_deletion` (Optional) Protects data from being deleted. Default is `false`
7275

7376

7477
## Attributes Reference

hsdp/data_source_cdl_research_study.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func dataSourceCDLResearchStudy() *schema.Resource {
5858
Computed: true,
5959
Elem: &schema.Schema{Type: schema.TypeString},
6060
},
61+
"data_protected_from_deletion": {
62+
Type: schema.TypeBool,
63+
Computed: true,
64+
},
6165
},
6266
}
6367

@@ -125,6 +129,7 @@ func dataSourceCDLResearchStudyRead(_ context.Context, d *schema.ResourceData, m
125129
_ = d.Set("data_scientists", dataScientists)
126130
_ = d.Set("uploaders", uploaders)
127131
_ = d.Set("study_managers", studyManagers)
132+
_ = d.Set("data_protected_from_deletion", study.DataProtectedFromDeletion)
128133

129134
return diags
130135
}

hsdp/resource_cdl_research_study.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)