Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit cb69250

Browse files
authored
+ add single api_endpoint for clients, + add examples for content of dns records (#91)
1 parent af432a4 commit cb69250

File tree

9 files changed

+124
-23
lines changed

9 files changed

+124
-23
lines changed

docs/index.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,14 @@ resource "gcore_lbmember" "lbm2" {
250250

251251
### Optional
252252

253-
- `gcore_api` (String) Region API
253+
- `api_endpoint` (String) A single API endpoint for all products. Will be used when specific product API url is not defined.
254+
- `gcore_api` (String, Deprecated) Region API
254255
- `gcore_cdn_api` (String) CDN API
255256
- `gcore_client_id` (String) Client id
257+
- `gcore_cloud_api` (String) Region API
256258
- `gcore_dns_api` (String) DNS API
257-
- `gcore_platform` (String) Platform URL is used for generate JWT
259+
- `gcore_platform` (String, Deprecated) Platform URL is used for generate JWT
260+
- `gcore_platform_api` (String) Platform URL is used for generate JWT
258261
- `gcore_storage_api` (String) Storage API
259262
- `ignore_creds_auth_error` (Boolean) Should be set to true when you are gonna to use storage resource with permanent API-token only.
260263
- `password` (String)

docs/resources/gcore_dns_zone_record.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,30 @@ resource "gcore_dns_zone_record" "subdomain_examplezone" {
7979
}
8080
}
8181
}
82+
83+
resource "gcore_dns_zone_record" "subdomain_examplezone_mx" {
84+
zone = "examplezone.com"
85+
domain = "subdomain.examplezone.com"
86+
type = "MX"
87+
ttl = 10
88+
89+
resource_record {
90+
content = "10 mail.my.com."
91+
enabled = true
92+
}
93+
}
94+
95+
resource "gcore_dns_zone_record" "subdomain_examplezone_caa" {
96+
zone = "examplezone.com"
97+
domain = "subdomain.examplezone.com"
98+
type = "CAA"
99+
ttl = 10
100+
101+
resource_record {
102+
content = "0 issue \"company.org; account=12345\""
103+
enabled = true
104+
}
105+
}
82106
```
83107

84108
<!-- schema generated by tfplugindocs -->
@@ -102,7 +126,7 @@ resource "gcore_dns_zone_record" "subdomain_examplezone" {
102126

103127
Required:
104128

105-
- `content` (String) A content of DNS Zone Record resource.
129+
- `content` (String) A content of DNS Zone Record resource. (TXT: 'anyString', MX: '50 mail.company.io.', CAA: '0 issue "company.org; account=12345"')
106130

107131
Optional:
108132

examples/resources/gcore_dns_zone_record/resource.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,27 @@ resource "gcore_dns_zone_record" "subdomain_examplezone" {
6464
}
6565
}
6666
}
67+
68+
resource "gcore_dns_zone_record" "subdomain_examplezone_mx" {
69+
zone = "examplezone.com"
70+
domain = "subdomain.examplezone.com"
71+
type = "MX"
72+
ttl = 10
73+
74+
resource_record {
75+
content = "10 mail.my.com."
76+
enabled = true
77+
}
78+
}
79+
80+
resource "gcore_dns_zone_record" "subdomain_examplezone_caa" {
81+
zone = "examplezone.com"
82+
domain = "subdomain.examplezone.com"
83+
type = "CAA"
84+
ttl = 10
85+
86+
resource_record {
87+
content = "0 issue \"company.org; account=12345\""
88+
enabled = true
89+
}
90+
}

gcore/provider.go

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"net/url"
99
"os"
1010

11-
dnssdk "github.com/G-Core/g-dns-sdk-go"
11+
dnssdk "github.com/G-Core/gcore-dns-sdk-go"
1212
storageSDK "github.com/G-Core/gcore-storage-sdk-go"
1313
gcdn "github.com/G-Core/gcorelabscdn-go"
1414
gcdnProvider "github.com/G-Core/gcorelabscdn-go/gcore/provider"
@@ -19,8 +19,9 @@ import (
1919
)
2020

2121
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"
2425

2526
lifecyclePolicyResource = "gcore_lifecyclepolicy"
2627
)
@@ -45,6 +46,12 @@ func Provider() *schema.Provider {
4546
Description: "A permanent [API-token](https://support.gcorelabs.com/hc/en-us/articles/360018625617-API-tokens)",
4647
DefaultFunc: schema.EnvDefaultFunc("GCORE_PERMANENT_TOKEN", ""),
4748
},
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+
},
4855
ProviderOptSkipCredsAuthErr: {
4956
Type: schema.TypeBool,
5057
Optional: true,
@@ -54,34 +61,48 @@ func Provider() *schema.Provider {
5461
},
5562
},
5663
"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": {
5771
Type: schema.TypeString,
5872
Optional: true,
5973
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", ""),
6175
},
6276
"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": {
6384
Type: schema.TypeString,
6485
Optional: true,
6586
Description: "Region API",
66-
DefaultFunc: schema.EnvDefaultFunc("GCORE_API", "https://api.cloud.gcorelabs.com"),
87+
DefaultFunc: schema.EnvDefaultFunc("GCORE_CLOUD_API", ""),
6788
},
6889
"gcore_cdn_api": {
6990
Type: schema.TypeString,
7091
Optional: true,
7192
Description: "CDN API",
72-
DefaultFunc: schema.EnvDefaultFunc("GCORE_CDN_API", "https://api.gcdn.co"),
93+
DefaultFunc: schema.EnvDefaultFunc("GCORE_CDN_API", ""),
7394
},
7495
"gcore_storage_api": {
7596
Type: schema.TypeString,
7697
Optional: true,
7798
Description: "Storage API",
78-
DefaultFunc: schema.EnvDefaultFunc("GCORE_STORAGE_API", "https://api.gcorelabs.com/storage"),
99+
DefaultFunc: schema.EnvDefaultFunc("GCORE_STORAGE_API", ""),
79100
},
80101
"gcore_dns_api": {
81102
Type: schema.TypeString,
82103
Optional: true,
83104
Description: "DNS API",
84-
DefaultFunc: schema.EnvDefaultFunc("GCORE_DNS_API", "https://dnsapi.gcorelabs.com"),
105+
DefaultFunc: schema.EnvDefaultFunc("GCORE_DNS_API", ""),
85106
},
86107
"gcore_client_id": {
87108
Type: schema.TypeString,
@@ -156,11 +177,39 @@ func providerConfigure(_ context.Context, d *schema.ResourceData) (interface{},
156177
username := d.Get("user_name").(string)
157178
password := d.Get("password").(string)
158179
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+
160190
cdnAPI := d.Get("gcore_cdn_api").(string)
191+
if cdnAPI == "" {
192+
cdnAPI = apiEndpoint
193+
}
194+
161195
storageAPI := d.Get("gcore_storage_api").(string)
196+
if storageAPI == "" {
197+
storageAPI = apiEndpoint + "/storage"
198+
}
199+
162200
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+
164213
clientID := d.Get("gcore_client_id").(string)
165214

166215
var diags diag.Diagnostics
@@ -169,12 +218,12 @@ func providerConfigure(_ context.Context, d *schema.ResourceData) (interface{},
169218
var provider *gcorecloud.ProviderClient
170219
if permanentToken != "" {
171220
provider, err = gc.APITokenClient(gcorecloud.APITokenOptions{
172-
APIURL: api,
221+
APIURL: cloudApi,
173222
APIToken: permanentToken,
174223
})
175224
} else {
176225
provider, err = gc.AuthenticatedClient(gcorecloud.AuthOptions{
177-
APIURL: api,
226+
APIURL: cloudApi,
178227
AuthURL: platform,
179228
Username: username,
180229
Password: password,

gcore/provider_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010
"testing"
1111

12-
dnssdk "github.com/G-Core/g-dns-sdk-go"
12+
dnssdk "github.com/G-Core/gcore-dns-sdk-go"
1313
storageSDK "github.com/G-Core/gcore-storage-sdk-go"
1414
gcdn "github.com/G-Core/gcorelabscdn-go"
1515
gcdnProvider "github.com/G-Core/gcorelabscdn-go/gcore/provider"

gcore/resource_gcore_dns_zone_record.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"net"
99
"strings"
1010

11-
dnssdk "github.com/G-Core/g-dns-sdk-go"
11+
dnssdk "github.com/G-Core/gcore-dns-sdk-go"
1212
"github.com/hashicorp/go-cty/cty"
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -140,7 +140,7 @@ func resourceDNSZoneRecord() *schema.Resource {
140140
DNSZoneRecordSchemaContent: {
141141
Type: schema.TypeString,
142142
Required: true,
143-
Description: "A content of DNS Zone Record resource.",
143+
Description: `A content of DNS Zone Record resource. (TXT: 'anyString', MX: '50 mail.company.io.', CAA: '0 issue "company.org; account=12345"')`,
144144
},
145145
DNSZoneRecordSchemaEnabled: {
146146
Type: schema.TypeBool,

gcore/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"strconv"
1414
"strings"
1515

16-
dnssdk "github.com/G-Core/g-dns-sdk-go"
16+
dnssdk "github.com/G-Core/gcore-dns-sdk-go"
1717
storageSDK "github.com/G-Core/gcore-storage-sdk-go"
1818
gcdn "github.com/G-Core/gcorelabscdn-go"
1919
gcorecloud "github.com/G-Core/gcorelabscloud-go"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.17
44

55
require (
66
github.com/AlekSi/pointer v1.2.0
7-
github.com/G-Core/g-dns-sdk-go v0.1.2
7+
github.com/G-Core/gcore-dns-sdk-go v0.2.1
88
github.com/G-Core/gcore-storage-sdk-go v0.1.2
99
github.com/G-Core/gcorelabscdn-go v0.1.19
1010
github.com/G-Core/gcorelabscloud-go v0.4.49

go.sum

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6L
4141
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
4242
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4343
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
44-
github.com/G-Core/g-dns-sdk-go v0.1.2 h1:XYgsdOtflZH106UUcArhmrfgNpwfqT1PSCAuTf+QI9o=
45-
github.com/G-Core/g-dns-sdk-go v0.1.2/go.mod h1:uArGxDKZjXzfIYGoBd9kuXkrd3RbMzv63TzGbyAci/c=
44+
github.com/G-Core/gcore-dns-sdk-go v0.2.1 h1:fX9vAEPpaiaMx/3Sfw4pmMqFPajCKli7gfLcjS8QCCU=
45+
github.com/G-Core/gcore-dns-sdk-go v0.2.1/go.mod h1:TM+VaDvBPObF+x085lS3i0kc2OPAkuW2c4Leg7Pe6jI=
4646
github.com/G-Core/gcore-storage-sdk-go v0.1.2 h1:bCKATw47kwYZLXDCgiQ4IS5ecwSv9HQF7FhgcA0knSc=
4747
github.com/G-Core/gcore-storage-sdk-go v0.1.2/go.mod h1:e/5w5R2Uh6T7g6oAc5SpTKZJInFG6FyYYvGpUgRwCQ4=
4848
github.com/G-Core/gcorelabscdn-go v0.1.19 h1:Vu7BRcRmSALqSpvwxZvwQnRpQ3B/cK94dNLppYMgq80=
@@ -591,8 +591,9 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
591591
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
592592
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
593593
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
594-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
595594
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
595+
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
596+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
596597
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
597598
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
598599
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=

0 commit comments

Comments
 (0)