mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-11 08:05:33 -06:00
Add a few explaining lines to the docs about ICMP types/codes
This commit is contained in:
parent
06b322f81f
commit
8bdec15649
@ -51,7 +51,7 @@ func resourceCloudStackDisk() *schema.Resource {
|
||||
Default: false,
|
||||
},
|
||||
|
||||
"virtual_machine": &schema.Schema{
|
||||
"virtual_machine_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
@ -119,7 +119,7 @@ func resourceCloudStackDiskCreate(d *schema.ResourceData, meta interface{}) erro
|
||||
d.SetPartial("device")
|
||||
d.SetPartial("disk_offering")
|
||||
d.SetPartial("size")
|
||||
d.SetPartial("virtual_machine")
|
||||
d.SetPartial("virtual_machine_id")
|
||||
d.SetPartial("project")
|
||||
d.SetPartial("zone")
|
||||
|
||||
@ -185,7 +185,7 @@ func resourceCloudStackDiskRead(d *schema.ResourceData, meta interface{}) error
|
||||
}
|
||||
|
||||
d.Set("device", retrieveDeviceName(v.Deviceid, c.Name))
|
||||
setValueOrID(d, "virtual_machine", v.Vmname, v.Virtualmachineid)
|
||||
d.Set("virtual_machine_id", v.Virtualmachineid)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -254,7 +254,7 @@ func resourceCloudStackDiskUpdate(d *schema.ResourceData, meta interface{}) erro
|
||||
// Set the additional partials
|
||||
d.SetPartial("attach")
|
||||
d.SetPartial("device")
|
||||
d.SetPartial("virtual_machine")
|
||||
d.SetPartial("virtual_machine_id")
|
||||
} else {
|
||||
// Detach the volume
|
||||
if err := resourceCloudStackDiskDetach(d, meta); err != nil {
|
||||
@ -295,24 +295,14 @@ func resourceCloudStackDiskDelete(d *schema.ResourceData, meta interface{}) erro
|
||||
func resourceCloudStackDiskAttach(d *schema.ResourceData, meta interface{}) error {
|
||||
cs := meta.(*cloudstack.CloudStackClient)
|
||||
|
||||
if virtualmachineid, ok := d.GetOk("virtual_machine_id"); ok {
|
||||
// First check if the disk isn't already attached
|
||||
if attached, err := isAttached(d, meta); err != nil || attached {
|
||||
return err
|
||||
}
|
||||
|
||||
// Retrieve the virtual_machine ID
|
||||
virtualmachineid, e := retrieveID(
|
||||
cs,
|
||||
"virtual_machine",
|
||||
d.Get("virtual_machine").(string),
|
||||
cloudstack.WithProject(d.Get("project").(string)),
|
||||
)
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
// Create a new parameter struct
|
||||
p := cs.Volume.NewAttachVolumeParams(d.Id(), virtualmachineid)
|
||||
p := cs.Volume.NewAttachVolumeParams(d.Id(), virtualmachineid.(string))
|
||||
|
||||
if device, ok := d.GetOk("device"); ok {
|
||||
// Retrieve the device ID
|
||||
@ -332,6 +322,7 @@ func resourceCloudStackDiskAttach(d *schema.ResourceData, meta interface{}) erro
|
||||
}
|
||||
|
||||
d.SetId(r.(*cloudstack.AttachVolumeResponse).Id)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -351,20 +342,11 @@ func resourceCloudStackDiskDetach(d *schema.ResourceData, meta interface{}) erro
|
||||
p.SetId(d.Id())
|
||||
|
||||
// Detach the currently attached volume
|
||||
if _, err := cs.Volume.DetachVolume(p); err != nil {
|
||||
// Retrieve the virtual_machine ID
|
||||
virtualmachineid, e := retrieveID(
|
||||
cs,
|
||||
"virtual_machine",
|
||||
d.Get("virtual_machine").(string),
|
||||
cloudstack.WithProject(d.Get("project").(string)),
|
||||
)
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
_, err := cs.Volume.DetachVolume(p)
|
||||
if err != nil {
|
||||
if virtualmachineid, ok := d.GetOk("virtual_machine_id"); ok {
|
||||
// Create a new parameter struct
|
||||
pd := cs.VirtualMachine.NewStopVirtualMachineParams(virtualmachineid)
|
||||
pd := cs.VirtualMachine.NewStopVirtualMachineParams(virtualmachineid.(string))
|
||||
|
||||
// Stop the virtual machine in order to be able to detach the disk
|
||||
if _, err := cs.VirtualMachine.StopVirtualMachine(pd); err != nil {
|
||||
@ -377,15 +359,16 @@ func resourceCloudStackDiskDetach(d *schema.ResourceData, meta interface{}) erro
|
||||
}
|
||||
|
||||
// Create a new parameter struct
|
||||
pu := cs.VirtualMachine.NewStartVirtualMachineParams(virtualmachineid)
|
||||
pu := cs.VirtualMachine.NewStartVirtualMachineParams(virtualmachineid.(string))
|
||||
|
||||
// Start the virtual machine again
|
||||
if _, err := cs.VirtualMachine.StartVirtualMachine(pu); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func isAttached(d *schema.ResourceData, meta interface{}) (bool, error) {
|
||||
|
@ -186,7 +186,7 @@ resource "cloudstack_disk" "foo" {
|
||||
attach = true
|
||||
device = "/dev/xvde"
|
||||
disk_offering = "%s"
|
||||
virtual_machine = "${cloudstack_instance.foobar.name}"
|
||||
virtual_machine_id = "${cloudstack_instance.foobar.id}"
|
||||
zone = "${cloudstack_instance.foobar.zone}"
|
||||
}`,
|
||||
CLOUDSTACK_SERVICE_OFFERING_1,
|
||||
@ -210,7 +210,7 @@ resource "cloudstack_disk" "foo" {
|
||||
name = "terraform-disk"
|
||||
attach = true
|
||||
disk_offering = "%s"
|
||||
virtual_machine = "${cloudstack_instance.foobar.name}"
|
||||
virtual_machine_id = "${cloudstack_instance.foobar.id}"
|
||||
zone = "${cloudstack_instance.foobar.zone}"
|
||||
}`,
|
||||
CLOUDSTACK_SERVICE_OFFERING_1,
|
||||
@ -234,7 +234,7 @@ resource "cloudstack_disk" "foo" {
|
||||
name = "terraform-disk"
|
||||
attach = true
|
||||
disk_offering = "%s"
|
||||
virtual_machine = "${cloudstack_instance.foobar.name}"
|
||||
virtual_machine_id = "${cloudstack_instance.foobar.id}"
|
||||
zone = "${cloudstack_instance.foobar.zone}"
|
||||
}`,
|
||||
CLOUDSTACK_SERVICE_OFFERING_1,
|
||||
|
@ -207,46 +207,38 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
|
||||
}
|
||||
|
||||
// If there are affinity group IDs supplied, add them to the parameter struct
|
||||
if ags := d.Get("affinity_group_ids").(*schema.Set); ags.Len() > 0 {
|
||||
if agIDs := d.Get("affinity_group_ids").(*schema.Set); agIDs.Len() > 0 {
|
||||
var groups []string
|
||||
|
||||
for _, group := range ags.List() {
|
||||
for _, group := range agIDs.List() {
|
||||
groups = append(groups, group.(string))
|
||||
}
|
||||
|
||||
p.SetAffinitygroupids(groups)
|
||||
}
|
||||
|
||||
// If there is a affinity_group_names supplied, add it to the parameter struct
|
||||
if agns := d.Get("affinity_group_names").(*schema.Set); agns.Len() > 0 {
|
||||
// If there are affinity group names supplied, add them to the parameter struct
|
||||
if agNames := d.Get("affinity_group_names").(*schema.Set); agNames.Len() > 0 {
|
||||
var groups []string
|
||||
|
||||
for _, group := range agns.List() {
|
||||
for _, group := range agNames.List() {
|
||||
groups = append(groups, group.(string))
|
||||
}
|
||||
|
||||
p.SetAffinitygroupnames(groups)
|
||||
}
|
||||
|
||||
// If there is a security_group_ids supplied, add it to the parameter struct
|
||||
if sgids := d.Get("security_group_ids").(*schema.Set); sgids.Len() > 0 {
|
||||
// If there are security group IDs supplied, add them to the parameter struct
|
||||
if sgIDs := d.Get("security_group_ids").(*schema.Set); sgIDs.Len() > 0 {
|
||||
var groups []string
|
||||
|
||||
for _, group := range sgids.List() {
|
||||
for _, group := range sgIDs.List() {
|
||||
groups = append(groups, group.(string))
|
||||
}
|
||||
|
||||
p.SetSecuritygroupids(groups)
|
||||
}
|
||||
|
||||
// If there is a security_group_names supplied, add it to the parameter struct
|
||||
if sgns := d.Get("security_group_names").(*schema.Set); sgns.Len() > 0 {
|
||||
// If there are security group names supplied, add them to the parameter struct
|
||||
if sgNames := d.Get("security_group_names").(*schema.Set); sgNames.Len() > 0 {
|
||||
var groups []string
|
||||
|
||||
for _, group := range sgns.List() {
|
||||
for _, group := range sgNames.List() {
|
||||
groups = append(groups, group.(string))
|
||||
}
|
||||
|
||||
p.SetSecuritygroupnames(groups)
|
||||
}
|
||||
|
||||
@ -324,46 +316,42 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
|
||||
d.Set("ip_address", vm.Nic[0].Ipaddress)
|
||||
d.Set("group", vm.Group)
|
||||
|
||||
setValueOrID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid)
|
||||
setValueOrID(d, "template", vm.Templatename, vm.Templateid)
|
||||
setValueOrID(d, "project", vm.Project, vm.Projectid)
|
||||
setValueOrID(d, "zone", vm.Zonename, vm.Zoneid)
|
||||
|
||||
if _, ok := d.GetOk("affinity_group_ids"); ok {
|
||||
groups := &schema.Set{F: schema.HashString}
|
||||
for _, group := range vm.Affinitygroup {
|
||||
groups.Add(group.Id)
|
||||
}
|
||||
|
||||
if groups.Len() > 0 {
|
||||
d.Set("affinity_group_ids", groups)
|
||||
}
|
||||
|
||||
agns := &schema.Set{F: schema.HashString}
|
||||
if _, ok := d.GetOk("affinity_group_names"); ok {
|
||||
groups := &schema.Set{F: schema.HashString}
|
||||
for _, group := range vm.Affinitygroup {
|
||||
agns.Add(group.Name)
|
||||
groups.Add(group.Name)
|
||||
}
|
||||
d.Set("affinity_group_names", groups)
|
||||
}
|
||||
|
||||
if agns.Len() > 0 {
|
||||
d.Set("affinity_group_names", agns)
|
||||
}
|
||||
|
||||
sgids := &schema.Set{F: schema.HashString}
|
||||
if _, ok := d.GetOk("security_group_ids"); ok {
|
||||
groups := &schema.Set{F: schema.HashString}
|
||||
for _, group := range vm.Securitygroup {
|
||||
sgids.Add(group.Id)
|
||||
groups.Add(group.Id)
|
||||
}
|
||||
d.Set("security_group_ids", groups)
|
||||
}
|
||||
|
||||
if sgids.Len() > 0 {
|
||||
d.Set("security_group_ids", sgids)
|
||||
}
|
||||
|
||||
sgns := &schema.Set{F: schema.HashString}
|
||||
if _, ok := d.GetOk("security_group_names"); ok {
|
||||
groups := &schema.Set{F: schema.HashString}
|
||||
for _, group := range vm.Securitygroup {
|
||||
sgns.Add(group.Name)
|
||||
groups.Add(group.Name)
|
||||
}
|
||||
d.Set("security_group_names", groups)
|
||||
}
|
||||
|
||||
if sgns.Len() > 0 {
|
||||
d.Set("security_group_names", sgns)
|
||||
}
|
||||
setValueOrID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid)
|
||||
setValueOrID(d, "template", vm.Templatename, vm.Templateid)
|
||||
setValueOrID(d, "project", vm.Project, vm.Projectid)
|
||||
setValueOrID(d, "zone", vm.Zonename, vm.Zoneid)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -415,7 +403,7 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
|
||||
}
|
||||
|
||||
// Attributes that require reboot to update
|
||||
if d.HasChange("name") || d.HasChange("service_offering") || d.HasChange("affinity_group_ids") || d.HasChange("keypair") {
|
||||
if d.HasChange("name") || d.HasChange("service_offering") || d.HasChange("affinity_group_ids") || d.HasChange("affinity_group_names") || d.HasChange("keypair") {
|
||||
// Before we can actually make these changes, the virtual machine must be stopped
|
||||
_, err := cs.VirtualMachine.StopVirtualMachine(
|
||||
cs.VirtualMachine.NewStopVirtualMachineParams(d.Id()))
|
||||
@ -470,8 +458,21 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
|
||||
p := cs.AffinityGroup.NewUpdateVMAffinityGroupParams(d.Id())
|
||||
groups := []string{}
|
||||
|
||||
if ags := d.Get("affinity_group_ids").(*schema.Set); ags.Len() > 0 {
|
||||
for _, group := range ags.List() {
|
||||
if agIDs := d.Get("affinity_group_ids").(*schema.Set); agIDs.Len() > 0 {
|
||||
for _, group := range agIDs.List() {
|
||||
groups = append(groups, group.(string))
|
||||
}
|
||||
}
|
||||
|
||||
p.SetAffinitygroupids(groups)
|
||||
}
|
||||
|
||||
if d.HasChange("affinity_group_names") {
|
||||
p := cs.AffinityGroup.NewUpdateVMAffinityGroupParams(d.Id())
|
||||
groups := []string{}
|
||||
|
||||
if agNames := d.Get("affinity_group_names").(*schema.Set); agNames.Len() > 0 {
|
||||
for _, group := range agNames.List() {
|
||||
groups = append(groups, group.(string))
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,6 @@ func retrieveID(cs *cloudstack.CloudStackClient, name string, value string, opts
|
||||
switch name {
|
||||
case "disk_offering":
|
||||
id, err = cs.DiskOffering.GetDiskOfferingID(value)
|
||||
case "virtual_machine":
|
||||
id, err = cs.VirtualMachine.GetVirtualMachineID(value, opts...)
|
||||
case "service_offering":
|
||||
id, err = cs.ServiceOffering.GetServiceOfferingID(value)
|
||||
case "network_offering":
|
||||
|
@ -44,8 +44,8 @@ The following arguments are supported:
|
||||
* `shrink_ok` - (Optional) Verifies if the disk volume is allowed to shrink when
|
||||
resizing (defaults false).
|
||||
|
||||
* `virtual_machine` - (Optional) The name or ID of the virtual machine to which you
|
||||
want to attach the disk volume.
|
||||
* `virtual_machine_id` - (Optional) The ID of the virtual machine to which you want
|
||||
to attach the disk volume.
|
||||
|
||||
* `project` - (Optional) The name or ID of the project to deploy this
|
||||
instance to. Changing this forces a new resource to be created.
|
||||
|
@ -53,11 +53,11 @@ The `rule` block supports:
|
||||
* `protocol` - (Required) The name of the protocol to allow. Valid options are:
|
||||
`tcp`, `udp`, `icmp`, `all` or a valid protocol number.
|
||||
|
||||
* `icmp_type` - (Optional) The ICMP type to allow. This can only be specified if
|
||||
the protocol is ICMP.
|
||||
* `icmp_type` - (Optional) The ICMP type to allow, or `-1` to allow `any`. This
|
||||
can only be specified if the protocol is ICMP. (defaults 0)
|
||||
|
||||
* `icmp_code` - (Optional) The ICMP code to allow. This can only be specified if
|
||||
the protocol is ICMP.
|
||||
* `icmp_code` - (Optional) The ICMP code to allow, or `-1` to allow `any`. This
|
||||
can only be specified if the protocol is ICMP. (defaults 0)
|
||||
|
||||
* `ports` - (Optional) List of ports and/or port ranges to allow. This can only
|
||||
be specified if the protocol is TCP, UDP, ALL or a valid protocol number.
|
||||
|
Loading…
Reference in New Issue
Block a user