Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions cloudstack/resource_cloudstack_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,19 @@ func resourceCloudStackDisk() *schema.Resource {
ForceNew: true,
},

"tags": tagsSchema(),

"reattach_on_change": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"deleteprotection": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},

"tags": tagsSchema(),
},
}
}
Expand Down Expand Up @@ -147,6 +153,19 @@ func resourceCloudStackDiskCreate(d *schema.ResourceData, meta interface{}) erro
// Set the volume ID and partials
d.SetId(r.Id)

// Set deleteprotection using UpdateVolume
if v, ok := d.GetOk("deleteprotection"); ok {
p := cs.Volume.NewUpdateVolumeParams()
p.SetId(d.Id())
p.SetDeleteprotection(v.(bool))

_, err := cs.Volume.UpdateVolume(p)
if err != nil {
return fmt.Errorf(
"Error updating the deleteprotection for disk %s: %s", name, err)
}
}

// Set tags if necessary
err = setTags(cs, d, "Volume")
if err != nil {
Expand Down Expand Up @@ -278,6 +297,19 @@ func resourceCloudStackDiskUpdate(d *schema.ResourceData, meta interface{}) erro
}
}

// Check if the deleteprotection has changed and if so, update the deleteprotection
if d.HasChange("deleteprotection") {
p := cs.Volume.NewUpdateVolumeParams()
p.SetId(d.Id())
p.SetDeleteprotection(d.Get("deleteprotection").(bool))

_, err := cs.Volume.UpdateVolume(p)
if err != nil {
return fmt.Errorf(
"Error updating the deleteprotection for disk %s: %s", name, err)
}
}

return resourceCloudStackDiskRead(d, meta)
}

Expand Down
30 changes: 30 additions & 0 deletions cloudstack/resource_cloudstack_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ func resourceCloudStackInstance() *schema.Resource {
Optional: true,
},

"deleteprotection": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},

"tags": tagsSchema(),
},
}
Expand Down Expand Up @@ -479,6 +485,18 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})

d.SetId(r.Id)

// Set deleteprotection using UpdateVirtualMachine
if v, ok := d.GetOk("deleteprotection"); ok {
p := cs.VirtualMachine.NewUpdateVirtualMachineParams(d.Id())
p.SetDeleteprotection(v.(bool))

_, err := cs.VirtualMachine.UpdateVirtualMachine(p)
if err != nil {
return fmt.Errorf(
"Error updating the deleteprotection for instance %s: %s", name, err)
}
}

// Set tags if necessary
if err = setTags(cs, d, "userVm"); err != nil {
return fmt.Errorf("Error setting tags on the new instance %s: %s", name, err)
Expand Down Expand Up @@ -873,6 +891,18 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
}
}

// Check if the deleteprotection has changed and if so, update the deleteprotection
if d.HasChange("deleteprotection") {
p := cs.VirtualMachine.NewUpdateVirtualMachineParams(d.Id())
p.SetDeleteprotection(d.Get("deleteprotection").(bool))

_, err := cs.VirtualMachine.UpdateVirtualMachine(p)
if err != nil {
return fmt.Errorf(
"Error updating the deleteprotection for instance %s: %s", name, err)
}
}

return resourceCloudStackInstanceRead(d, meta)
}

Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ The following arguments are supported:
* `reattach_on_change` - (Optional) Determines whether or not to detach the disk volume
from the virtual machine on disk offering or size change.

* `deleteprotection` - (Optional) Set delete protection for the volume. If true, the volume will be protected from deletion.
Note: If the volume is managed by another service like autoscaling groups or CKS, delete protection will be ignored.

## Attributes Reference

The following attributes are exported:
Expand Down
9 changes: 7 additions & 2 deletions website/docs/r/instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ The following arguments are supported:
* `user_data` - (Optional) The user data to provide when launching the
instance. This can be either plain text or base64 encoded text.

* `userdata_id` - (Optional) The ID of a registered CloudStack user data to use for this instance. Cannot be used together with `user_data`.
* `userdata_id` - (Optional) The ID of a registered CloudStack user data to use for this instance.
Cannot be used together with `user_data`.

* `userdata_details` - (Optional) A map of key-value pairs to pass as parameters to the user data script. Only valid when `userdata_id` is specified. Keys must match the parameter names defined in the user data.
* `userdata_details` - (Optional) A map of key-value pairs to pass as parameters to the user data script.
Only valid when `userdata_id` is specified. Keys must match the parameter names defined in the user data.

* `keypair` - (Optional) The name of the SSH key pair that will be used to
access this instance. (Mutual exclusive with keypairs)
Expand All @@ -192,6 +194,9 @@ The following arguments are supported:

* `boot_mode` - (Optional) The boot mode of the instance. Can only be specified when uefi is true. Valid options are 'Legacy' and 'Secure'.

* `deleteprotection` - (Optional) Set delete protection for the virtual machine. If true, the instance will be protected from deletion.
Note: If the instance is managed by another service like autoscaling groups or CKS, delete protection will be ignored.

## Attributes Reference

The following attributes are exported:
Expand Down