Skip to content

Commit

Permalink
Merge pull request #33487 from triggan/main
Browse files Browse the repository at this point in the history
r/aws_neptune_cluster_instance: remove engine_version as ForceNew parameter and fixed default cluster parameter behavior.
  • Loading branch information
ewbankkit authored Oct 13, 2023
2 parents 4a19834 + 05dfff1 commit 2ca7785
Show file tree
Hide file tree
Showing 14 changed files with 344 additions and 200 deletions.
7 changes: 7 additions & 0 deletions .changelog/33487.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_neptune_cluster_instance: Remove [ForceNew](https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-behaviors#forcenew) from `engine_version`
```

```release-note:bug
resource/aws_neptune_cluster_parameter_group: Fix condition where defined cluster parameters with system default values are seen as updates
```
85 changes: 43 additions & 42 deletions internal/service/neptune/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand Down Expand Up @@ -459,7 +460,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int

d.SetId(clusterID)

if _, err = waitClusterAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
if _, err = waitDBClusterAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Neptune Cluster (%s) create: %s", d.Id(), err)
}

Expand All @@ -480,7 +481,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int
return sdkdiag.AppendErrorf(diags, "modifying Neptune Cluster (%s): %s", d.Id(), err)
}

if _, err = waitClusterAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
if _, err = waitDBClusterAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Neptune Cluster (%s) update: %s", d.Id(), err)
}
}
Expand All @@ -492,7 +493,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).NeptuneConn(ctx)

dbc, err := FindClusterByID(ctx, conn, d.Id())
dbc, err := FindDBClusterByID(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Neptune Cluster (%s) not found, removing from state", d.Id())
Expand Down Expand Up @@ -664,7 +665,7 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int
return sdkdiag.AppendErrorf(diags, "modifying Neptune Cluster (%s): %s", d.Id(), err)
}

if _, err = waitClusterAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
if _, err = waitDBClusterAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Neptune Cluster (%s) update: %s", d.Id(), err)
}
}
Expand Down Expand Up @@ -758,7 +759,7 @@ func resourceClusterDelete(ctx context.Context, d *schema.ResourceData, meta int
return sdkdiag.AppendErrorf(diags, "deleting Neptune Cluster (%s): %s", d.Id(), err)
}

if _, err := waitClusterDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil {
if _, err := waitDBClusterDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Neptune Cluster (%s) delete: %s", d.Id(), err)
}

Expand Down Expand Up @@ -810,78 +811,78 @@ func removeClusterFromGlobalCluster(ctx context.Context, conn *neptune.Neptune,
return nil
}

func FindClusterByID(ctx context.Context, conn *neptune.Neptune, id string) (*neptune.DBCluster, error) {
func FindDBClusterByID(ctx context.Context, conn *neptune.Neptune, id string) (*neptune.DBCluster, error) {
input := &neptune.DescribeDBClustersInput{
DBClusterIdentifier: aws.String(id),
}

output, err := conn.DescribeDBClustersWithContext(ctx, input)

if tfawserr.ErrCodeEquals(err, neptune.ErrCodeDBClusterNotFoundFault) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}
output, err := findDBCluster(ctx, conn, input, tfslices.PredicateTrue[*neptune.DBCluster]())

if err != nil {
return nil, err
}

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

dbCluster := output.DBClusters[0]

// Eventual consistency check.
if aws.StringValue(dbCluster.DBClusterIdentifier) != id {
if aws.StringValue(output.DBClusterIdentifier) != id {
return nil, &retry.NotFoundError{
LastRequest: input,
}
}

return dbCluster, nil
return output, nil
}

func findClusterByARN(ctx context.Context, conn *neptune.Neptune, arn string) (*neptune.DBCluster, error) {
input := &neptune.DescribeDBClustersInput{}
var output *neptune.DBCluster

return findDBCluster(ctx, conn, input, func(v *neptune.DBCluster) bool {
return aws.StringValue(v.DBClusterArn) == arn
})
}

func findDBCluster(ctx context.Context, conn *neptune.Neptune, input *neptune.DescribeDBClustersInput, filter tfslices.Predicate[*neptune.DBCluster]) (*neptune.DBCluster, error) {
output, err := findDBClusters(ctx, conn, input, filter)

if err != nil {
return nil, err
}

return tfresource.AssertSinglePtrResult(output)
}

func findDBClusters(ctx context.Context, conn *neptune.Neptune, input *neptune.DescribeDBClustersInput, filter tfslices.Predicate[*neptune.DBCluster]) ([]*neptune.DBCluster, error) {
var output []*neptune.DBCluster

err := conn.DescribeDBClustersPagesWithContext(ctx, input, func(page *neptune.DescribeDBClustersOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, v := range page.DBClusters {
if v == nil {
continue
}

if aws.StringValue(v.DBClusterArn) == arn {
output = v

return false
if v != nil && filter(v) {
output = append(output, v)
}
}

return !lastPage
})

if err != nil {
return nil, err
if tfawserr.ErrCodeEquals(err, neptune.ErrCodeDBClusterNotFoundFault) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if output == nil {
return nil, &retry.NotFoundError{}
if err != nil {
return nil, err
}

return output, nil
}

func statusCluster(ctx context.Context, conn *neptune.Neptune, id string) retry.StateRefreshFunc {
func statusDBCluster(ctx context.Context, conn *neptune.Neptune, id string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := FindClusterByID(ctx, conn, id)
output, err := FindDBClusterByID(ctx, conn, id)

if tfresource.NotFound(err) {
return nil, "", nil
Expand All @@ -895,7 +896,7 @@ func statusCluster(ctx context.Context, conn *neptune.Neptune, id string) retry.
}
}

func waitClusterAvailable(ctx context.Context, conn *neptune.Neptune, id string, timeout time.Duration) (*neptune.DBCluster, error) { //nolint:unparam
func waitDBClusterAvailable(ctx context.Context, conn *neptune.Neptune, id string, timeout time.Duration) (*neptune.DBCluster, error) { //nolint:unparam
stateConf := &retry.StateChangeConf{
Pending: []string{
"creating",
Expand All @@ -907,7 +908,7 @@ func waitClusterAvailable(ctx context.Context, conn *neptune.Neptune, id string,
"upgrading",
},
Target: []string{"available"},
Refresh: statusCluster(ctx, conn, id),
Refresh: statusDBCluster(ctx, conn, id),
Timeout: timeout,
MinTimeout: 10 * time.Second,
Delay: 30 * time.Second,
Expand All @@ -922,7 +923,7 @@ func waitClusterAvailable(ctx context.Context, conn *neptune.Neptune, id string,
return nil, err
}

func waitClusterDeleted(ctx context.Context, conn *neptune.Neptune, id string, timeout time.Duration) (*neptune.DBCluster, error) {
func waitDBClusterDeleted(ctx context.Context, conn *neptune.Neptune, id string, timeout time.Duration) (*neptune.DBCluster, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{
"available",
Expand All @@ -931,7 +932,7 @@ func waitClusterDeleted(ctx context.Context, conn *neptune.Neptune, id string, t
"modifying",
},
Target: []string{},
Refresh: statusCluster(ctx, conn, id),
Refresh: statusDBCluster(ctx, conn, id),
Timeout: timeout,
MinTimeout: 10 * time.Second,
Delay: 30 * time.Second,
Expand Down
2 changes: 1 addition & 1 deletion internal/service/neptune/cluster_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ resource "aws_neptune_cluster" "test" {
cluster_identifier = %[1]q
availability_zones = local.availability_zone_names
engine = "neptune"
neptune_cluster_parameter_group_name = "default.neptune1"
neptune_cluster_parameter_group_name = "default.neptune1.2"
skip_final_snapshot = true
}
`, rName))
Expand Down
Loading

0 comments on commit 2ca7785

Please sign in to comment.