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

Commit

Permalink
Lifecycle policy support
Browse files Browse the repository at this point in the history
  • Loading branch information
intiluha authored and 0ndi committed Jun 9, 2021
1 parent 2a3c71b commit 6c7c7e3
Show file tree
Hide file tree
Showing 10 changed files with 975 additions and 12 deletions.
141 changes: 141 additions & 0 deletions docs/resources/gcore_lifecyclepolicy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "gcore_lifecyclepolicy Resource - terraform-provider-gcorelabs"
subcategory: ""
description: |-
Represent lifecycle policy. Use to periodically take snapshots
---

# gcore_lifecyclepolicy (Resource)

Represent lifecycle policy. Use to periodically take snapshots

## Example Usage

```terraform
provider gcore {
user_name = "test"
password = "test"
gcore_platform = "https://api.gcdn.co"
gcore_api = "https://api.cloud.gcorelabs.com"
}
resource "gcore_lifecyclepolicy" "lp" {
project_id = 1
region_id = 1
name = "test"
status = "active"
action = "volume_snapshot"
volume {
id = "fe93bfdd-4ce3-4041-b89b-4f10d0d49498"
}
schedule {
max_quantity = 4
interval {
weeks = 1
days = 2
hours = 3
minutes = 4
}
resource_name_template = "reserve snap of the volume {volume_id}"
retention_time {
weeks = 4
days = 3
hours = 2
minutes = 1
}
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- **name** (String)

### Optional

- **action** (String)
- **id** (String) The ID of this resource.
- **project_id** (Number)
- **project_name** (String)
- **region_id** (Number)
- **region_name** (String)
- **schedule** (Block List) (see [below for nested schema](#nestedblock--schedule))
- **status** (String)
- **volume** (Block Set) List of managed volumes (see [below for nested schema](#nestedblock--volume))

### Read-Only

- **user_id** (Number)

<a id="nestedblock--schedule"></a>
### Nested Schema for `schedule`

Required:

- **max_quantity** (Number) Maximum number of stored resources

Optional:

- **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))
- **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))
- **resource_name_template** (String) Used to name snapshots. {volume_id} is substituted with volume.id on creation
- **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))

Read-Only:

- **id** (String) The ID of this resource.
- **type** (String)

<a id="nestedblock--schedule--cron"></a>
### Nested Schema for `schedule.cron`

Optional:

- **day** (String) Either single asterisk or comma-separated list of integers (1-31)
- **day_of_week** (String) Either single asterisk or comma-separated list of integers (0-6)
- **hour** (String) Either single asterisk or comma-separated list of integers (0-23)
- **minute** (String) Either single asterisk or comma-separated list of integers (0-59)
- **month** (String) Either single asterisk or comma-separated list of integers (1-12)
- **timezone** (String)
- **week** (String) Either single asterisk or comma-separated list of integers (1-53)


<a id="nestedblock--schedule--interval"></a>
### Nested Schema for `schedule.interval`

Optional:

- **days** (Number) Number of days to wait between actions
- **hours** (Number) Number of hours to wait between actions
- **minutes** (Number) Number of minutes to wait between actions
- **weeks** (Number) Number of weeks to wait between actions


<a id="nestedblock--schedule--retention_time"></a>
### Nested Schema for `schedule.retention_time`

Optional:

- **days** (Number) Number of days to wait before deleting snapshot
- **hours** (Number) Number of hours to wait before deleting snapshot
- **minutes** (Number) Number of minutes to wait before deleting snapshot
- **weeks** (Number) Number of weeks to wait before deleting snapshot



<a id="nestedblock--volume"></a>
### Nested Schema for `volume`

Required:

- **id** (String) The ID of this resource.

Read-Only:

- **name** (String)


33 changes: 33 additions & 0 deletions examples/resources/gcore_lifecyclepolicy/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
provider gcore {
user_name = "test"
password = "test"
gcore_platform = "https://api.gcdn.co"
gcore_api = "https://api.cloud.gcorelabs.com"
}

resource "gcore_lifecyclepolicy" "lp" {
project_id = 1
region_id = 1
name = "test"
status = "active"
action = "volume_snapshot"
volume {
id = "fe93bfdd-4ce3-4041-b89b-4f10d0d49498"
}
schedule {
max_quantity = 4
interval {
weeks = 1
days = 2
hours = 3
minutes = 4
}
resource_name_template = "reserve snap of the volume {volume_id}"
retention_time {
weeks = 4
days = 3
hours = 2
minutes = 1
}
}
}
5 changes: 4 additions & 1 deletion gcore/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
const (
ProviderOptPermanentToken = "permanent_api_token"
ProviderOptSkipCredsAuthErr = "ignore_creds_auth_error"

lifecyclePolicyResource = "gcore_lifecyclepolicy"
)

func Provider() *schema.Provider {
Expand Down Expand Up @@ -101,6 +103,7 @@ func Provider() *schema.Provider {
"gcore_cdn_origingroup": resourceCDNOriginGroup(),
"gcore_cdn_rule": resourceCDNRule(),
"gcore_cdn_sslcert": resourceCDNCert(),
lifecyclePolicyResource: resourceLifecyclePolicy(),
},
DataSourcesMap: map[string]*schema.Resource{
"gcore_project": dataSourceProject(),
Expand Down Expand Up @@ -163,7 +166,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
}))
cdnService := gcdn.NewService(cdnProvider)

stHost, stPath, err := ExtractHosAndPath(storageAPI)
stHost, stPath, err := ExtractHostAndPath(storageAPI)
if err != nil {
return nil, diag.FromErr(fmt.Errorf("storage api url: %w", err))
}
Expand Down
4 changes: 2 additions & 2 deletions gcore/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ func objectInfo(resourceType string) string {
// resourceType is a word in capital letters
keyID := fmt.Sprintf("TEST_%s_ID", resourceType)
keyName := fmt.Sprintf("TEST_%s_NAME", resourceType)
if regionID, exists := os.LookupEnv(keyID); exists {
return fmt.Sprintf(`%s_id = %s`, strings.ToLower(resourceType), regionID)
if objectID, exists := os.LookupEnv(keyID); exists {
return fmt.Sprintf(`%s_id = %s`, strings.ToLower(resourceType), objectID)
}
return fmt.Sprintf(`%s_name = "%s"`, strings.ToLower(resourceType), os.Getenv(keyName))
}
Expand Down
Loading

0 comments on commit 6c7c7e3

Please sign in to comment.