Skip to content

Commit 6e04900

Browse files
committed
add forceNew if the policy is modified to recreate the resource + fix test
1 parent a2ec78b commit 6e04900

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

cloudstack/resource_cloudstack_snapshot_policy.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ import (
2727
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2828
)
2929

30+
func intervalTypeToString(intervalType int) string {
31+
switch intervalType {
32+
case 0:
33+
return "hourly"
34+
case 1:
35+
return "daily"
36+
case 2:
37+
return "weekly"
38+
case 3:
39+
return "monthly"
40+
default:
41+
return fmt.Sprintf("%d", intervalType)
42+
}
43+
}
44+
3045
func resourceCloudStackSnapshotPolicy() *schema.Resource {
3146
return &schema.Resource{
3247
Create: resourceCloudstackSnapshotPolicyCreate,
@@ -38,26 +53,32 @@ func resourceCloudStackSnapshotPolicy() *schema.Resource {
3853
"volume_id": {
3954
Type: schema.TypeString,
4055
Required: true,
56+
ForceNew: true,
4157
},
4258
"interval_type": {
4359
Type: schema.TypeString,
4460
Required: true,
61+
ForceNew: true,
4562
},
4663
"max_snaps": {
4764
Type: schema.TypeInt,
4865
Required: true,
66+
ForceNew: true,
4967
},
5068
"schedule": {
5169
Type: schema.TypeString,
5270
Required: true,
71+
ForceNew: true,
5372
},
5473
"timezone": {
5574
Type: schema.TypeString,
5675
Required: true,
76+
ForceNew: true,
5777
},
5878
"zone_ids": {
5979
Type: schema.TypeList,
6080
Optional: true,
81+
ForceNew: true,
6182
Elem: &schema.Schema{
6283
Type: schema.TypeString,
6384
},
@@ -150,7 +171,7 @@ func resourceCloudstackSnapshotPolicyRead(d *schema.ResourceData, meta interface
150171
snapshotPolicy := resp.SnapshotPolicies[0]
151172

152173
d.Set("volume_id", snapshotPolicy.Volumeid)
153-
d.Set("interval_type", snapshotPolicy.Intervaltype)
174+
d.Set("interval_type", intervalTypeToString(snapshotPolicy.Intervaltype))
154175
d.Set("max_snaps", snapshotPolicy.Maxsnaps)
155176
d.Set("schedule", snapshotPolicy.Schedule)
156177
d.Set("timezone", snapshotPolicy.Timezone)

cloudstack/resource_cloudstack_snapshot_policy_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ resource "cloudstack_disk" "foo" {
234234
235235
resource "cloudstack_snapshot_policy" "foo" {
236236
volume_id = cloudstack_disk.foo.id
237-
interval_type = 1
237+
interval_type = "DAILY"
238238
max_snaps = 7
239239
schedule = "02:30"
240240
timezone = "UTC"
@@ -345,7 +345,7 @@ resource "cloudstack_disk" "foo" {
345345
346346
resource "cloudstack_snapshot_policy" "hourly" {
347347
volume_id = cloudstack_disk.foo.id
348-
interval_type = 0
348+
interval_type = "HOURLY"
349349
max_snaps = 6
350350
schedule = "0"
351351
timezone = "UTC"
@@ -396,7 +396,7 @@ resource "cloudstack_disk" "foo" {
396396
397397
resource "cloudstack_snapshot_policy" "weekly" {
398398
volume_id = cloudstack_disk.foo.id
399-
interval_type = 2
399+
interval_type = "WEEKLY"
400400
max_snaps = 4
401401
schedule = "1:03:00" # Monday at 3:00 AM
402402
timezone = "UTC"
@@ -446,7 +446,7 @@ resource "cloudstack_disk" "foo" {
446446
447447
resource "cloudstack_snapshot_policy" "monthly" {
448448
volume_id = cloudstack_disk.foo.id
449-
interval_type = 3
449+
interval_type = "MONTHLY"
450450
max_snaps = 12
451451
schedule = "15:01:00" # 15th day at 1:00 AM
452452
timezone = "UTC"

0 commit comments

Comments
 (0)