@@ -79,19 +79,33 @@ func s3ClientWithRegion(d *schema.ResourceData, m interface{}) (*s3.S3, scw.Regi
7979 return s3Client , region , err
8080}
8181
82- func s3ClientWithRegionAndName (d * schema.ResourceData , m interface {}, name string ) (* s3.S3 , scw.Region , string , error ) {
82+ func s3ClientWithRegionAndName (d * schema.ResourceData , m interface {}, id string ) (* s3.S3 , scw.Region , string , error ) {
8383 meta := m .(* Meta )
84- region , name , err := parseRegionalID (name )
84+ region , name , err := parseRegionalID (id )
8585 if err != nil {
8686 return nil , "" , "" , err
8787 }
8888
89- accessKey , _ := meta . scwClient . GetAccessKey ( )
90- if projectID , isDefaultProjectID , err := extractProjectID ( d , meta ); err == nil && ! isDefaultProjectID {
91- accessKey = accessKeyWithProjectID ( accessKey , projectID )
89+ parts := strings . Split ( name , "@" )
90+ if len ( parts ) > 2 {
91+ return nil , "" , "" , fmt . Errorf ( "invalid ID %q: expected ID in format <region>/<name>[@<project_id>]" , id )
9292 }
93+ name = parts [0 ]
94+
95+ d .SetId (fmt .Sprintf ("%s/%s" , region , name ))
96+
97+ accessKey , _ := meta .scwClient .GetAccessKey ()
9398 secretKey , _ := meta .scwClient .GetSecretKey ()
9499
100+ if len (parts ) == 2 {
101+ accessKey = accessKeyWithProjectID (accessKey , parts [1 ])
102+ } else {
103+ extractedProjectID , isDefaultProjectID , err := extractProjectID (d , meta )
104+ if err == nil && ! isDefaultProjectID {
105+ accessKey = accessKeyWithProjectID (accessKey , extractedProjectID )
106+ }
107+ }
108+
95109 s3Client , err := newS3Client (meta .httpClient , region .String (), accessKey , secretKey )
96110 if err != nil {
97111 return nil , "" , "" , err
0 commit comments