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

Commit 6c7c7e3

Browse files
intiluha0ndi
authored andcommitted
Lifecycle policy support
1 parent 2a3c71b commit 6c7c7e3

File tree

10 files changed

+975
-12
lines changed

10 files changed

+975
-12
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gcore_lifecyclepolicy Resource - terraform-provider-gcorelabs"
4+
subcategory: ""
5+
description: |-
6+
Represent lifecycle policy. Use to periodically take snapshots
7+
---
8+
9+
# gcore_lifecyclepolicy (Resource)
10+
11+
Represent lifecycle policy. Use to periodically take snapshots
12+
13+
## Example Usage
14+
15+
```terraform
16+
provider gcore {
17+
user_name = "test"
18+
password = "test"
19+
gcore_platform = "https://api.gcdn.co"
20+
gcore_api = "https://api.cloud.gcorelabs.com"
21+
}
22+
23+
resource "gcore_lifecyclepolicy" "lp" {
24+
project_id = 1
25+
region_id = 1
26+
name = "test"
27+
status = "active"
28+
action = "volume_snapshot"
29+
volume {
30+
id = "fe93bfdd-4ce3-4041-b89b-4f10d0d49498"
31+
}
32+
schedule {
33+
max_quantity = 4
34+
interval {
35+
weeks = 1
36+
days = 2
37+
hours = 3
38+
minutes = 4
39+
}
40+
resource_name_template = "reserve snap of the volume {volume_id}"
41+
retention_time {
42+
weeks = 4
43+
days = 3
44+
hours = 2
45+
minutes = 1
46+
}
47+
}
48+
}
49+
```
50+
51+
<!-- schema generated by tfplugindocs -->
52+
## Schema
53+
54+
### Required
55+
56+
- **name** (String)
57+
58+
### Optional
59+
60+
- **action** (String)
61+
- **id** (String) The ID of this resource.
62+
- **project_id** (Number)
63+
- **project_name** (String)
64+
- **region_id** (Number)
65+
- **region_name** (String)
66+
- **schedule** (Block List) (see [below for nested schema](#nestedblock--schedule))
67+
- **status** (String)
68+
- **volume** (Block Set) List of managed volumes (see [below for nested schema](#nestedblock--volume))
69+
70+
### Read-Only
71+
72+
- **user_id** (Number)
73+
74+
<a id="nestedblock--schedule"></a>
75+
### Nested Schema for `schedule`
76+
77+
Required:
78+
79+
- **max_quantity** (Number) Maximum number of stored resources
80+
81+
Optional:
82+
83+
- **cron** (Block List, Max: 1) Use for taking actions at specified moments of time. Exactly one of interval and cron blocks should be provided (see [below for nested schema](#nestedblock--schedule--cron))
84+
- **interval** (Block List, Max: 1) Use for taking actions with equal time intervals between them. Exactly one of interval and cron blocks should be provided (see [below for nested schema](#nestedblock--schedule--interval))
85+
- **resource_name_template** (String) Used to name snapshots. {volume_id} is substituted with volume.id on creation
86+
- **retention_time** (Block List, Max: 1) If it is set, new resource will be deleted after time (see [below for nested schema](#nestedblock--schedule--retention_time))
87+
88+
Read-Only:
89+
90+
- **id** (String) The ID of this resource.
91+
- **type** (String)
92+
93+
<a id="nestedblock--schedule--cron"></a>
94+
### Nested Schema for `schedule.cron`
95+
96+
Optional:
97+
98+
- **day** (String) Either single asterisk or comma-separated list of integers (1-31)
99+
- **day_of_week** (String) Either single asterisk or comma-separated list of integers (0-6)
100+
- **hour** (String) Either single asterisk or comma-separated list of integers (0-23)
101+
- **minute** (String) Either single asterisk or comma-separated list of integers (0-59)
102+
- **month** (String) Either single asterisk or comma-separated list of integers (1-12)
103+
- **timezone** (String)
104+
- **week** (String) Either single asterisk or comma-separated list of integers (1-53)
105+
106+
107+
<a id="nestedblock--schedule--interval"></a>
108+
### Nested Schema for `schedule.interval`
109+
110+
Optional:
111+
112+
- **days** (Number) Number of days to wait between actions
113+
- **hours** (Number) Number of hours to wait between actions
114+
- **minutes** (Number) Number of minutes to wait between actions
115+
- **weeks** (Number) Number of weeks to wait between actions
116+
117+
118+
<a id="nestedblock--schedule--retention_time"></a>
119+
### Nested Schema for `schedule.retention_time`
120+
121+
Optional:
122+
123+
- **days** (Number) Number of days to wait before deleting snapshot
124+
- **hours** (Number) Number of hours to wait before deleting snapshot
125+
- **minutes** (Number) Number of minutes to wait before deleting snapshot
126+
- **weeks** (Number) Number of weeks to wait before deleting snapshot
127+
128+
129+
130+
<a id="nestedblock--volume"></a>
131+
### Nested Schema for `volume`
132+
133+
Required:
134+
135+
- **id** (String) The ID of this resource.
136+
137+
Read-Only:
138+
139+
- **name** (String)
140+
141+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
provider gcore {
2+
user_name = "test"
3+
password = "test"
4+
gcore_platform = "https://api.gcdn.co"
5+
gcore_api = "https://api.cloud.gcorelabs.com"
6+
}
7+
8+
resource "gcore_lifecyclepolicy" "lp" {
9+
project_id = 1
10+
region_id = 1
11+
name = "test"
12+
status = "active"
13+
action = "volume_snapshot"
14+
volume {
15+
id = "fe93bfdd-4ce3-4041-b89b-4f10d0d49498"
16+
}
17+
schedule {
18+
max_quantity = 4
19+
interval {
20+
weeks = 1
21+
days = 2
22+
hours = 3
23+
minutes = 4
24+
}
25+
resource_name_template = "reserve snap of the volume {volume_id}"
26+
retention_time {
27+
weeks = 4
28+
days = 3
29+
hours = 2
30+
minutes = 1
31+
}
32+
}
33+
}

gcore/provider.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
const (
1919
ProviderOptPermanentToken = "permanent_api_token"
2020
ProviderOptSkipCredsAuthErr = "ignore_creds_auth_error"
21+
22+
lifecyclePolicyResource = "gcore_lifecyclepolicy"
2123
)
2224

2325
func Provider() *schema.Provider {
@@ -101,6 +103,7 @@ func Provider() *schema.Provider {
101103
"gcore_cdn_origingroup": resourceCDNOriginGroup(),
102104
"gcore_cdn_rule": resourceCDNRule(),
103105
"gcore_cdn_sslcert": resourceCDNCert(),
106+
lifecyclePolicyResource: resourceLifecyclePolicy(),
104107
},
105108
DataSourcesMap: map[string]*schema.Resource{
106109
"gcore_project": dataSourceProject(),
@@ -163,7 +166,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
163166
}))
164167
cdnService := gcdn.NewService(cdnProvider)
165168

166-
stHost, stPath, err := ExtractHosAndPath(storageAPI)
169+
stHost, stPath, err := ExtractHostAndPath(storageAPI)
167170
if err != nil {
168171
return nil, diag.FromErr(fmt.Errorf("storage api url: %w", err))
169172
}

gcore/provider_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ func objectInfo(resourceType string) string {
224224
// resourceType is a word in capital letters
225225
keyID := fmt.Sprintf("TEST_%s_ID", resourceType)
226226
keyName := fmt.Sprintf("TEST_%s_NAME", resourceType)
227-
if regionID, exists := os.LookupEnv(keyID); exists {
228-
return fmt.Sprintf(`%s_id = %s`, strings.ToLower(resourceType), regionID)
227+
if objectID, exists := os.LookupEnv(keyID); exists {
228+
return fmt.Sprintf(`%s_id = %s`, strings.ToLower(resourceType), objectID)
229229
}
230230
return fmt.Sprintf(`%s_name = "%s"`, strings.ToLower(resourceType), os.Getenv(keyName))
231231
}

0 commit comments

Comments
 (0)