Skip to content

Commit

Permalink
Merge pull request #31544 from sdevope/b-29456-aws_fsx_ontap_volume-t…
Browse files Browse the repository at this point in the history
…ype-variable

FSx ONTAP volume - ontap_volume_type shouldn't be computed
  • Loading branch information
ewbankkit authored May 30, 2023
2 parents e29ffea + 8c4f52a commit fe4e3c9
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 100 deletions.
27 changes: 27 additions & 0 deletions .changelog/31544.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
```release-note:enhancement
resource/aws_fsx_ontap_volume: Update `ontap_volume_type` attribute to be configurable
```

```release-note:enhancement
resource/aws_fsx_ontap_volume: `junction_path` is Optional
```

```release-note:enhancement
resource/aws_fsx_ontap_volume: Remove default value for `security_style` argument and mark as Computed
```

```release-note:enhancement
resource/aws_fsx_ontap_volume: `storage_efficiency_enabled` is Optional
```

```release-note:bug
resource/aws_fsx_ontap_volume: Change `volume_type` to [ForceNew](https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-behaviors#forcenew)
```

```release-note:enhancement
resource/aws_fsx_ontap_volume: Add `skip_final_backup` argument
```

```release-note:bug
resource/aws_fsx_ontap_volume: Change `storage_virtual_machine_id` to [ForceNew](https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-behaviors#forcenew)
```
70 changes: 49 additions & 21 deletions internal/service/fsx/ontap_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ func ResourceOntapVolume() *schema.Resource {
ReadWithoutTimeout: resourceOntapVolumeRead,
UpdateWithoutTimeout: resourceOntapVolumeUpdate,
DeleteWithoutTimeout: resourceOntapVolumeDelete,

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

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

Timeouts: &schema.ResourceTimeout{
Expand All @@ -53,7 +58,7 @@ func ResourceOntapVolume() *schema.Resource {
},
"junction_path": {
Type: schema.TypeString,
Required: true,
Optional: true,
ValidateFunc: validation.StringLenBetween(1, 255),
},
"name": {
Expand All @@ -63,27 +68,36 @@ func ResourceOntapVolume() *schema.Resource {
ValidateFunc: validation.StringLenBetween(1, 203),
},
"ontap_volume_type": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(fsx.InputOntapVolumeType_Values(), false),
},
"security_style": {
Type: schema.TypeString,
Optional: true,
Default: "UNIX",
Computed: true,
ValidateFunc: validation.StringInSlice(fsx.StorageVirtualMachineRootVolumeSecurityStyle_Values(), false),
},
"size_in_megabytes": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(0, 2147483647),
},
"skip_final_backup": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"storage_efficiency_enabled": {
Type: schema.TypeBool,
Required: true,
Optional: true,
},
"storage_virtual_machine_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(21, 21),
},
"tiering_policy": {
Expand Down Expand Up @@ -115,8 +129,9 @@ func ResourceOntapVolume() *schema.Resource {
},
"volume_type": {
Type: schema.TypeString,
Default: fsx.VolumeTypeOntap,
Optional: true,
ForceNew: true,
Default: fsx.VolumeTypeOntap,
ValidateFunc: validation.StringInSlice(fsx.VolumeType_Values(), false),
},
},
Expand All @@ -128,36 +143,47 @@ func resourceOntapVolumeCreate(ctx context.Context, d *schema.ResourceData, meta
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).FSxConn()

name := d.Get("name").(string)
input := &fsx.CreateVolumeInput{
Name: aws.String(d.Get("name").(string)),
VolumeType: aws.String(d.Get("volume_type").(string)),
Name: aws.String(name),
OntapConfiguration: &fsx.CreateOntapVolumeConfiguration{
JunctionPath: aws.String(d.Get("junction_path").(string)),
SizeInMegabytes: aws.Int64(int64(d.Get("size_in_megabytes").(int))),
StorageEfficiencyEnabled: aws.Bool(d.Get("storage_efficiency_enabled").(bool)),
StorageVirtualMachineId: aws.String(d.Get("storage_virtual_machine_id").(string)),
SizeInMegabytes: aws.Int64(int64(d.Get("size_in_megabytes").(int))),
StorageVirtualMachineId: aws.String(d.Get("storage_virtual_machine_id").(string)),
},
Tags: GetTagsIn(ctx),
Tags: GetTagsIn(ctx),
VolumeType: aws.String(d.Get("volume_type").(string)),
}

