Skip to content

Commit

Permalink
feat: Add delete config args to aws_fsx_[lustre|openzfs|windows]_file…
Browse files Browse the repository at this point in the history
…_system resources
  • Loading branch information
acwwat committed May 26, 2024
1 parent 250de7d commit 6d4adcd
Show file tree
Hide file tree
Showing 10 changed files with 820 additions and 194 deletions.
9 changes: 9 additions & 0 deletions .changelog/37717.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```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
```
93 changes: 88 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,32 @@ func resourceLustreFileSystem() *schema.Resource {
validation.StringMatch(regexache.MustCompile(`^[0-9].[0-9]+$`), "must be in format x.y"),
),
},
"final_backup_tags": {
Type: schema.TypeSet,
Optional: true,
MinItems: 1,
MaxItems: 50,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
names.AttrKey: {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 128),
validation.StringMatch(regexache.MustCompile(`^([\p{L}\p{Z}\p{N}_.:/=+\-@]*)$`), "must be a valid tag key"),
),
},
names.AttrValue: {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(0, 128),
validation.StringMatch(regexache.MustCompile(`^([\p{L}\p{Z}\p{N}_.:/=+\-@]*)$`), "must be a valid tag value"),
),
},
},
},
},
"import_path": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -238,6 +268,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 @@ -491,7 +526,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 @@ -557,10 +597,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 {
lustreConfig.FinalBackupTags = expandFinalBackupTags(v.(*schema.Set))
}

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 All @@ -577,6 +634,32 @@ func resourceLustreFileSystemDelete(ctx context.Context, d *schema.ResourceData,
return diags
}

func expandFinalBackupTags(cfg *schema.Set) []*fsx.Tag {
tags := []*fsx.Tag{}

for _, tag := range cfg.List() {
expandedTag := expandFinalBackupTag(tag.(map[string]interface{}))
if expandedTag != nil {
tags = append(tags, expandedTag)
}
}

return tags
}

func expandFinalBackupTag(cfg map[string]interface{}) *fsx.Tag {
out := fsx.Tag{}

if v, ok := cfg[names.AttrKey].(string); ok {
out.Key = aws.String(v)
}
if v, ok := cfg[names.AttrValue].(string); ok {
out.Value = aws.String(v)
}

return &out
}

func expandLustreRootSquashConfiguration(l []interface{}) *fsx.LustreRootSquashConfiguration {
if len(l) == 0 || l[0] == nil {
return nil
Expand Down
Loading

0 comments on commit 6d4adcd

Please sign in to comment.