Add support for snapshot policies#223
Merged
kiranchavala merged 13 commits intomainfrom Sep 22, 2025
Merged
Conversation
Member
kiranchavala
left a comment
There was a problem hiding this comment.
https://cloudstack.apache.org/api/apidocs-4.21/apis/updateSnapshotPolicy.html
Suppose i change max_snaps via terraform after a resource is deployed
its not actually changed in the cloudstack , the terraform.tfstate contains
"max_snaps": 2,
resource "cloudstack_snapshot_policy" "frequent_backup" {
volume_id = "fc2e91ee-699c-489d-b005-f0afafdcbf41"
interval_type = "HOURLY"
max_snaps = 2
schedule = "2"
timezone = "UTC"
tags = {
Environment = "demo"
}
}
terraform apply
cloudstack_snapshot_policy.frequent_backup_DAILY: Refreshing state... [id=b070fba3-f751-4528-989b-785cf445d5bb]
cloudstack_snapshot_policy.frequent_backup: Refreshing state... [id=b070fba3-f751-4528-989b-785cf445d5bb]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# cloudstack_snapshot_policy.frequent_backup will be updated in-place
~ resource "cloudstack_snapshot_policy" "frequent_backup" {
id = "b070fba3-f751-4528-989b-785cf445d5bb"
~ max_snaps = 1 -> 2
~ schedule = "00:00" -> "2"
tags = {
"Environment" = "demo"
}
~ zone_ids = [
- "05d9863d-bd94-41c2-bba8-251aab44637a",
]
# (3 unchanged attributes hidden)
}
# cloudstack_snapshot_policy.frequent_backup_DAILY will be updated in-place
~ resource "cloudstack_snapshot_policy" "frequent_backup_DAILY" {
id = "b070fba3-f751-4528-989b-785cf445d5bb"
tags = {
"Environment" = "demo"
}
~ zone_ids = [
- "05d9863d-bd94-41c2-bba8-251aab44637a",
]
# (5 unchanged attributes hidden)
}
Plan: 0 to add, 2 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
cloudstack_snapshot_policy.frequent_backup_DAILY: Modifying... [id=b070fba3-f751-4528-989b-785cf445d5bb]
cloudstack_snapshot_policy.frequent_backup: Modifying... [id=b070fba3-f751-4528-989b-785cf445d5bb]
cloudstack_snapshot_policy.frequent_backup: Modifications complete after 1s [id=b070fba3-f751-4528-989b-785cf445d5bb]
cloudstack_snapshot_policy.frequent_backup_DAILY: Modifications complete after 1s [id=b070fba3-f751-4528-989b-785cf445d5bb]
Apply complete! Resources: 0 added, 2 changed, 0 destroyed.
Outputs:
deployment_summary = {
"snapshot_policies" = {
"daily_policy_id" = "b070fba3-f751-4528-989b-785cf445d5bb"
"hourly_policy_id" = "b070fba3-f751-4528-989b-785cf445d5bb"
}
}
…-provider into support-snapshot-policies
kiranchavala
approved these changes
Sep 19, 2025
Member
kiranchavala
left a comment
There was a problem hiding this comment.
LGTM, tested manually, was able to create snapshot policy and also update it
resource "cloudstack_snapshot_policy" "frequent_backup" {
volume_id = "fc2e91ee-699c-489d-b005-f0afafdcbf41"
interval_type = "HOURLY"
max_snaps = 2
schedule = "1"
timezone = "UTC"
tags = {
Environment = "demo"
}
}
resource "cloudstack_snapshot_policy" "frequent_backup_DAILY" {
volume_id = "fc2e91ee-699c-489d-b005-f0afafdcbf41"
interval_type = "DAILY"
max_snaps = 3
schedule = "00:00"
timezone = "UTC"
tags = {
Environment = "demo"
}
}
output "deployment_summary" {
description = "Summary of deployed resources"
value = {
snapshot_policies = {
hourly_policy_id = cloudstack_snapshot_policy.frequent_backup.id
daily_policy_id = cloudstack_snapshot_policy.frequent_backup_DAILY.id
}
}
}
terraform apply
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# cloudstack_snapshot_policy.frequent_backup will be created
+ resource "cloudstack_snapshot_policy" "frequent_backup" {
+ id = (known after apply)
+ interval_type = "HOURLY"
+ max_snaps = 1
+ schedule = "1"
+ tags = {
+ "Environment" = "demo"
}
+ timezone = "UTC"
+ volume_id = "fc2e91ee-699c-489d-b005-f0afafdcbf41"
}
# cloudstack_snapshot_policy.frequent_backup_DAILY will be created
+ resource "cloudstack_snapshot_policy" "frequent_backup_DAILY" {
+ id = (known after apply)
+ interval_type = "DAILY"
+ max_snaps = 1
+ schedule = "00:00"
+ tags = {
+ "Environment" = "demo"
}
+ timezone = "UTC"
+ volume_id = "fc2e91ee-699c-489d-b005-f0afafdcbf41"
}
Plan: 2 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ deployment_summary = {
+ snapshot_policies = {
+ daily_policy_id = (known after apply)
+ hourly_policy_id = (known after apply)
}
}
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
cloudstack_snapshot_policy.frequent_backup_DAILY: Creating...
cloudstack_snapshot_policy.frequent_backup: Creating...
cloudstack_snapshot_policy.frequent_backup: Creation complete after 1s [id=a54f053a-48b4-48fe-94f8-f181446b8b28]
cloudstack_snapshot_policy.frequent_backup_DAILY: Creation complete after 1s [id=a54f053a-48b4-48fe-94f8-f181446b8b28]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
Outputs:
deployment_summary = {
"snapshot_policies" = {
"daily_policy_id" = "a54f053a-48b4-48fe-94f8-f181446b8b28"
"hourly_policy_id" = "a54f053a-48b4-48fe-94f8-f181446b8b28"
}
}
╭─ ~/Desktop/cloudstack-India-demo/cloudstack-terraform copy ✔ ╱ 3s ╱ Azure subscription 1 ╱ 11:19:12 AM
╰─ terraform apply
cloudstack_snapshot_policy.frequent_backup_DAILY: Refreshing state... [id=a54f053a-48b4-48fe-94f8-f181446b8b28]
cloudstack_snapshot_policy.frequent_backup: Refreshing state... [id=a54f053a-48b4-48fe-94f8-f181446b8b28]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement
Terraform will perform the following actions:
# cloudstack_snapshot_policy.frequent_backup must be replaced
-/+ resource "cloudstack_snapshot_policy" "frequent_backup" {
~ id = "a54f053a-48b4-48fe-94f8-f181446b8b28" -> (known after apply)
~ interval_type = "DAILY" -> "HOURLY" # forces replacement
~ max_snaps = 1 -> 2 # forces replacement
~ schedule = "00:00" -> "1" # forces replacement
tags = {
"Environment" = "demo"
}
- zone_ids = [ # forces replacement
- "05d9863d-bd94-41c2-bba8-251aab44637a",
] -> null
# (2 unchanged attributes hidden)
}
# cloudstack_snapshot_policy.frequent_backup_DAILY must be replaced
-/+ resource "cloudstack_snapshot_policy" "frequent_backup_DAILY" {
~ id = "a54f053a-48b4-48fe-94f8-f181446b8b28" -> (known after apply)
~ max_snaps = 1 -> 3 # forces replacement
tags = {
"Environment" = "demo"
}
- zone_ids = [ # forces replacement
- "05d9863d-bd94-41c2-bba8-251aab44637a",
] -> null
# (4 unchanged attributes hidden)
}
Plan: 2 to add, 0 to change, 2 to destroy.
Changes to Outputs:
~ deployment_summary = {
~ snapshot_policies = {
~ daily_policy_id = "a54f053a-48b4-48fe-94f8-f181446b8b28" -> (known after apply)
~ hourly_policy_id = "a54f053a-48b4-48fe-94f8-f181446b8b28" -> (known after apply)
}
}
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
cloudstack_snapshot_policy.frequent_backup: Destroying... [id=a54f053a-48b4-48fe-94f8-f181446b8b28]
cloudstack_snapshot_policy.frequent_backup_DAILY: Destroying... [id=a54f053a-48b4-48fe-94f8-f181446b8b28]
cloudstack_snapshot_policy.frequent_backup: Destruction complete after 0s
cloudstack_snapshot_policy.frequent_backup_DAILY: Destruction complete after 0s
cloudstack_snapshot_policy.frequent_backup: Creating...
cloudstack_snapshot_policy.frequent_backup_DAILY: Creating...
cloudstack_snapshot_policy.frequent_backup_DAILY: Creation complete after 1s [id=3c2f9ade-f66e-42eb-9947-a6f4d2342eef]
cloudstack_snapshot_policy.frequent_backup: Creation complete after 1s [id=3c2f9ade-f66e-42eb-9947-a6f4d2342eef]
Apply complete! Resources: 2 added, 0 changed, 2 destroyed.
Outputs:
deployment_summary = {
"snapshot_policies" = {
"daily_policy_id" = "3c2f9ade-f66e-42eb-9947-a6f4d2342eef"
"hourly_policy_id" = "3c2f9ade-f66e-42eb-9947-a6f4d2342eef"
}
}
Member
|
@Pearl1594 could you please look at the acceptance tests |
Member
|
@DaanHoogland could you please review |
DaanHoogland
approved these changes
Sep 22, 2025
Contributor
DaanHoogland
left a comment
There was a problem hiding this comment.
clgtm (thought smaller methods are always better ;)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tested with following config: