Skip to content

Commit

Permalink
Merge pull request #38193 from VictorCodesseira/b-docdb-change-passwo…
Browse files Browse the repository at this point in the history
…rd-if-snapshot

fix: Add master password to ModifyDbClusterInput when creating DocumentDb from Snapshot
  • Loading branch information
ewbankkit authored Oct 29, 2024
2 parents 2da756b + 6faf7d6 commit f337f4f
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .changelog/38193.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_docdb_cluster: Use `master_password` on resource Create when `snapshot_identifier` is configured
```
21 changes: 13 additions & 8 deletions internal/service/docdb/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"fmt"
"log"
"reflect"
"strings"
"time"

Expand All @@ -28,13 +27,14 @@ 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"
)

// @SDKResource("aws_docdb_cluster", name="Cluster")
// @Tags(identifierAttribute="arn")
func ResourceCluster() *schema.Resource {
func resourceCluster() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceClusterCreate,
ReadWithoutTimeout: resourceClusterRead,
Expand Down Expand Up @@ -243,7 +243,7 @@ func ResourceCluster() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(RestoreType_Values(), false),
ValidateFunc: validation.StringInSlice(restoreType_Values(), false),
},
"source_cluster_identifier": {
Type: schema.TypeString,
Expand Down Expand Up @@ -371,6 +371,11 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int
input.KmsKeyId = aws.String(v.(string))
}

if v, ok := d.GetOk("master_password"); ok {
inputM.MasterUserPassword = aws.String(v.(string))
requiresModifyDbCluster = true
}

if v, ok := d.GetOk(names.AttrPort); ok {
input.Port = aws.Int32(int32(v.(int)))
}
Expand Down Expand Up @@ -859,7 +864,7 @@ func findDBClusterByID(ctx context.Context, conn *docdb.Client, id string) (*aws
input := &docdb.DescribeDBClustersInput{
DBClusterIdentifier: aws.String(id),
}
output, err := findDBCluster(ctx, conn, input, tfslices.PredicateTrue[awstypes.DBCluster]())
output, err := findDBCluster(ctx, conn, input, tfslices.PredicateTrue[*awstypes.DBCluster]())

if err != nil {
return nil, err
Expand All @@ -878,12 +883,12 @@ func findDBClusterByID(ctx context.Context, conn *docdb.Client, id string) (*aws
func findClusterByARN(ctx context.Context, conn *docdb.Client, arn string) (*awstypes.DBCluster, error) {
input := &docdb.DescribeDBClustersInput{}

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

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

if err != nil {
Expand All @@ -893,7 +898,7 @@ func findDBCluster(ctx context.Context, conn *docdb.Client, input *docdb.Describ
return tfresource.AssertSingleValueResult(output)
}

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

pages := docdb.NewDescribeDBClustersPaginator(conn, input)
Expand All @@ -912,7 +917,7 @@ func findDBClusters(ctx context.Context, conn *docdb.Client, input *docdb.Descri
}

for _, v := range page.DBClusters {
if !reflect.ValueOf(v).IsZero() && filter(v) {
if !itypes.IsZero(&v) && filter(&v) {
output = append(output, v)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/docdb/cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

// @SDKResource("aws_docdb_cluster_instance", name="Cluster Instance")
// @Tags(identifierAttribute="arn")
func ResourceClusterInstance() *schema.Resource {
func resourceClusterInstance() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceClusterInstanceCreate,
ReadWithoutTimeout: resourceClusterInstanceRead,
Expand Down
8 changes: 4 additions & 4 deletions internal/service/docdb/cluster_parameter_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"fmt"
"log"
"reflect"
"slices"
"time"

Expand All @@ -24,13 +23,14 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
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"
)

// @SDKResource("aws_docdb_cluster_parameter_group", name="Cluster Parameter Group")
// @Tags(identifierAttribute="arn")
func ResourceClusterParameterGroup() *schema.Resource {
func resourceClusterParameterGroup() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceClusterParameterGroupCreate,
ReadWithoutTimeout: resourceClusterParameterGroupRead,
Expand Down Expand Up @@ -291,7 +291,7 @@ func findDBClusterParameterGroups(ctx context.Context, conn *docdb.Client, input
}

for _, v := range page.DBClusterParameterGroups {
if !reflect.ValueOf(v).IsZero() {
if !itypes.IsZero(&v) {
output = append(output, v)
}
}
Expand Down Expand Up @@ -319,7 +319,7 @@ func findDBClusterParameters(ctx context.Context, conn *docdb.Client, input *doc
}

for _, v := range page.Parameters {
if !reflect.ValueOf(v).IsZero() {
if !itypes.IsZero(&v) {
output = append(output, v)
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/docdb/cluster_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package docdb
import (
"context"
"log"
"reflect"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
Expand All @@ -19,6 +18,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
itypes "github.com/hashicorp/terraform-provider-aws/internal/types"
"github.com/hashicorp/terraform-provider-aws/names"
)

Expand Down Expand Up @@ -226,7 +226,7 @@ func findClusterSnapshots(ctx context.Context, conn *docdb.Client, input *docdb.
}

for _, v := range page.DBClusterSnapshots {
if !reflect.ValueOf(v).IsZero() {
if !itypes.IsZero(&v) {
output = append(output, v)
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/service/docdb/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ func storageType_Values() []string {
}

const (
RestoreTypeCopyOnWrite = "copy-on-write"
RestoreTypeFullCopy = "full-copy"
restoreTypeCopyOnWrite = "copy-on-write"
restoreTypeFullCopy = "full-copy"
)

func RestoreType_Values() []string {
func restoreType_Values() []string {
return []string{
RestoreTypeCopyOnWrite,
RestoreTypeFullCopy,
restoreTypeCopyOnWrite,
restoreTypeFullCopy,
}
}
2 changes: 1 addition & 1 deletion internal/service/docdb/engine_version_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

// @SDKDataSource("aws_docdb_engine_version")
func DataSourceEngineVersion() *schema.Resource {
func dataSourceEngineVersion() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceEngineVersionRead,
Schema: map[string]*schema.Schema{
Expand Down
6 changes: 3 additions & 3 deletions internal/service/docdb/event_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package docdb
import (
"context"
"log"
"reflect"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
Expand All @@ -22,13 +21,14 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/flex"
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"
)

// @SDKResource("aws_docdb_event_subscription", name="Event Subscription")
// @Tags(identifierAttribute="arn")
func ResourceEventSubscription() *schema.Resource {
func resourceEventSubscription() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceEventSubscriptionCreate,
ReadWithoutTimeout: resourceEventSubscriptionRead,
Expand Down Expand Up @@ -328,7 +328,7 @@ func findEventSubscriptions(ctx context.Context, conn *docdb.Client, input *docd
}

for _, v := range page.EventSubscriptionsList {
if !reflect.ValueOf(v).IsZero() {
if !itypes.IsZero(&v) {
output = append(output, v)
}
}
Expand Down
7 changes: 7 additions & 0 deletions internal/service/docdb/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ package docdb

// Exports for use in tests only.
var (
ResourceCluster = resourceCluster
ResourceClusterInstance = resourceClusterInstance
ResourceClusterParameterGroup = resourceClusterParameterGroup
ResourceEventSubscription = resourceEventSubscription
ResourceGlobalCluster = resourceGlobalCluster
ResourceSubnetGroup = resourceSubnetGroup

FindDBClusterByID = findDBClusterByID
FindDBClusterParameterGroupByName = findDBClusterParameterGroupByName
FindDBSubnetGroupByName = findDBSubnetGroupByName
Expand Down
14 changes: 7 additions & 7 deletions internal/service/docdb/global_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package docdb
import (
"context"
"log"
"reflect"
"slices"
"time"

Expand All @@ -22,11 +21,12 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
itypes "github.com/hashicorp/terraform-provider-aws/internal/types"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKResource("aws_docdb_global_cluster")
func ResourceGlobalCluster() *schema.Resource {
func resourceGlobalCluster() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceGlobalClusterCreate,
ReadWithoutTimeout: resourceGlobalClusterRead,
Expand Down Expand Up @@ -316,7 +316,7 @@ func findGlobalClusterByID(ctx context.Context, conn *docdb.Client, id string) (
input := &docdb.DescribeGlobalClustersInput{
GlobalClusterIdentifier: aws.String(id),
}
output, err := findGlobalCluster(ctx, conn, input, tfslices.PredicateTrue[awstypes.GlobalCluster]())
output, err := findGlobalCluster(ctx, conn, input, tfslices.PredicateTrue[*awstypes.GlobalCluster]())

if err != nil {
return nil, err
Expand All @@ -342,14 +342,14 @@ func findGlobalClusterByID(ctx context.Context, conn *docdb.Client, id string) (
func findGlobalClusterByClusterARN(ctx context.Context, conn *docdb.Client, arn string) (*awstypes.GlobalCluster, error) {
input := &docdb.DescribeGlobalClustersInput{}

return findGlobalCluster(ctx, conn, input, func(v awstypes.GlobalCluster) bool {
return findGlobalCluster(ctx, conn, input, func(v *awstypes.GlobalCluster) bool {
return slices.ContainsFunc(v.GlobalClusterMembers, func(v awstypes.GlobalClusterMember) bool {
return aws.ToString(v.DBClusterArn) == arn
})
})
}

func findGlobalCluster(ctx context.Context, conn *docdb.Client, input *docdb.DescribeGlobalClustersInput, filter tfslices.Predicate[awstypes.GlobalCluster]) (*awstypes.GlobalCluster, error) {
func findGlobalCluster(ctx context.Context, conn *docdb.Client, input *docdb.DescribeGlobalClustersInput, filter tfslices.Predicate[*awstypes.GlobalCluster]) (*awstypes.GlobalCluster, error) {
output, err := findGlobalClusters(ctx, conn, input, filter)

if err != nil {
Expand All @@ -359,7 +359,7 @@ func findGlobalCluster(ctx context.Context, conn *docdb.Client, input *docdb.Des
return tfresource.AssertSingleValueResult(output)
}

func findGlobalClusters(ctx context.Context, conn *docdb.Client, input *docdb.DescribeGlobalClustersInput, filter tfslices.Predicate[awstypes.GlobalCluster]) ([]awstypes.GlobalCluster, error) {
func findGlobalClusters(ctx context.Context, conn *docdb.Client, input *docdb.DescribeGlobalClustersInput, filter tfslices.Predicate[*awstypes.GlobalCluster]) ([]awstypes.GlobalCluster, error) {
var output []awstypes.GlobalCluster

pages := docdb.NewDescribeGlobalClustersPaginator(conn, input)
Expand All @@ -377,7 +377,7 @@ func findGlobalClusters(ctx context.Context, conn *docdb.Client, input *docdb.De
}

for _, v := range page.GlobalClusters {
if !reflect.ValueOf(v).IsZero() && filter(v) {
if !itypes.IsZero(&v) && filter(&v) {
output = append(output, v)
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/service/docdb/orderable_db_instance_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package docdb

import (
"context"
"reflect"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/docdb"
Expand All @@ -17,11 +16,12 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
itypes "github.com/hashicorp/terraform-provider-aws/internal/types"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKDataSource("aws_docdb_orderable_db_instance")
func DataSourceOrderableDBInstance() *schema.Resource {
func dataSourceOrderableDBInstance() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceOrderableDBInstanceRead,
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -156,7 +156,7 @@ func findOrderableDBInstances(ctx context.Context, conn *docdb.Client, input *do
}

for _, v := range page.OrderableDBInstanceOptions {
if !reflect.ValueOf(v).IsZero() {
if !itypes.IsZero(&v) {
output = append(output, v)
}
}
Expand Down
Loading

0 comments on commit f337f4f

Please sign in to comment.