Skip to content

Commit 95098f6

Browse files
authored
task: remove dependency on pointy (#1953)
1 parent 8952761 commit 95098f6

38 files changed

+352
-381
lines changed

go.mod

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ require (
2121
github.com/hashicorp/terraform-plugin-sdk/v2 v2.32.0
2222
github.com/hashicorp/terraform-plugin-testing v1.6.0
2323
github.com/mongodb-forks/digest v1.0.5
24-
github.com/mwielbut/pointy v1.1.0
2524
github.com/spf13/cast v1.6.0
2625
github.com/stretchr/testify v1.8.4
2726
github.com/zclconf/go-cty v1.14.2
@@ -32,8 +31,6 @@ require (
3231
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819
3332
)
3433

35-
require github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
36-
3734
require (
3835
cloud.google.com/go v0.110.10 // indirect
3936
cloud.google.com/go/compute v1.23.3 // indirect
@@ -46,6 +43,7 @@ require (
4643
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
4744
github.com/agext/levenshtein v1.2.3 // indirect
4845
github.com/apparentlymart/go-cidr v1.1.0 // indirect
46+
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
4947
github.com/armon/go-radix v1.0.0 // indirect
5048
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
5149
github.com/bgentry/speakeasy v0.1.0 // indirect

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,6 @@ github.com/mongodb-forks/digest v1.0.5 h1:EJu3wtLZcA0HCvsZpX5yuD193/sW9tHiNvrEM5
646646
github.com/mongodb-forks/digest v1.0.5/go.mod h1:rb+EX8zotClD5Dj4NdgxnJXG9nwrlx3NWKJ8xttz1Dg=
647647
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
648648
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
649-
github.com/mwielbut/pointy v1.1.0 h1:U5/YEfoIkaGCHv0St3CgjduqXID4FNRoyZgLM1kY9vg=
650-
github.com/mwielbut/pointy v1.1.0/go.mod h1:MvvO+uMFj9T5DMda33HlvogsFBX7pWWKAkFIn4teYwY=
651649
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
652650
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
653651
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=

internal/common/conversion/type_conversion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func IntPtrToInt64Ptr(i *int) *int64 {
4949

5050
// IsStringPresent returns true if the string is non-empty.
5151
func IsStringPresent(strPtr *string) bool {
52-
return strPtr != nil && len(*strPtr) > 0
52+
return strPtr != nil && *strPtr != ""
5353
}
5454

5555
// MongoDBRegionToAWSRegion converts region in US_EAST_1-like format to us-east-1-like

internal/provider/provider_sdk2.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import (
5959
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/teams"
6060
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/thirdpartyintegration"
6161
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/x509authenticationdatabaseuser"
62-
"github.com/mwielbut/pointy"
6362
)
6463

6564
var (
@@ -323,7 +322,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (any, diag.D
323322
func setDefaultsAndValidations(d *schema.ResourceData) diag.Diagnostics {
324323
diagnostics := []diag.Diagnostic{}
325324

326-
mongodbgovCloud := pointy.Bool(d.Get("is_mongodbgov_cloud").(bool))
325+
mongodbgovCloud := conversion.Pointer(d.Get("is_mongodbgov_cloud").(bool))
327326
if *mongodbgovCloud {
328327
if err := d.Set("base_url", MongodbGovCloudURL); err != nil {
329328
return append(diagnostics, diag.FromErr(err)...)

internal/service/advancedcluster/common_advanced_cluster.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1515
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1616
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
17-
"github.com/mwielbut/pointy"
17+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
1818
"github.com/spf13/cast"
1919
matlas "go.mongodb.org/atlas/mongodbatlas"
2020
)
@@ -326,48 +326,48 @@ func ExpandProcessArgs(d *schema.ResourceData, p map[string]any) *matlas.Process
326326
}
327327

328328
if _, ok := d.GetOkExists("advanced_configuration.0.fail_index_key_too_long"); ok {
329-
res.FailIndexKeyTooLong = pointy.Bool(cast.ToBool(p["fail_index_key_too_long"]))
329+
res.FailIndexKeyTooLong = conversion.Pointer(cast.ToBool(p["fail_index_key_too_long"]))
330330
}
331331

332332
if _, ok := d.GetOkExists("advanced_configuration.0.javascript_enabled"); ok {
333-
res.JavascriptEnabled = pointy.Bool(cast.ToBool(p["javascript_enabled"]))
333+
res.JavascriptEnabled = conversion.Pointer(cast.ToBool(p["javascript_enabled"]))
334334
}
335335

336336
if _, ok := d.GetOkExists("advanced_configuration.0.minimum_enabled_tls_protocol"); ok {
337337
res.MinimumEnabledTLSProtocol = cast.ToString(p["minimum_enabled_tls_protocol"])
338338
}
339339

340340
if _, ok := d.GetOkExists("advanced_configuration.0.no_table_scan"); ok {
341-
res.NoTableScan = pointy.Bool(cast.ToBool(p["no_table_scan"]))
341+
res.NoTableScan = conversion.Pointer(cast.ToBool(p["no_table_scan"]))
342342
}
343343

344344
if _, ok := d.GetOkExists("advanced_configuration.0.sample_size_bi_connector"); ok {
345-
res.SampleSizeBIConnector = pointy.Int64(cast.ToInt64(p["sample_size_bi_connector"]))
345+
res.SampleSizeBIConnector = conversion.Pointer(cast.ToInt64(p["sample_size_bi_connector"]))
346346
}
347347

348348
if _, ok := d.GetOkExists("advanced_configuration.0.sample_refresh_interval_bi_connector"); ok {
349-
res.SampleRefreshIntervalBIConnector = pointy.Int64(cast.ToInt64(p["sample_refresh_interval_bi_connector"]))
349+
res.SampleRefreshIntervalBIConnector = conversion.Pointer(cast.ToInt64(p["sample_refresh_interval_bi_connector"]))
350350
}
351351

352352
if _, ok := d.GetOkExists("advanced_configuration.0.oplog_size_mb"); ok {
353353
if sizeMB := cast.ToInt64(p["oplog_size_mb"]); sizeMB != 0 {
354-
res.OplogSizeMB = pointy.Int64(cast.ToInt64(p["oplog_size_mb"]))
354+
res.OplogSizeMB = conversion.Pointer(cast.ToInt64(p["oplog_size_mb"]))
355355
} else {
356356
log.Printf(ErrorClusterSetting, `oplog_size_mb`, "", cast.ToString(sizeMB))
357357
}
358358
}
359359

360360
if _, ok := d.GetOkExists("advanced_configuration.0.oplog_min_retention_hours"); ok {
361361
if minRetentionHours := cast.ToFloat64(p["oplog_min_retention_hours"]); minRetentionHours >= 0 {
362-
res.OplogMinRetentionHours = pointy.Float64(cast.ToFloat64(p["oplog_min_retention_hours"]))
362+
res.OplogMinRetentionHours = conversion.Pointer(cast.ToFloat64(p["oplog_min_retention_hours"]))
363363
} else {
364364
log.Printf(ErrorClusterSetting, `oplog_min_retention_hours`, "", cast.ToString(minRetentionHours))
365365
}
366366
}
367367

368368
if _, ok := d.GetOkExists("advanced_configuration.0.transaction_lifetime_limit_seconds"); ok {
369369
if transactionLifetimeLimitSeconds := cast.ToInt64(p["transaction_lifetime_limit_seconds"]); transactionLifetimeLimitSeconds > 0 {
370-
res.TransactionLifetimeLimitSeconds = pointy.Int64(cast.ToInt64(p["transaction_lifetime_limit_seconds"]))
370+
res.TransactionLifetimeLimitSeconds = conversion.Pointer(cast.ToInt64(p["transaction_lifetime_limit_seconds"]))
371371
} else {
372372
log.Printf(ErrorClusterSetting, `transaction_lifetime_limit_seconds`, "", cast.ToString(transactionLifetimeLimitSeconds))
373373
}

internal/service/advancedcluster/resource_advanced_cluster.go

+25-26
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant"
2020
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
2121
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
22-
"github.com/mwielbut/pointy"
2322
"github.com/spf13/cast"
2423
matlas "go.mongodb.org/atlas/mongodbatlas"
2524
"golang.org/x/exp/slices"
@@ -370,7 +369,7 @@ func resourceMongoDBAtlasAdvancedClusterCreate(ctx context.Context, d *schema.Re
370369
}
371370

372371
if v, ok := d.GetOk("backup_enabled"); ok {
373-
request.BackupEnabled = pointy.Bool(v.(bool))
372+
request.BackupEnabled = conversion.Pointer(v.(bool))
374373
}
375374
if _, ok := d.GetOk("bi_connector_config"); ok {
376375
biConnector, err := ExpandBiConnectorConfig(d)
@@ -380,7 +379,7 @@ func resourceMongoDBAtlasAdvancedClusterCreate(ctx context.Context, d *schema.Re
380379
request.BiConnector = biConnector
381380
}
382381
if v, ok := d.GetOk("disk_size_gb"); ok {
383-
request.DiskSizeGB = pointy.Float64(v.(float64))
382+
request.DiskSizeGB = conversion.Pointer(v.(float64))
384383
}
385384
if v, ok := d.GetOk("encryption_at_rest_provider"); ok {
386385
request.EncryptionAtRestProvider = v.(string)
@@ -398,13 +397,13 @@ func resourceMongoDBAtlasAdvancedClusterCreate(ctx context.Context, d *schema.Re
398397
request.MongoDBMajorVersion = FormatMongoDBMajorVersion(v.(string))
399398
}
400399
if v, ok := d.GetOk("pit_enabled"); ok {
401-
request.PitEnabled = pointy.Bool(v.(bool))
400+
request.PitEnabled = conversion.Pointer(v.(bool))
402401
}
403402
if v, ok := d.GetOk("root_cert_type"); ok {
404403
request.RootCertType = v.(string)
405404
}
406405
if v, ok := d.GetOk("termination_protection_enabled"); ok {
407-
request.TerminationProtectionEnabled = pointy.Bool(v.(bool))
406+
request.TerminationProtectionEnabled = conversion.Pointer(v.(bool))
408407
}
409408
if v, ok := d.GetOk("version_release_system"); ok {
410409
request.VersionReleaseSystem = v.(string)
@@ -458,7 +457,7 @@ func resourceMongoDBAtlasAdvancedClusterCreate(ctx context.Context, d *schema.Re
458457
// To pause a cluster
459458
if v := d.Get("paused").(bool); v {
460459
request = &matlas.AdvancedCluster{
461-
Paused: pointy.Bool(v),
460+
Paused: conversion.Pointer(v),
462461
}
463462

464463
_, _, err = updateAdvancedCluster(ctx, conn, request, projectID, d.Get("name").(string), timeout)
@@ -646,7 +645,7 @@ func resourceMongoDBAtlasAdvancedClusterUpdate(ctx context.Context, d *schema.Re
646645
clusterChangeDetect := new(matlas.AdvancedCluster)
647646

648647
if d.HasChange("backup_enabled") {
649-
cluster.BackupEnabled = pointy.Bool(d.Get("backup_enabled").(bool))
648+
cluster.BackupEnabled = conversion.Pointer(d.Get("backup_enabled").(bool))
650649
}
651650

652651
if d.HasChange("bi_connector_config") {
@@ -658,7 +657,7 @@ func resourceMongoDBAtlasAdvancedClusterUpdate(ctx context.Context, d *schema.Re
658657
}
659658

660659
if d.HasChange("disk_size_gb") {
661-
cluster.DiskSizeGB = pointy.Float64(d.Get("disk_size_gb").(float64))
660+
cluster.DiskSizeGB = conversion.Pointer(d.Get("disk_size_gb").(float64))
662661
}
663662

664663
if d.HasChange("encryption_at_rest_provider") {
@@ -682,7 +681,7 @@ func resourceMongoDBAtlasAdvancedClusterUpdate(ctx context.Context, d *schema.Re
682681
}
683682

684683
if d.HasChange("pit_enabled") {
685-
cluster.PitEnabled = pointy.Bool(d.Get("pit_enabled").(bool))
684+
cluster.PitEnabled = conversion.Pointer(d.Get("pit_enabled").(bool))
686685
}
687686

688687
if d.HasChange("replication_specs") {
@@ -694,7 +693,7 @@ func resourceMongoDBAtlasAdvancedClusterUpdate(ctx context.Context, d *schema.Re
694693
}
695694

696695
if d.HasChange("termination_protection_enabled") {
697-
cluster.TerminationProtectionEnabled = pointy.Bool(d.Get("termination_protection_enabled").(bool))
696+
cluster.TerminationProtectionEnabled = conversion.Pointer(d.Get("termination_protection_enabled").(bool))
698697
}
699698

700699
if d.HasChange("version_release_system") {
@@ -706,7 +705,7 @@ func resourceMongoDBAtlasAdvancedClusterUpdate(ctx context.Context, d *schema.Re
706705
}
707706

708707
if d.HasChange("paused") && !d.Get("paused").(bool) {
709-
cluster.Paused = pointy.Bool(d.Get("paused").(bool))
708+
cluster.Paused = conversion.Pointer(d.Get("paused").(bool))
710709
}
711710

712711
timeout := d.Timeout(schema.TimeoutUpdate)
@@ -743,7 +742,7 @@ func resourceMongoDBAtlasAdvancedClusterUpdate(ctx context.Context, d *schema.Re
743742

744743
if d.Get("paused").(bool) {
745744
clusterRequest := &matlas.AdvancedCluster{
746-
Paused: pointy.Bool(true),
745+
Paused: conversion.Pointer(true),
747746
}
748747

749748
_, _, err := updateAdvancedCluster(ctx, conn, clusterRequest, projectID, clusterName, timeout)
@@ -765,7 +764,7 @@ func resourceMongoDBAtlasAdvancedClusterDelete(ctx context.Context, d *schema.Re
765764
var options *matlas.DeleteAdvanceClusterOptions
766765
if v, ok := d.GetOkExists("retain_backups_enabled"); ok {
767766
options = &matlas.DeleteAdvanceClusterOptions{
768-
RetainBackups: pointy.Bool(v.(bool)),
767+
RetainBackups: conversion.Pointer(v.(bool)),
769768
}
770769
}
771770

@@ -886,7 +885,7 @@ func expandRegionConfig(tfMap map[string]any) *matlas.AdvancedRegionConfig {
886885

887886
providerName := tfMap["provider_name"].(string)
888887
apiObject := &matlas.AdvancedRegionConfig{
889-
Priority: pointy.Int(cast.ToInt(tfMap["priority"])),
888+
Priority: conversion.Pointer(cast.ToInt(tfMap["priority"])),
890889
ProviderName: providerName,
891890
RegionName: tfMap["region_name"].(string),
892891
}
@@ -946,7 +945,7 @@ func expandRegionConfigSpec(tfList []any, providerName string) *matlas.Specs {
946945

947946
if providerName == "AWS" {
948947
if v, ok := tfMap["disk_iops"]; ok && v.(int) > 0 {
949-
apiObject.DiskIOPS = pointy.Int64(cast.ToInt64(v.(int)))
948+
apiObject.DiskIOPS = conversion.Pointer(cast.ToInt64(v.(int)))
950949
}
951950
if v, ok := tfMap["ebs_volume_type"]; ok {
952951
apiObject.EbsVolumeType = v.(string)
@@ -956,7 +955,7 @@ func expandRegionConfigSpec(tfList []any, providerName string) *matlas.Specs {
956955
apiObject.InstanceSize = v.(string)
957956
}
958957
if v, ok := tfMap["node_count"]; ok {
959-
apiObject.NodeCount = pointy.Int(v.(int))
958+
apiObject.NodeCount = conversion.Pointer(v.(int))
960959
}
961960

962961
return apiObject
@@ -974,13 +973,13 @@ func expandRegionConfigAutoScaling(tfList []any) *matlas.AdvancedAutoScaling {
974973
compute := &matlas.Compute{}
975974

976975
if v, ok := tfMap["disk_gb_enabled"]; ok {
977-
diskGB.Enabled = pointy.Bool(v.(bool))
976+
diskGB.Enabled = conversion.Pointer(v.(bool))
978977
}
979978
if v, ok := tfMap["compute_enabled"]; ok {
980-
compute.Enabled = pointy.Bool(v.(bool))
979+
compute.Enabled = conversion.Pointer(v.(bool))
981980
}
982981
if v, ok := tfMap["compute_scale_down_enabled"]; ok {
983-
compute.ScaleDownEnabled = pointy.Bool(v.(bool))
982+
compute.ScaleDownEnabled = conversion.Pointer(v.(bool))
984983
}
985984
if v, ok := tfMap["compute_min_instance_size"]; ok {
986985
value := compute.ScaleDownEnabled
@@ -1011,19 +1010,19 @@ func flattenAdvancedReplicationSpec(ctx context.Context, apiObject *matlas.Advan
10111010
tfMap["num_shards"] = apiObject.NumShards
10121011
tfMap["id"] = apiObject.ID
10131012
if tfMapObject != nil {
1014-
object, containerIds, err := flattenAdvancedReplicationSpecRegionConfigs(ctx, apiObject.RegionConfigs, tfMapObject["region_configs"].([]any), d, conn)
1013+
object, containerIDs, err := flattenAdvancedReplicationSpecRegionConfigs(ctx, apiObject.RegionConfigs, tfMapObject["region_configs"].([]any), d, conn)
10151014
if err != nil {
10161015
return nil, err
10171016
}
10181017
tfMap["region_configs"] = object
1019-
tfMap["container_id"] = containerIds
1018+
tfMap["container_id"] = containerIDs
10201019
} else {
1021-
object, containerIds, err := flattenAdvancedReplicationSpecRegionConfigs(ctx, apiObject.RegionConfigs, nil, d, conn)
1020+
object, containerIDs, err := flattenAdvancedReplicationSpecRegionConfigs(ctx, apiObject.RegionConfigs, nil, d, conn)
10221021
if err != nil {
10231022
return nil, err
10241023
}
10251024
tfMap["region_configs"] = object
1026-
tfMap["container_id"] = containerIds
1025+
tfMap["container_id"] = containerIDs
10271026
}
10281027
tfMap["zone_name"] = apiObject.ZoneName
10291028

@@ -1149,7 +1148,7 @@ func flattenAdvancedReplicationSpecRegionConfigs(ctx context.Context, apiObjects
11491148
}
11501149

11511150
var tfList []map[string]any
1152-
containerIds := make(map[string]string)
1151+
containerIDs := make(map[string]string)
11531152

11541153
for i, apiObject := range apiObjects {
11551154
if apiObject == nil {
@@ -1171,12 +1170,12 @@ func flattenAdvancedReplicationSpecRegionConfigs(ctx context.Context, apiObjects
11711170
}
11721171
if result := getAdvancedClusterContainerID(containers, apiObject); result != "" {
11731172
// Will print as "providerName:regionName" = "containerId" in terraform show
1174-
containerIds[fmt.Sprintf("%s:%s", apiObject.ProviderName, apiObject.RegionName)] = result
1173+
containerIDs[fmt.Sprintf("%s:%s", apiObject.ProviderName, apiObject.RegionName)] = result
11751174
}
11761175
}
11771176
}
11781177

1179-
return tfList, containerIds, nil
1178+
return tfList, containerIDs, nil
11801179
}
11811180

11821181
func flattenAdvancedReplicationSpecRegionConfigSpec(apiObject *matlas.Specs, providerName string, tfMapObjects []any) []map[string]any {

0 commit comments

Comments
 (0)