From a1ec31f3b8519a73f7db8fedcf51372960aad1f7 Mon Sep 17 00:00:00 2001 From: VenelinMartinov Date: Mon, 27 Nov 2023 19:25:41 +0000 Subject: [PATCH] Replace credential validation once with atomic bool (#3051) 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. --- provider/resources.go | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/provider/resources.go b/provider/resources.go index 7216f088207..4cb06affdba 100644 --- a/provider/resources.go +++ b/provider/resources.go @@ -22,7 +22,7 @@ import ( "path/filepath" "strconv" "strings" - "sync" + "sync/atomic" "unicode" "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" @@ -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 @@ -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 } @@ -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{ @@ -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{ @@ -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{ @@ -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"}, }, @@ -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{ @@ -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"), }, @@ -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")}, @@ -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"), }, @@ -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), @@ -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 })(),