Skip to content

Commit 1cce6cf

Browse files
AWS registration: Fix to allow empty IOA resources for commercial accounts in gov (#148)
1 parent 541081e commit 1cce6cf

File tree

1 file changed

+0
-93
lines changed

1 file changed

+0
-93
lines changed

internal/fcs/cloud_aws_account.go

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"regexp"
88
"strings"
9-
"time"
109

1110
"github.com/crowdstrike/gofalcon/falcon/client"
1211
"github.com/crowdstrike/gofalcon/falcon/client/cloud_aws_registration"
@@ -33,7 +32,6 @@ import (
3332
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
3433
"github.com/hashicorp/terraform-plugin-framework/types"
3534
"github.com/hashicorp/terraform-plugin-log/tflog"
36-
"golang.org/x/exp/maps"
3735
)
3836

3937
type cloudAWSAccountResource struct {
@@ -569,11 +567,6 @@ func (r *cloudAWSAccountResource) Create(
569567
}
570568
}
571569

572-
// if IDP or realtime visibility are enabled wait until we get all values back
573-
if state.IDP.Enabled.ValueBool() || state.RealtimeVisibility.Enabled.ValueBool() {
574-
resp.Diagnostics.Append(r.pollMissingValues(ctx, &state)...)
575-
}
576-
577570
// Set refreshed state
578571
diags = resp.State.Set(ctx, state)
579572
resp.Diagnostics.Append(diags...)
@@ -1451,89 +1444,3 @@ func (r *cloudAWSAccountResource) ValidateConfig(
14511444
return
14521445
}
14531446
}
1454-
1455-
// pollMissingValues waits for missing backend values [eventbus_arn, eventbus_name, cloudtrail_bucket_name] to be set.
1456-
func (r *cloudAWSAccountResource) pollMissingValues(
1457-
ctx context.Context,
1458-
config *cloudAWSAccountModel,
1459-
) diag.Diagnostics {
1460-
var diags diag.Diagnostics
1461-
missingValues := make(map[string]interface{})
1462-
1463-
if config.EventbusArn.ValueString() == "" {
1464-
missingValues["eventbus_arn"] = nil
1465-
}
1466-
1467-
if config.EventbusName.ValueString() == "" {
1468-
missingValues["eventbus_name"] = nil
1469-
}
1470-
1471-
if config.CloudTrailBucketName.ValueString() == "" {
1472-
missingValues["cloudtrail_bucket_name"] = nil
1473-
}
1474-
1475-
if len(missingValues) == 0 {
1476-
return diags
1477-
}
1478-
1479-
pollCtx, cancel := context.WithTimeout(ctx, 5*time.Minute)
1480-
defer cancel()
1481-
1482-
ticker := time.NewTicker(10 * time.Second)
1483-
defer ticker.Stop()
1484-
1485-
for {
1486-
select {
1487-
case <-ticker.C:
1488-
account, diag := r.getCSPMAccount(pollCtx, config.AccountID.ValueString())
1489-
if diag.HasError() {
1490-
return diag
1491-
}
1492-
1493-
if _, ok := missingValues["eventbus_arn"]; ok && account.AwsEventbusArn != "" {
1494-
config.EventbusArn = types.StringValue(account.AwsEventbusArn)
1495-
delete(missingValues, "eventbus_arn")
1496-
}
1497-
1498-
if _, ok := missingValues["eventbus_name"]; ok && account.EventbusName != "" {
1499-
config.EventbusName = types.StringValue(account.EventbusName)
1500-
delete(missingValues, "eventbus_name")
1501-
}
1502-
1503-
if _, ok := missingValues["cloudtrail_bucket_name"]; ok &&
1504-
account.AwsCloudtrailBucketName != "" {
1505-
config.CloudTrailBucketName = types.StringValue(account.AwsCloudtrailBucketName)
1506-
delete(missingValues, "cloudtrail_bucket_name")
1507-
}
1508-
1509-
if len(missingValues) == 0 {
1510-
return diags
1511-
}
1512-
1513-
fields := strings.Join(maps.Keys(missingValues), ", ")
1514-
tflog.Debug(
1515-
pollCtx,
1516-
fmt.Sprintf("[%s] not yet available, polling again in 10s...", fields),
1517-
)
1518-
1519-
case <-pollCtx.Done():
1520-
if pollCtx.Err() != context.DeadlineExceeded {
1521-
return diags
1522-
}
1523-
1524-
if len(missingValues) == 0 {
1525-
return diags
1526-
}
1527-
1528-
fields := strings.Join(maps.Keys(missingValues), ", ")
1529-
diags.AddError(
1530-
"Timed out waiting for missing fields to populate",
1531-
fmt.Sprintf(
1532-
"Timed out on create waiting for missing fields [%s] to return from API.",
1533-
fields,
1534-
),
1535-
)
1536-
return diags
1537-
}
1538-
}
1539-
}

0 commit comments

Comments
 (0)