Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_neptune_cluster: Fixing Issue #38979 with incorrect default value used for cluster and instance parameter group #38980

Merged
merged 8 commits into from
Aug 27, 2024
Merged
7 changes: 7 additions & 0 deletions .changelog/38980.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_neptune_cluster: Mark `neptune_cluster_parameter_group_name` as Computed
```

```release-note:bug
resource/aws_neptune_cluster_instance: Mark `neptune_parameter_group_name` as Computed
```
48 changes: 30 additions & 18 deletions internal/service/neptune/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
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"
itypes "github.com/hashicorp/terraform-provider-aws/internal/types"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
"github.com/hashicorp/terraform-provider-aws/names"
)
Expand Down Expand Up @@ -201,7 +202,7 @@ func resourceCluster() *schema.Resource {
"neptune_cluster_parameter_group_name": {
Type: schema.TypeString,
Optional: true,
Default: "default.neptune1",
Computed: true,
},
"neptune_instance_parameter_group_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -480,7 +481,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int

d.SetId(clusterID)

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

Expand All @@ -501,7 +502,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 = waitDBClusterAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
if _, err = waitDBClusterAvailable(ctx, conn, d.Id(), true, d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Neptune Cluster (%s) update: %s", d.Id(), err)
}
}
Expand Down Expand Up @@ -691,7 +692,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 = waitDBClusterAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
if _, err = waitDBClusterAvailable(ctx, conn, d.Id(), true, d.Timeout(schema.TimeoutUpdate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Neptune Cluster (%s) update: %s", d.Id(), err)
}
}
Expand Down Expand Up @@ -903,7 +904,7 @@ func findDBClusters(ctx context.Context, conn *neptune.Client, input *neptune.De
return output, nil
}

func statusDBCluster(ctx context.Context, conn *neptune.Client, id string) retry.StateRefreshFunc {
func statusDBCluster(ctx context.Context, conn *neptune.Client, id string, waitNoPendingModifiedValues bool) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := findDBClusterByID(ctx, conn, id)

Expand All @@ -915,23 +916,34 @@ func statusDBCluster(ctx context.Context, conn *neptune.Client, id string) retry
return nil, "", err
}

return output, aws.ToString(output.Status), nil
status := aws.ToString(output.Status)

if status == clusterStatusAvailable && waitNoPendingModifiedValues && !itypes.IsZero(output.PendingModifiedValues) {
status = clusterStatusAvailableWithPendingModifiedValues
}

return output, status, nil
}
}

func waitDBClusterAvailable(ctx context.Context, conn *neptune.Client, id string, timeout time.Duration) (*awstypes.DBCluster, error) { //nolint:unparam
func waitDBClusterAvailable(ctx context.Context, conn *neptune.Client, id string, waitNoPendingModifiedValues bool, timeout time.Duration) (*awstypes.DBCluster, error) { //nolint:unparam
pendingStatuses := []string{
clusterStatusCreating,
clusterStatusBackingUp,
clusterStatusModifying,
clusterStatusPreparingDataMigration,
clusterStatusMigrating,
clusterStatusConfiguringIAMDatabaseAuth,
clusterStatusUpgrading,
}
if waitNoPendingModifiedValues {
pendingStatuses = append(pendingStatuses, clusterStatusAvailableWithPendingModifiedValues)
}

stateConf := &retry.StateChangeConf{
Pending: []string{
clusterStatusCreating,
clusterStatusBackingUp,
clusterStatusModifying,
clusterStatusPreparingDataMigration,
clusterStatusMigrating,
clusterStatusConfiguringIAMDatabaseAuth,
clusterStatusUpgrading,
},
Pending: pendingStatuses,
Target: []string{clusterStatusAvailable},
Refresh: statusDBCluster(ctx, conn, id),
Refresh: statusDBCluster(ctx, conn, id, waitNoPendingModifiedValues),
Timeout: timeout,
MinTimeout: 10 * time.Second,
Delay: 30 * time.Second,
Expand All @@ -955,7 +967,7 @@ func waitDBClusterDeleted(ctx context.Context, conn *neptune.Client, id string,
clusterStatusModifying,
},
Target: []string{},
Refresh: statusDBCluster(ctx, conn, id),
Refresh: statusDBCluster(ctx, conn, id, false),
Timeout: timeout,
MinTimeout: 10 * time.Second,
Delay: 30 * time.Second,
Expand Down
2 changes: 1 addition & 1 deletion internal/service/neptune/cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func resourceClusterInstance() *schema.Resource {
"neptune_parameter_group_name": {
Type: schema.TypeString,
Optional: true,
Default: "default.neptune1",
Computed: true,
},
"neptune_subnet_group_name": {
Type: schema.TypeString,
Expand Down
26 changes: 9 additions & 17 deletions internal/service/neptune/cluster_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,6 @@ func testAccCheckClusterInstanceExists(ctx context.Context, n string, v *awstype
return fmt.Errorf("Not found: %s", n)
}

if rs.Primary.ID == "" {
return fmt.Errorf("No Neptune Cluster Instance ID is set")
}

conn := acctest.Provider.Meta().(*conns.AWSClient).NeptuneClient(ctx)

output, err := tfneptune.FindDBInstanceByID(ctx, conn, rs.Primary.ID)
Expand Down Expand Up @@ -349,12 +345,12 @@ data "aws_neptune_orderable_db_instance" "test" {
engine_version = aws_neptune_cluster.test.engine_version
license_model = "amazon-license"

preferred_instance_classes = ["db.t3.medium", "db.r5.large", "db.r4.large"]
preferred_instance_classes = ["db.t4g.medium", "db.r6g.large", "db.r5.large", "db.t3.medium", "db.r4.large"]
}

resource "aws_neptune_parameter_group" "test" {
name = %[1]q
family = "neptune1.3"
family = join("", ["neptune", split(".", aws_neptune_cluster.test.engine_version)[0], ".", split(".", aws_neptune_cluster.test.engine_version)[1]])

parameter {
name = "neptune_query_timeout"
Expand All @@ -367,11 +363,10 @@ resource "aws_neptune_parameter_group" "test" {
func testAccClusterInstanceConfig_base(rName string) string {
return acctest.ConfigCompose(testAccClusterInstanceConfig_baseSansCluster(rName), acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(`
resource "aws_neptune_cluster" "test" {
cluster_identifier = %[1]q
availability_zones = slice(data.aws_availability_zones.available.names, 0, min(3, length(data.aws_availability_zones.available.names)))
engine = "neptune"
neptune_cluster_parameter_group_name = "default.neptune1.3"
skip_final_snapshot = true
cluster_identifier = %[1]q
availability_zones = slice(data.aws_availability_zones.available.names, 0, min(3, length(data.aws_availability_zones.available.names)))
engine = "neptune"
skip_final_snapshot = true
}
`, rName))
}
Expand Down Expand Up @@ -494,10 +489,9 @@ resource "aws_neptune_subnet_group" "test" {
}

resource "aws_neptune_cluster" "test" {
cluster_identifier = %[1]q
neptune_subnet_group_name = aws_neptune_subnet_group.test.name
neptune_cluster_parameter_group_name = "default.neptune1.3"
skip_final_snapshot = true
cluster_identifier = %[1]q
neptune_subnet_group_name = aws_neptune_subnet_group.test.name
skip_final_snapshot = true
}
`, rName))
}
Expand Down Expand Up @@ -540,8 +534,6 @@ resource "aws_neptune_cluster" "test" {
skip_final_snapshot = true
storage_encrypted = true
kms_key_arn = aws_kms_key.test.arn

neptune_cluster_parameter_group_name = "default.neptune1.3"
}
`, rName))
}
Loading
Loading