8
8
"net/url"
9
9
"os"
10
10
11
- dnssdk "github.com/G-Core/g -dns-sdk-go"
11
+ dnssdk "github.com/G-Core/gcore -dns-sdk-go"
12
12
storageSDK "github.com/G-Core/gcore-storage-sdk-go"
13
13
gcdn "github.com/G-Core/gcorelabscdn-go"
14
14
gcdnProvider "github.com/G-Core/gcorelabscdn-go/gcore/provider"
@@ -19,8 +19,9 @@ import (
19
19
)
20
20
21
21
const (
22
- ProviderOptPermanentToken = "permanent_api_token"
23
- ProviderOptSkipCredsAuthErr = "ignore_creds_auth_error"
22
+ ProviderOptPermanentToken = "permanent_api_token"
23
+ ProviderOptSkipCredsAuthErr = "ignore_creds_auth_error"
24
+ ProviderOptSingleApiEndpoint = "api_endpoint"
24
25
25
26
lifecyclePolicyResource = "gcore_lifecyclepolicy"
26
27
)
@@ -45,6 +46,12 @@ func Provider() *schema.Provider {
45
46
Description : "A permanent [API-token](https://support.gcorelabs.com/hc/en-us/articles/360018625617-API-tokens)" ,
46
47
DefaultFunc : schema .EnvDefaultFunc ("GCORE_PERMANENT_TOKEN" , "" ),
47
48
},
49
+ ProviderOptSingleApiEndpoint : {
50
+ Type : schema .TypeString ,
51
+ Optional : true ,
52
+ Description : "A single API endpoint for all products. Will be used when specific product API url is not defined." ,
53
+ DefaultFunc : schema .EnvDefaultFunc ("GCORE_API_ENDPOINT" , "https://api.gcorelabs.com" ),
54
+ },
48
55
ProviderOptSkipCredsAuthErr : {
49
56
Type : schema .TypeBool ,
50
57
Optional : true ,
@@ -54,34 +61,48 @@ func Provider() *schema.Provider {
54
61
},
55
62
},
56
63
"gcore_platform" : {
64
+ Type : schema .TypeString ,
65
+ Optional : true ,
66
+ Deprecated : "Use gcore_platform_api instead" ,
67
+ Description : "Platform URL is used for generate JWT" ,
68
+ DefaultFunc : schema .EnvDefaultFunc ("GCORE_PLATFORM" , "" ),
69
+ },
70
+ "gcore_platform_api" : {
57
71
Type : schema .TypeString ,
58
72
Optional : true ,
59
73
Description : "Platform URL is used for generate JWT" ,
60
- DefaultFunc : schema .EnvDefaultFunc ("GCORE_PLATFORM " , "https://api.gcdn.co " ),
74
+ DefaultFunc : schema .EnvDefaultFunc ("GCORE_PLATFORM_API " , "" ),
61
75
},
62
76
"gcore_api" : {
77
+ Type : schema .TypeString ,
78
+ Optional : true ,
79
+ Deprecated : "Use gcore_cloud_api instead" ,
80
+ Description : "Region API" ,
81
+ DefaultFunc : schema .EnvDefaultFunc ("GCORE_API" , "" ),
82
+ },
83
+ "gcore_cloud_api" : {
63
84
Type : schema .TypeString ,
64
85
Optional : true ,
65
86
Description : "Region API" ,
66
- DefaultFunc : schema .EnvDefaultFunc ("GCORE_API " , "https://api.cloud.gcorelabs.com " ),
87
+ DefaultFunc : schema .EnvDefaultFunc ("GCORE_CLOUD_API " , "" ),
67
88
},
68
89
"gcore_cdn_api" : {
69
90
Type : schema .TypeString ,
70
91
Optional : true ,
71
92
Description : "CDN API" ,
72
- DefaultFunc : schema .EnvDefaultFunc ("GCORE_CDN_API" , "https://api.gcdn.co " ),
93
+ DefaultFunc : schema .EnvDefaultFunc ("GCORE_CDN_API" , "" ),
73
94
},
74
95
"gcore_storage_api" : {
75
96
Type : schema .TypeString ,
76
97
Optional : true ,
77
98
Description : "Storage API" ,
78
- DefaultFunc : schema .EnvDefaultFunc ("GCORE_STORAGE_API" , "https://api.gcorelabs.com/storage " ),
99
+ DefaultFunc : schema .EnvDefaultFunc ("GCORE_STORAGE_API" , "" ),
79
100
},
80
101
"gcore_dns_api" : {
81
102
Type : schema .TypeString ,
82
103
Optional : true ,
83
104
Description : "DNS API" ,
84
- DefaultFunc : schema .EnvDefaultFunc ("GCORE_DNS_API" , "https://dnsapi.gcorelabs.com " ),
105
+ DefaultFunc : schema .EnvDefaultFunc ("GCORE_DNS_API" , "" ),
85
106
},
86
107
"gcore_client_id" : {
87
108
Type : schema .TypeString ,
@@ -156,11 +177,39 @@ func providerConfigure(_ context.Context, d *schema.ResourceData) (interface{},
156
177
username := d .Get ("user_name" ).(string )
157
178
password := d .Get ("password" ).(string )
158
179
permanentToken := d .Get (ProviderOptPermanentToken ).(string )
159
- api := d .Get ("gcore_api" ).(string )
180
+ apiEndpoint := d .Get (ProviderOptSingleApiEndpoint ).(string )
181
+
182
+ cloudApi := d .Get ("gcore_cloud_api" ).(string )
183
+ if cloudApi == "" {
184
+ cloudApi = d .Get ("gcore_api" ).(string )
185
+ }
186
+ if cloudApi == "" {
187
+ cloudApi = apiEndpoint + "/cloud"
188
+ }
189
+
160
190
cdnAPI := d .Get ("gcore_cdn_api" ).(string )
191
+ if cdnAPI == "" {
192
+ cdnAPI = apiEndpoint
193
+ }
194
+
161
195
storageAPI := d .Get ("gcore_storage_api" ).(string )
196
+ if storageAPI == "" {
197
+ storageAPI = apiEndpoint + "/storage"
198
+ }
199
+
162
200
dnsAPI := d .Get ("gcore_dns_api" ).(string )
163
- platform := d .Get ("gcore_platform" ).(string )
201
+ if dnsAPI == "" {
202
+ dnsAPI = apiEndpoint + "/dns"
203
+ }
204
+
205
+ platform := d .Get ("gcore_platform_api" ).(string )
206
+ if platform == "" {
207
+ platform = d .Get ("gcore_platform" ).(string )
208
+ }
209
+ if platform == "" {
210
+ platform = apiEndpoint
211
+ }
212
+
164
213
clientID := d .Get ("gcore_client_id" ).(string )
165
214
166
215
var diags diag.Diagnostics
@@ -169,12 +218,12 @@ func providerConfigure(_ context.Context, d *schema.ResourceData) (interface{},
169
218
var provider * gcorecloud.ProviderClient
170
219
if permanentToken != "" {
171
220
provider , err = gc .APITokenClient (gcorecloud.APITokenOptions {
172
- APIURL : api ,
221
+ APIURL : cloudApi ,
173
222
APIToken : permanentToken ,
174
223
})
175
224
} else {
176
225
provider , err = gc .AuthenticatedClient (gcorecloud.AuthOptions {
177
- APIURL : api ,
226
+ APIURL : cloudApi ,
178
227
AuthURL : platform ,
179
228
Username : username ,
180
229
Password : password ,
0 commit comments