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

Commit 057138d

Browse files
vvelikodnyVitaly Velikodny
andauthored
* add terraform import support for CDN resources (#73)
* update CDN resources examples Co-authored-by: Vitaly Velikodny <[email protected]>
1 parent e2a5ba4 commit 057138d

File tree

8 files changed

+99
-28
lines changed

8 files changed

+99
-28
lines changed

examples/resources/gcore_cdn_origingroup/resource.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
provider gcore {
2-
user_name = "test"
3-
password = "test"
2+
# G-Core dashboard => Profile => API tokens => Create token
3+
permanent_api_token = ""
4+
5+
# user_name = "test"
6+
# password = "test"
7+
48
gcore_platform = "https://api.gcdn.co"
59
gcore_cdn_api = "https://api.gcdn.co"
610
}

examples/resources/gcore_cdn_resource/resource.tf

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
provider gcore {
2-
user_name = "test"
3-
password = "test"
2+
# G-Core dashboard => Profile => API tokens => Create token
3+
permanent_api_token = ""
4+
5+
# user_name = "test"
6+
# password = "test"
7+
48
gcore_platform = "https://api.gcdn.co"
59
gcore_cdn_api = "https://api.gcdn.co"
610
}
@@ -11,4 +15,28 @@ resource "gcore_cdn_resource" "cdn_example_com" {
1115
origin_group = gcore_cdn_origingroup.origin_group_1.id
1216
origin_protocol = "MATCH"
1317
secondary_hostnames = ["cdn2.example.com"]
18+
19+
options {
20+
browser_cache_settings {
21+
value = "1d"
22+
}
23+
redirect_http_to_https {
24+
value = true
25+
}
26+
gzip_on {
27+
value = true
28+
}
29+
cors {
30+
value = [
31+
"*"
32+
]
33+
}
34+
rewrite {
35+
body = "/(.*) /$1"
36+
}
37+
webp {
38+
jpg_quality = 55
39+
png_quality = 66
40+
}
41+
}
1442
}

examples/resources/gcore_cdn_rule/resource.tf

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,58 @@
11
provider gcore {
2-
user_name = "test"
3-
password = "test"
2+
# G-Core dashboard => Profile => API tokens => Create token
3+
permanent_api_token = ""
4+
5+
# user_name = "test"
6+
# password = "test"
7+
48
gcore_platform = "https://api.gcdn.co"
59
gcore_cdn_api = "https://api.gcdn.co"
610
}
711

12+
resource "gcore_cdn_rule" "cdn_example_com_rule_1" {
13+
resource_id = gcore_cdn_resource.cdn_example_com.id
14+
name = "All PNG images"
15+
rule = "/folder/images/*.png"
16+
rule_type = 0
17+
18+
options {
19+
edge_cache_settings {
20+
default = "4d"
21+
}
22+
redirect_http_to_https {
23+
value = true
24+
}
25+
gzip_on {
26+
value = true
27+
}
28+
}
29+
}
30+
31+
resource "gcore_cdn_rule" "cdn_example_com_rule_2" {
32+
resource_id = gcore_cdn_resource.cdn_example_com.id
33+
name = "All JS scripts"
34+
rule = "/folder/images/*.js"
35+
rule_type = 0
36+
37+
options {
38+
redirect_http_to_https {
39+
enabled = false
40+
value = true
41+
}
42+
gzip_on {
43+
enabled = false
44+
value = true
45+
}
46+
}
47+
}
48+
849
resource "gcore_cdn_origingroup" "origin_group_1" {
950
name = "origin_group_1"
1051
use_next = true
1152
origin {
1253
source = "example.com"
1354
enabled = true
1455
}
15-
origin {
16-
source = "mirror.example.com"
17-
enabled = true
18-
backup = true
19-
}
2056
}
2157

2258
resource "gcore_cdn_resource" "cdn_example_com" {
@@ -25,17 +61,3 @@ resource "gcore_cdn_resource" "cdn_example_com" {
2561
origin_protocol = "MATCH"
2662
secondary_hostnames = ["cdn2.example.com"]
2763
}
28-
29-
resource "gcore_cdn_rule" "cdn_example_com_rule_1" {
30-
resource_id = gcore_cdn_resource.cdn_example_com.id
31-
name = "All images"
32-
rule = "/folder/images/*.png"
33-
rule_type = 0
34-
}
35-
36-
resource "gcore_cdn_rule" "cdn_example_com_rule_2" {
37-
resource_id = gcore_cdn_resource.cdn_example_com.id
38-
name = "All scripts"
39-
rule = "/folder/images/*.js"
40-
rule_type = 0
41-
}

examples/resources/gcore_cdn_sslcert/resource.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
provider gcore {
2-
user_name = "test"
3-
password = "test"
2+
# G-Core dashboard => Profile => API tokens => Create token
3+
permanent_api_token = ""
4+
5+
# user_name = "test"
6+
# password = "test"
7+
48
gcore_platform = "https://api.gcdn.co"
59
gcore_cdn_api = "https://api.gcdn.co"
610
}

gcore/resource_gcore_cdn_origin_group.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616

1717
func resourceCDNOriginGroup() *schema.Resource {
1818
return &schema.Resource{
19+
Importer: &schema.ResourceImporter{
20+
StateContext: schema.ImportStatePassthroughContext,
21+
},
1922
Schema: map[string]*schema.Schema{
2023
"name": {
2124
Type: schema.TypeString,

gcore/resource_gcore_cdn_resource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import (
1515

1616
func resourceCDNResource() *schema.Resource {
1717
return &schema.Resource{
18+
Importer: &schema.ResourceImporter{
19+
StateContext: schema.ImportStatePassthroughContext,
20+
},
1821
Schema: map[string]*schema.Schema{
1922
"cname": {
2023
Type: schema.TypeString,

gcore/resource_gcore_cdn_rule.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313

1414
func resourceCDNRule() *schema.Resource {
1515
return &schema.Resource{
16+
Importer: &schema.ResourceImporter{
17+
StateContext: schema.ImportStatePassthroughContext,
18+
},
1619
Schema: map[string]*schema.Schema{
1720
"resource_id": {
1821
Type: schema.TypeInt,
@@ -51,7 +54,8 @@ func resourceCDNRule() *schema.Resource {
5154
Schema: map[string]*schema.Schema{
5255
"enabled": {
5356
Type: schema.TypeBool,
54-
Required: true,
57+
Optional: true,
58+
Default: true,
5559
},
5660
"value": {
5761
Type: schema.TypeString,

gcore/resource_gcore_cdn_sslcerts.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313

1414
func resourceCDNCert() *schema.Resource {
1515
return &schema.Resource{
16+
Importer: &schema.ResourceImporter{
17+
StateContext: schema.ImportStatePassthroughContext,
18+
},
1619
Schema: map[string]*schema.Schema{
1720
"name": {
1821
Type: schema.TypeString,

0 commit comments

Comments
 (0)