Skip to content

Commit

Permalink
Merge pull request #37717 from acwwat/f-aws_fsx_file_systems-add_dele…
Browse files Browse the repository at this point in the history
…te_config

feat: Add delete config args to aws_fsx_[lustre|openzfs|windows]_file_system and aws_fsx_ontap_volume
  • Loading branch information
ewbankkit authored Jul 18, 2024
2 parents 8675eee + 7617d14 commit 47c482c
Show file tree
Hide file tree
Showing 13 changed files with 863 additions and 250 deletions.
12 changes: 12 additions & 0 deletions .changelog/37717.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```release-note:enhancement
resource/aws_fsx_lustre_file_system: Add `final_backup_tags` and `skip_final_backup` arguments
```
```release-note:enhancement
resource/aws_fsx_openzfs_file_system: Add `delete_options` and `final_backup_tags` arguments
```
```release-note:enhancement
resource/aws_fsx_windows_file_system: Add `final_backup_tags` argument
```
```release-note:enhancement
resource/aws_fsx_ontap_volume: Add `final_backup_tags` argument
```
42 changes: 37 additions & 5 deletions internal/service/fsx/lustre_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ func resourceLustreFileSystem() *schema.Resource {
DeleteWithoutTimeout: resourceLustreFileSystemDelete,

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
StateContext: func(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
d.Set("skip_final_backup", true)

return []*schema.ResourceData{d}, nil
},
},

Timeouts: &schema.ResourceTimeout{
Expand Down Expand Up @@ -131,6 +135,7 @@ func resourceLustreFileSystem() *schema.Resource {
validation.StringMatch(regexache.MustCompile(`^[0-9].[0-9]+$`), "must be in format x.y"),
),
},
"final_backup_tags": tftags.TagsSchema(),
"import_path": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -260,6 +265,11 @@ func resourceLustreFileSystem() *schema.Resource {
MaxItems: 50,
Elem: &schema.Schema{Type: schema.TypeString},
},
"skip_final_backup": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"storage_capacity": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -567,7 +577,12 @@ func resourceLustreFileSystemUpdate(ctx context.Context, d *schema.ResourceData,
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).FSxConn(ctx)

if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) {
if d.HasChangesExcept(
"final_backup_tags",
"skip_final_backup",
names.AttrTags,
names.AttrTagsAll,
) {
input := &fsx.UpdateFileSystemInput{
ClientRequestToken: aws.String(id.UniqueId()),
FileSystemId: aws.String(d.Id()),
Expand Down Expand Up @@ -637,10 +652,27 @@ func resourceLustreFileSystemDelete(ctx context.Context, d *schema.ResourceData,
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).FSxConn(ctx)

input := &fsx.DeleteFileSystemInput{
ClientRequestToken: aws.String(id.UniqueId()),
FileSystemId: aws.String(d.Id()),
}

// Final backup during delete is not supported on file systems using the Scratch deployment type
// LustreConfiguration cannot be supplied at all, even when empty, in this scenario
if v, ok := d.GetOk("deployment_type"); ok && !strings.HasPrefix(v.(string), "SCRATCH_") {
lustreConfig := &fsx.DeleteFileSystemLustreConfiguration{
SkipFinalBackup: aws.Bool(d.Get("skip_final_backup").(bool)),
}

if v, ok := d.GetOk("final_backup_tags"); ok && len(v.(map[string]interface{})) > 0 {
lustreConfig.FinalBackupTags = Tags(tftags.New(ctx, v))
}

input.LustreConfiguration = lustreConfig
}

log.Printf("[DEBUG] Deleting FSx for Lustre File System: %s", d.Id())
_, err := conn.DeleteFileSystemWithContext(ctx, &fsx.DeleteFileSystemInput{
FileSystemId: aws.String(d.Id()),
})
_, err := conn.DeleteFileSystemWithContext(ctx, input)

if tfawserr.ErrCodeEquals(err, fsx.ErrCodeFileSystemNotFound) {
return diags
Expand Down
Loading

0 comments on commit 47c482c

Please sign in to comment.