Skip to content

Commit

Permalink
Merge pull request #33466 from hashicorp/f-aws_fsx_ontap_file_system-…
Browse files Browse the repository at this point in the history
…additions

r/aws_fsx_ontap_storage_virtual_machine: In-place update of all `active_directory_configuration` attributes
  • Loading branch information
ewbankkit committed Sep 19, 2023
2 parents d6517bb + d9afb34 commit e35e78d
Show file tree
Hide file tree
Showing 27 changed files with 744 additions and 693 deletions.
7 changes: 7 additions & 0 deletions .changelog/33466.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_fsx_ontap_storage_virtual_machine: Remove [ForceNew](https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-behaviors#forcenew) from `active_directory_configuration.self_managed_active_directory_configuration.domain_name`, `active_directory_configuration.self_managed_active_directory_configuration.file_system_administrators_group` and `active_directory_configuration.self_managed_active_directory_configuration.organizational_unit_distinguished_name` allowing an SVM to join AD after creation
```

```release-note:bug
resource/aws_fsx_ontap_storage_virtual_machine: Avoid recreating resource when `active_directory_configuration.self_managed_active_directory_configuration.file_system_administrators_group` is configured
```
36 changes: 15 additions & 21 deletions internal/service/athena/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/athena"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
)
Expand All @@ -34,48 +33,43 @@ func sweepDatabases(region string) error {
input := &athena.ListDatabasesInput{
CatalogName: aws.String("AwsDataCatalog"),
}
var errs *multierror.Error

sweepResources := make([]sweep.Sweepable, 0)
for {
output, err := conn.ListDatabasesWithContext(ctx, input)

for _, v := range output.DatabaseList {
err = conn.ListDatabasesPagesWithContext(ctx, input, func(page *athena.ListDatabasesOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, v := range page.DatabaseList {
name := aws.StringValue(v.Name)
if name == "default" {
continue
}
r := ResourceDatabase()
d := r.Data(nil)
d.SetId(name)

if err != nil {
err := fmt.Errorf("error listing Athena Databases (%s): %w", name, err)
log.Printf("[ERROR] %s", err)
errs = multierror.Append(errs, err)
continue
}
d.Set("force_destroy", true)

sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client))
}

if aws.StringValue(output.NextToken) == "" {
break
}

input.NextToken = output.NextToken
}
return !lastPage
})

if sweep.SkipSweepError(err) {
log.Printf("[WARN] Skipping Athena Database sweep for %s: %s", region, err)
return nil
}

if err != nil {
return fmt.Errorf("error listing Athena Databases (%s): %w", region, err)
}

err = sweep.SweepOrchestrator(ctx, sweepResources)

if err != nil {
errs = multierror.Append(errs, fmt.Errorf("error sweeping Athena Databases (%s): %w", region, err))
return fmt.Errorf("error sweeping Athena Databases (%s): %w", region, err)
}

return errs.ErrorOrNil()
return nil
}
2 changes: 2 additions & 0 deletions internal/service/cloudformation/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func sweepStackSetInstances(region string) error {
aws.StringValue(summary.Region),
)
d.SetId(id)
d.Set("call_as", "SELF")

sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client))
}
Expand Down Expand Up @@ -135,6 +136,7 @@ func sweepStackSets(region string) error {
r := ResourceStackSet()
d := r.Data(nil)
d.SetId(aws.StringValue(summary.StackSetName))
d.Set("call_as", "SELF")

sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client))
}
Expand Down
5 changes: 3 additions & 2 deletions internal/service/codestarconnections/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/codestarconnections"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
"github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2"
)

func init() {
Expand Down Expand Up @@ -45,7 +46,7 @@ func sweepConnections(region string) error {
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

if sweep.SkipSweepError(err) {
if awsv2.SkipSweepError(err) {
log.Printf("[WARN] Skipping CodeStar Connections Connection sweep for %s: %s", region, err)
return nil
}
Expand Down Expand Up @@ -86,7 +87,7 @@ func sweepHosts(region string) error {
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

if sweep.SkipSweepError(err) {
if awsv2.SkipSweepError(err) {
log.Printf("[WARN] Skipping CodeStar Connections Host sweep for %s: %s", region, err)
return nil
}
Expand Down
7 changes: 6 additions & 1 deletion internal/service/cur/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
cur "github.com/aws/aws-sdk-go/service/costandusagereportservice"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
"github.com/hashicorp/terraform-provider-aws/names"
)

func init() {
Expand All @@ -25,6 +26,10 @@ func init() {

func sweepReportDefinitions(region string) error {
ctx := sweep.Context(region)
if region != names.USEast1RegionID {
log.Printf("[WARN] Skipping Cost And Usage Report Definition sweep for region: %s", region)
return nil
}
client, err := sweep.SharedRegionalSweepClient(ctx, region)
if err != nil {
return fmt.Errorf("error getting client: %s", err)
Expand All @@ -50,7 +55,7 @@ func sweepReportDefinitions(region string) error {
})

if sweep.SkipSweepError(err) {
log.Printf("[WARN] Skipping EC2 Cost And Usage Report Definition sweep for %s: %s", region, err)
log.Printf("[WARN] Skipping Cost And Usage Report Definition sweep for %s: %s", region, err)
return nil
}
if err != nil {
Expand Down
39 changes: 0 additions & 39 deletions internal/service/fsx/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,45 +71,6 @@ func findFileCacheByID(ctx context.Context, conn *fsx.FSx, id string) (*fsx.File
return fileCaches[0], nil
}

func FindStorageVirtualMachineByID(ctx context.Context, conn *fsx.FSx, id string) (*fsx.StorageVirtualMachine, error) {
input := &fsx.DescribeStorageVirtualMachinesInput{
StorageVirtualMachineIds: []*string{aws.String(id)},
}

var storageVirtualMachines []*fsx.StorageVirtualMachine

err := conn.DescribeStorageVirtualMachinesPagesWithContext(ctx, input, func(page *fsx.DescribeStorageVirtualMachinesOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

storageVirtualMachines = append(storageVirtualMachines, page.StorageVirtualMachines...)

return !lastPage
})

if tfawserr.ErrCodeEquals(err, fsx.ErrCodeStorageVirtualMachineNotFound) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if len(storageVirtualMachines) == 0 || storageVirtualMachines[0] == nil {
return nil, tfresource.NewEmptyResultError(input)
}

if count := len(storageVirtualMachines); count > 1 {
return nil, tfresource.NewTooManyResultsError(count, input)
}

return storageVirtualMachines[0], nil
}

func FindSnapshotByID(ctx context.Context, conn *fsx.FSx, id string) (*fsx.Snapshot, error) {
input := &fsx.DescribeSnapshotsInput{
SnapshotIds: aws.StringSlice([]string{id}),
Expand Down
52 changes: 8 additions & 44 deletions internal/service/fsx/lustre_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,10 @@ func resourceLustreFileSystemUpdate(ctx context.Context, d *schema.ResourceData,
conn := meta.(*conns.AWSClient).FSxConn(ctx)

if d.HasChangesExcept("tags", "tags_all") {
waitAdminAction := false
input := &fsx.UpdateFileSystemInput{
ClientRequestToken: aws.String(id.UniqueId()),
LustreConfiguration: &fsx.UpdateFileSystemLustreConfiguration{},
FileSystemId: aws.String(d.Id()),
LustreConfiguration: &fsx.UpdateFileSystemLustreConfiguration{},
}

if d.HasChange("auto_import_policy") {
Expand All @@ -517,12 +516,10 @@ func resourceLustreFileSystemUpdate(ctx context.Context, d *schema.ResourceData,

if d.HasChange("log_configuration") {
input.LustreConfiguration.LogConfiguration = expandLustreLogCreateConfiguration(d.Get("log_configuration").([]interface{}))
waitAdminAction = true
}

if d.HasChange("root_squash_configuration") {
input.LustreConfiguration.RootSquashConfiguration = expandLustreRootSquashConfiguration(d.Get("root_squash_configuration").([]interface{}))
waitAdminAction = true
}

if d.HasChange("storage_capacity") {
Expand All @@ -544,10 +541,8 @@ func resourceLustreFileSystemUpdate(ctx context.Context, d *schema.ResourceData,
return sdkdiag.AppendErrorf(diags, "waiting for FSx for Lustre File System (%s) update: %s", d.Id(), err)
}

if waitAdminAction {
if _, err := waitAdministrativeActionCompleted(ctx, conn, d.Id(), fsx.AdministrativeActionTypeFileSystemUpdate, d.Timeout(schema.TimeoutUpdate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for FSx for Lustre File System (%s) administrative action (%s) complete: %s", d.Id(), fsx.AdministrativeActionTypeFileSystemUpdate, err)
}
if _, err := waitAdministrativeActionCompleted(ctx, conn, d.Id(), fsx.AdministrativeActionTypeFileSystemUpdate, d.Timeout(schema.TimeoutUpdate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for FSx for Lustre File System (%s) administrative action (%s) complete: %s", d.Id(), fsx.AdministrativeActionTypeFileSystemUpdate, err)
}
}

Expand Down Expand Up @@ -663,43 +658,12 @@ func logStateFunc(v interface{}) string {
return value
}

func FindFileSystemByID(ctx context.Context, conn *fsx.FSx, id string) (*fsx.FileSystem, error) {
func findFileSystemByID(ctx context.Context, conn *fsx.FSx, id string) (*fsx.FileSystem, error) {
input := &fsx.DescribeFileSystemsInput{
FileSystemIds: []*string{aws.String(id)},
}

var filesystems []*fsx.FileSystem

err := conn.DescribeFileSystemsPagesWithContext(ctx, input, func(page *fsx.DescribeFileSystemsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

filesystems = append(filesystems, page.FileSystems...)

return !lastPage
})

if tfawserr.ErrCodeEquals(err, fsx.ErrCodeFileSystemNotFound) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if len(filesystems) == 0 || filesystems[0] == nil {
return nil, tfresource.NewEmptyResultError(input)
}

if count := len(filesystems); count > 1 {
return nil, tfresource.NewTooManyResultsError(count, input)
FileSystemIds: aws.StringSlice([]string{id}),
}

return filesystems[0], nil
return findFileSystem(ctx, conn, input, tfslices.PredicateTrue[*fsx.FileSystem]())
}

func FindLustreFileSystemByID(ctx context.Context, conn *fsx.FSx, id string) (*fsx.FileSystem, error) {
Expand Down Expand Up @@ -770,7 +734,7 @@ func findFileSystems(ctx context.Context, conn *fsx.FSx, input *fsx.DescribeFile

func statusFileSystem(ctx context.Context, conn *fsx.FSx, id string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := FindFileSystemByID(ctx, conn, id)
output, err := findFileSystemByID(ctx, conn, id)

if tfresource.NotFound(err) {
return nil, "", nil
Expand Down Expand Up @@ -869,7 +833,7 @@ func waitFileSystemDeleted(ctx context.Context, conn *fsx.FSx, id string, timeou
}

func findAdministrativeAction(ctx context.Context, conn *fsx.FSx, fsID, actionType string) (*fsx.AdministrativeAction, error) {
output, err := FindFileSystemByID(ctx, conn, fsID)
output, err := findFileSystemByID(ctx, conn, fsID)

if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/service/fsx/lustre_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ func TestAccFSxLustreFileSystem_kmsKeyID(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckLustreFileSystemExists(ctx, resourceName, &filesystem2),
resource.TestCheckResourceAttr(resourceName, "deployment_type", fsx.LustreDeploymentTypePersistent1),
testAccCheckWindowsFileSystemRecreated(&filesystem1, &filesystem2),
testAccCheckLustreFileSystemRecreated(&filesystem1, &filesystem2),
resource.TestCheckResourceAttrPair(resourceName, "kms_key_id", kmsKeyResourceName2, "arn"),
),
},
Expand Down
Loading

0 comments on commit e35e78d

Please sign in to comment.