if v, ok := d.GetOk("junction_path"); ok {
input.OntapConfiguration.JunctionPath = aws.String(v.(string))
}

if v, ok := d.GetOk("ontap_volume_type"); ok {
input.OntapConfiguration.OntapVolumeType = aws.String(v.(string))
}

if v, ok := d.GetOk("security_style"); ok {
input.OntapConfiguration.SecurityStyle = aws.String(v.(string))
}

if v, ok := d.GetOkExists("storage_efficiency_enabled"); ok {
input.OntapConfiguration.StorageEfficiencyEnabled = aws.Bool(v.(bool))
}

if v, ok := d.GetOk("tiering_policy"); ok {
input.OntapConfiguration.TieringPolicy = expandOntapVolumeTieringPolicy(v.([]interface{}))
}

result, err := conn.CreateVolumeWithContext(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating FSx Volume: %s", err)
return sdkdiag.AppendErrorf(diags, "creating FSx ONTAP Volume (%s): %s", name, err)
}

d.SetId(aws.StringValue(result.Volume.VolumeId))

if _, err := waitVolumeCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for FSx Volume(%s) create: %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "waiting for FSx ONTAP Volume (%s) create: %s", d.Id(), err)
}

return append(diags, resourceOntapVolumeRead(ctx, d, meta)...)
Expand All @@ -181,7 +207,7 @@ func resourceOntapVolumeRead(ctx context.Context, d *schema.ResourceData, meta i

ontapConfig := volume.OntapConfiguration
if ontapConfig == nil {
return sdkdiag.AppendErrorf(diags, "describing FSx ONTAP Volume (%s): empty ONTAP configuration", d.Id())
return sdkdiag.AppendErrorf(diags, "reading FSx ONTAP Volume (%s): empty ONTAP configuration", d.Id())
}

d.Set("arn", volume.ResourceARN)
Expand All @@ -193,12 +219,11 @@ func resourceOntapVolumeRead(ctx context.Context, d *schema.ResourceData, meta i
d.Set("size_in_megabytes", ontapConfig.SizeInMegabytes)
d.Set("storage_efficiency_enabled", ontapConfig.StorageEfficiencyEnabled)
d.Set("storage_virtual_machine_id", ontapConfig.StorageVirtualMachineId)
d.Set("uuid", ontapConfig.UUID)
d.Set("volume_type", volume.VolumeType)

if err := d.Set("tiering_policy", flattenOntapVolumeTieringPolicy(ontapConfig.TieringPolicy)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting tiering_policy: %s", err)
}
d.Set("uuid", ontapConfig.UUID)
d.Set("volume_type", volume.VolumeType)

return diags
}
Expand All @@ -210,8 +235,8 @@ func resourceOntapVolumeUpdate(ctx context.Context, d *schema.ResourceData, meta
if d.HasChangesExcept("tags_all", "tags") {
input := &fsx.UpdateVolumeInput{
ClientRequestToken: aws.String(id.UniqueId()),
VolumeId: aws.String(d.Id()),
OntapConfiguration: &fsx.UpdateOntapVolumeConfiguration{},
VolumeId: aws.String(d.Id()),
}

if d.HasChange("junction_path") {
Expand Down Expand Up @@ -254,6 +279,9 @@ func resourceOntapVolumeDelete(ctx context.Context, d *schema.ResourceData, meta

log.Printf("[DEBUG] Deleting FSx ONTAP Volume: %s", d.Id())
_, err := conn.DeleteVolumeWithContext(ctx, &fsx.DeleteVolumeInput{
OntapConfiguration: &fsx.DeleteVolumeOntapConfiguration{
SkipFinalBackup: aws.Bool(d.Get("skip_final_backup").(bool)),
},
VolumeId: aws.String(d.Id()),
})

Expand Down
Loading

0 comments on commit fe4e3c9

Please sign in to comment.