@@ -567,6 +567,10 @@ func (client *Client) TagS3BucketAccessLogging(ctx context.Context, l log.Logger
567567
568568 _ , err := client .s3Client .PutBucketTagging (ctx , & putBucketTaggingInput )
569569 if err != nil {
570+ if handleS3TaggingMethodNotAllowed (err , l , "access logging bucket" ) {
571+ return nil
572+ }
573+
570574 return errors .New (err )
571575 }
572576
@@ -601,6 +605,10 @@ func (client *Client) TagS3Bucket(ctx context.Context, l log.Logger) error {
601605
602606 _ , err := client .s3Client .PutBucketTagging (ctx , & putBucketTaggingInput )
603607 if err != nil {
608+ if handleS3TaggingMethodNotAllowed (err , l , cfg .Bucket ) {
609+ return nil
610+ }
611+
604612 return errors .New (err )
605613 }
606614
@@ -718,6 +726,7 @@ func (client *Client) EnableRootAccesstoS3Bucket(ctx context.Context, l log.Logg
718726
719727 // Access bucket name safely through defensive checking
720728 config := client .ExtendedRemoteStateConfigS3
729+
721730 bucket := config .RemoteStateConfigS3 .Bucket
722731 if bucket == "" {
723732 return errors .Errorf ("S3 bucket name is empty - cannot enable root access to S3 bucket" )
@@ -733,6 +742,7 @@ func (client *Client) EnableRootAccesstoS3Bucket(ctx context.Context, l log.Logg
733742 if err != nil {
734743 return errors .Errorf ("error getting AWS account ID %s for bucket %s: %w" , accountID , bucket , err )
735744 }
745+
736746 if accountID == "" {
737747 return errors .Errorf ("AWS account ID is empty - cannot enable root access to S3 bucket %s" , bucket )
738748 }
@@ -741,6 +751,7 @@ func (client *Client) EnableRootAccesstoS3Bucket(ctx context.Context, l log.Logg
741751 if err != nil {
742752 return errors .Errorf ("error getting AWS partition %s for bucket %s: %w" , partition , bucket , err )
743753 }
754+
744755 if partition == "" {
745756 return errors .Errorf ("AWS partition is empty - cannot enable root access to S3 bucket %s" , bucket )
746757 }
@@ -1898,3 +1909,15 @@ func isAWSResourceNotFoundError(err error) bool {
18981909 var apiErr smithy.APIError
18991910 return errors .As (err , & apiErr ) && apiErr .ErrorCode () == "ResourceNotFoundException"
19001911}
1912+
1913+ // handleS3TaggingMethodNotAllowed handles MethodNotAllowed errors for S3 bucket tagging operations
1914+ // Returns true if the error was handled (caller should return nil), false otherwise
1915+ func handleS3TaggingMethodNotAllowed (err error , l log.Logger , bucketName string ) bool {
1916+ var apiErr smithy.APIError
1917+ if errors .As (err , & apiErr ) && apiErr .ErrorCode () == "MethodNotAllowed" {
1918+ l .Warnf ("S3 bucket tagging is not supported for bucket %s - skipping tagging (this is normal for some AWS configurations)" , bucketName )
1919+ return true
1920+ }
1921+
1922+ return false
1923+ }
0 commit comments