@@ -49,6 +49,71 @@ type Meta struct {
4949 credentialsSource * CredentialsSource
5050}
5151
52+ // NewMeta creates the Meta object containing the SDK client.
53+ func NewMeta (ctx context.Context , config * Config ) (* Meta , error ) {
54+ ////
55+ // Load Profile
56+ ////
57+ profile , credentialsSource , err := loadProfile (ctx , config .ProviderSchema )
58+ if err != nil {
59+ return nil , err
60+ }
61+
62+ if config .ForceZone != "" {
63+ region , err := config .ForceZone .Region ()
64+ if err != nil {
65+ return nil , err
66+ }
67+
68+ profile .DefaultRegion = scw .StringPtr (region .String ())
69+ profile .DefaultZone = scw .StringPtr (config .ForceZone .String ())
70+ }
71+
72+ if config .ForceProjectID != "" {
73+ profile .DefaultProjectID = scw .StringPtr (config .ForceProjectID )
74+ }
75+
76+ if config .ForceOrganizationID != "" {
77+ profile .DefaultOrganizationID = scw .StringPtr (config .ForceOrganizationID )
78+ }
79+
80+ if config .ForceAccessKey != "" {
81+ profile .AccessKey = scw .StringPtr (config .ForceAccessKey )
82+ }
83+
84+ if config .ForceSecretKey != "" {
85+ profile .SecretKey = scw .StringPtr (config .ForceSecretKey )
86+ }
87+
88+ // TODO validated profile
89+
90+ ////
91+ // Create scaleway SDK client
92+ ////
93+ opts := []scw.ClientOption {
94+ scw .WithUserAgent (customizeUserAgent (version .Version , config .TerraformVersion )),
95+ scw .WithProfile (profile ),
96+ }
97+
98+ httpClient := & http.Client {Transport : transport .NewRetryableTransport (http .DefaultTransport )}
99+ if config .HTTPClient != nil {
100+ httpClient = config .HTTPClient
101+ }
102+
103+ opts = append (opts , scw .WithHTTPClient (httpClient ))
104+
105+ scwClient , err := scw .NewClient (opts ... )
106+ if err != nil {
107+ return nil , err
108+ }
109+
110+ return & Meta {
111+ scwClient : scwClient ,
112+ httpClient : httpClient ,
113+ credentialsSource : credentialsSource ,
114+ }, nil
115+ }
116+
52117func (m Meta ) ScwClient () * scw.Client {
53118 return m .scwClient
54119}
@@ -129,71 +194,6 @@ type Config struct {
129194 ForceSecretKey string
130195}
131196
132- // NewMeta creates the Meta object containing the SDK client.
133- func NewMeta (ctx context.Context , config * Config ) (* Meta , error ) {
134- ////
135- // Load Profile
136- ////
137- profile , credentialsSource , err := loadProfile (ctx , config .ProviderSchema )
138- if err != nil {
139- return nil , err
140- }
141-
142- if config .ForceZone != "" {
143- region , err := config .ForceZone .Region ()
144- if err != nil {
145- return nil , err
146- }
147-
148- profile .DefaultRegion = scw .StringPtr (region .String ())
149- profile .DefaultZone = scw .StringPtr (config .ForceZone .String ())
150- }
151-
152- if config .ForceProjectID != "" {
153- profile .DefaultProjectID = scw .StringPtr (config .ForceProjectID )
154- }
155-
156- if config .ForceOrganizationID != "" {
157- profile .DefaultOrganizationID = scw .StringPtr (config .ForceOrganizationID )
158- }
159-
160- if config .ForceAccessKey != "" {
161- profile .AccessKey = scw .StringPtr (config .ForceAccessKey )
162- }
163-
164- if config .ForceSecretKey != "" {
165- profile .SecretKey = scw .StringPtr (config .ForceSecretKey )
166- }
167-
168- // TODO validated profile
169-
170- ////
171- // Create scaleway SDK client
172- ////
173- opts := []scw.ClientOption {
174- scw .WithUserAgent (customizeUserAgent (version .Version , config .TerraformVersion )),
175- scw .WithProfile (profile ),
176- }
177-
178- httpClient := & http.Client {Transport : transport .NewRetryableTransport (http .DefaultTransport )}
179- if config .HTTPClient != nil {
180- httpClient = config .HTTPClient
181- }
182-
183- opts = append (opts , scw .WithHTTPClient (httpClient ))
184-
185- scwClient , err := scw .NewClient (opts ... )
186- if err != nil {
187- return nil , err
188- }
189-
190- return & Meta {
191- scwClient : scwClient ,
192- httpClient : httpClient ,
193- credentialsSource : credentialsSource ,
194- }, nil
195- }
196-
197197func customizeUserAgent (providerVersion string , terraformVersion string ) string {
198198 userAgent := fmt .Sprintf ("terraform-provider/%s terraform/%s" , providerVersion , terraformVersion )
199199
0 commit comments