Skip to content

Commit

Permalink
Replace credential validation once with atomic bool (#3051)
Browse files Browse the repository at this point in the history
The `once.Do` makes all threads wait on the execution of the `Do`.  

We now replace it with a comparison with an atomic bool - this should
mean that all other threads will not wait for the credential validation.
  • Loading branch information
VenelinMartinov authored Nov 27, 2023
1 parent e89f018 commit a1ec31f
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"path/filepath"
"strconv"
"strings"
"sync"
"sync/atomic"
"unicode"

"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
Expand Down Expand Up @@ -621,7 +621,7 @@ func validateCredentials(vars resource.PropertyMap, c shim.ResourceConfig) error
}

// We should only run the validation once to avoid duplicating the reported errors.
var credentialsValidationOnce sync.Once
var credentialsValidationRun atomic.Bool

// preConfigureCallback validates that AWS credentials can be successfully discovered. This emulates the credentials
// configuration subset of `github.com/terraform-providers/terraform-provider-aws/aws.providerConfigure`. We do this
Expand All @@ -637,9 +637,9 @@ func preConfigureCallback(vars resource.PropertyMap, c shim.ResourceConfig) erro
}

var err error
credentialsValidationOnce.Do(func() {
if credentialsValidationRun.CompareAndSwap(false, true) {
err = validateCredentials(vars, c)
})
}
return err
}

Expand Down Expand Up @@ -905,7 +905,8 @@ func ProviderFromMeta(metaInfo *tfbridge.MetadataInfo) *tfbridge.ProviderInfo {
Type: "string",
AltTypes: []tokens.Type{awsTypeDefaultFile(apigatewayMod, "RestApi")},
},
}},
},
},
"aws_api_gateway_method_settings": {
Tok: awsResource(apigatewayMod, "MethodSettings"),
Fields: map[string]*tfbridge.SchemaInfo{
Expand All @@ -914,7 +915,8 @@ func ProviderFromMeta(metaInfo *tfbridge.MetadataInfo) *tfbridge.ProviderInfo {
Type: "string",
AltTypes: []tokens.Type{awsTypeDefaultFile(apigatewayMod, "RestApi")},
},
}},
},
},
"aws_api_gateway_model": {
Tok: awsResource(apigatewayMod, "Model"),
Fields: map[string]*tfbridge.SchemaInfo{
Expand All @@ -923,7 +925,8 @@ func ProviderFromMeta(metaInfo *tfbridge.MetadataInfo) *tfbridge.ProviderInfo {
Type: "string",
AltTypes: []tokens.Type{awsTypeDefaultFile(apigatewayMod, "RestApi")},
},
}},
},
},
"aws_api_gateway_request_validator": {
Tok: awsResource(apigatewayMod, "RequestValidator"),
Fields: map[string]*tfbridge.SchemaInfo{
Expand Down Expand Up @@ -2458,7 +2461,6 @@ func ProviderFromMeta(metaInfo *tfbridge.MetadataInfo) *tfbridge.ProviderInfo {
Elem: &tfbridge.SchemaInfo{NestedType: "TopicRuleS3"},
},
"sns": {

// Singularization converts `sns` to `sn`, which is wrong.
Elem: &tfbridge.SchemaInfo{NestedType: "TopicRuleSns"},
},
Expand Down Expand Up @@ -3495,7 +3497,7 @@ func ProviderFromMeta(metaInfo *tfbridge.MetadataInfo) *tfbridge.ProviderInfo {
Tok: awsResource(s3Mod, "BucketIntelligentTieringConfiguration"),
},
"aws_s3_bucket_replication_configuration": {Tok: awsResource(s3Mod, "BucketReplicationConfig")},
//S3 Control
// S3 Control
"aws_s3control_bucket": {
Tok: awsResource(s3ControlMod, "Bucket"),
Fields: map[string]*tfbridge.SchemaInfo{
Expand Down Expand Up @@ -4929,7 +4931,6 @@ $ pulumi import aws:networkfirewall/resourcePolicy:ResourcePolicy example arn:aw
},
},
DataSources: map[string]*tfbridge.DataSourceInfo{

"aws_auditmanager_control": {
Tok: awsDataSource(auditmanagerMod, "getControl"),
},
Expand Down Expand Up @@ -5460,7 +5461,8 @@ $ pulumi import aws:networkfirewall/resourcePolicy:ResourcePolicy example arn:aw
// S3
"aws_canonical_user_id": {Tok: awsDataSource(s3Mod, "getCanonicalUserId")},
"aws_s3_account_public_access_block": {
Tok: awsDataSource(s3Mod, "getAccountPublicAccessBlock")},
Tok: awsDataSource(s3Mod, "getAccountPublicAccessBlock"),
},
"aws_s3_bucket": {Tok: awsDataSource(s3Mod, "getBucket")},
"aws_s3_bucket_object": {Tok: awsDataSource(s3Mod, "getBucketObject")},
"aws_s3_bucket_objects": {Tok: awsDataSource(s3Mod, "getBucketObjects")},
Expand Down Expand Up @@ -5638,14 +5640,14 @@ $ pulumi import aws:networkfirewall/resourcePolicy:ResourcePolicy example arn:aw
"aws_imagebuilder_container_recipes": {Tok: awsDataSource(imageBuilderMod, "getContainerRecipes")},
"aws_imagebuilder_image_pipelines": {Tok: awsDataSource(imageBuilderMod, "getImagePipelines")},

//ses
// ses
"aws_ses_active_receipt_rule_set": {Tok: awsDataSource(sesMod, "getActiveReceiptRuleSet")},
"aws_ses_domain_identity": {Tok: awsDataSource(sesMod, "getDomainIdentity")},
"aws_ses_email_identity": {Tok: awsDataSource(sesMod, "getEmailIdentity")},
//signer
// signer
"aws_signer_signing_job": {Tok: awsDataSource(signerMod, "getSigningJob")},
"aws_signer_signing_profile": {Tok: awsDataSource(signerMod, "getSigningProfile")},
//serverless repository
// serverless repository
"aws_serverlessapplicationrepository_application": {
Tok: awsDataSource(serverlessRepositoryMod, "getApplication"),
},
Expand Down Expand Up @@ -5721,7 +5723,8 @@ $ pulumi import aws:networkfirewall/resourcePolicy:ResourcePolicy example arn:aw
},
},
"aws_lb_listener": {Tok: awsDataSource(lbMod, "getListener")},
"aws_lb_target_group": {Tok: awsDataSource(lbMod, "getTargetGroup"),
"aws_lb_target_group": {
Tok: awsDataSource(lbMod, "getTargetGroup"),
Fields: map[string]*tfbridge.SchemaInfo{
"stickiness": {
MaxItemsOne: ref(true),
Expand Down Expand Up @@ -5886,7 +5889,8 @@ $ pulumi import aws:networkfirewall/resourcePolicy:ResourcePolicy example arn:aw
i := &tfbridge.PythonInfo{
Requires: map[string]string{
"pulumi": ">=3.0.0,<4.0.0",
}}
},
}
i.PyProject.Enabled = true
return i
})(),
Expand Down

0 comments on commit a1ec31f

Please sign in to comment.