Skip to content

Commit 1b12008

Browse files
authored
INTMDB-560: cloud_provider_access_authorization and encryption_at_rest improvements (#1045)
* Add additional logging and retries based on error code * Lint add catch error handler at end if fails after retry * Fix missing groupID * Update resource_mongodbatlas_encryption_at_rest.go
1 parent 3c3d72c commit 1b12008

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

mongodbatlas/resource_mongodbatlas_cloud_provider_access_authorization.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ func resourceMongoDBAtlasCloudProviderAccessAuthorizationCreate(ctx context.Cont
149149
time.Sleep(10 * time.Second)
150150
continue
151151
}
152+
if err != nil {
153+
log.Printf("MISSED ERRROR %s", err.Error())
154+
}
152155
break
153156
}
154157

mongodbatlas/resource_mongodbatlas_encryption_at_rest.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package mongodbatlas
33
import (
44
"context"
55
"fmt"
6+
"log"
67
"net/http"
8+
"strings"
9+
"time"
710

811
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
912
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -236,9 +239,22 @@ func resourceMongoDBAtlasEncryptionAtRestCreate(ctx context.Context, d *schema.R
236239
encryptionAtRestReq.GoogleCloudKms = expandGCPKmsConfig(gcpC.([]interface{}))
237240
}
238241

239-
_, _, err := conn.EncryptionsAtRest.Create(ctx, encryptionAtRestReq)
240-
if err != nil {
241-
return diag.FromErr(fmt.Errorf(errorCreateEncryptionAtRest, err))
242+
for i := 0; i < 5; i++ {
243+
_, _, err := conn.EncryptionsAtRest.Create(ctx, encryptionAtRestReq)
244+
if err != nil {
245+
if strings.Contains(err.Error(), "CANNOT_ASSUME_ROLE") || strings.Contains(err.Error(), "INVALID_AWS_CREDENTIALS") ||
246+
strings.Contains(err.Error(), "CLOUD_PROVIDER_ACCESS_ROLE_NOT_AUTHORIZED") {
247+
log.Printf("warning issue performing authorize EncryptionsAtRest not done try again: %s \n", err.Error())
248+
log.Println("retrying ")
249+
time.Sleep(10 * time.Second)
250+
encryptionAtRestReq.GroupID = d.Get("project_id").(string)
251+
continue
252+
}
253+
}
254+
if err != nil {
255+
return diag.FromErr(fmt.Errorf(errorCreateEncryptionAtRest, err))
256+
}
257+
break
242258
}
243259

244260
d.SetId(d.Get("project_id").(string))

0 commit comments

Comments
 (0)