provider/cloudstack: add support for multiple NICs with port forwards and set network_domain for networks (#10638)
* Add support for multiple NICs with port forwards * Fix issue #9801
This commit is contained in:
parent
5016a56fd4
commit
bad3a876ca
|
@ -77,6 +77,12 @@ func resourceCloudStackNetwork() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"network_domain": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
|
||||||
"network_offering": &schema.Schema{
|
"network_offering": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
|
@ -165,6 +171,11 @@ func resourceCloudStackNetworkCreate(d *schema.ResourceData, meta interface{}) e
|
||||||
p.SetEndip(endip)
|
p.SetEndip(endip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the network domain if we have one
|
||||||
|
if networkDomain, ok := d.GetOk("network_domain"); ok {
|
||||||
|
p.SetNetworkdomain(networkDomain.(string))
|
||||||
|
}
|
||||||
|
|
||||||
if vlan, ok := d.GetOk("vlan"); ok {
|
if vlan, ok := d.GetOk("vlan"); ok {
|
||||||
p.SetVlan(strconv.Itoa(vlan.(int)))
|
p.SetVlan(strconv.Itoa(vlan.(int)))
|
||||||
}
|
}
|
||||||
|
@ -225,6 +236,7 @@ func resourceCloudStackNetworkRead(d *schema.ResourceData, meta interface{}) err
|
||||||
d.Set("display_text", n.Displaytext)
|
d.Set("display_text", n.Displaytext)
|
||||||
d.Set("cidr", n.Cidr)
|
d.Set("cidr", n.Cidr)
|
||||||
d.Set("gateway", n.Gateway)
|
d.Set("gateway", n.Gateway)
|
||||||
|
d.Set("network_domain", n.Networkdomain)
|
||||||
d.Set("vpc_id", n.Vpcid)
|
d.Set("vpc_id", n.Vpcid)
|
||||||
|
|
||||||
if n.Aclid == "" {
|
if n.Aclid == "" {
|
||||||
|
@ -270,6 +282,11 @@ func resourceCloudStackNetworkUpdate(d *schema.ResourceData, meta interface{}) e
|
||||||
p.SetGuestvmcidr(d.Get("cidr").(string))
|
p.SetGuestvmcidr(d.Get("cidr").(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the network domain is changed
|
||||||
|
if d.HasChange("network_domain") {
|
||||||
|
p.SetNetworkdomain(d.Get("network_domain").(string))
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the network offering is changed
|
// Check if the network offering is changed
|
||||||
if d.HasChange("network_offering") {
|
if d.HasChange("network_offering") {
|
||||||
// Retrieve the network_offering ID
|
// Retrieve the network_offering ID
|
||||||
|
|
|
@ -65,6 +65,12 @@ func resourceCloudStackPortForward() *schema.Resource {
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"vm_guest_ip": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
|
||||||
"uuid": &schema.Schema{
|
"uuid": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
|
@ -154,9 +160,28 @@ func createPortForward(d *schema.ResourceData, meta interface{}, forward map[str
|
||||||
p := cs.Firewall.NewCreatePortForwardingRuleParams(d.Id(), forward["private_port"].(int),
|
p := cs.Firewall.NewCreatePortForwardingRuleParams(d.Id(), forward["private_port"].(int),
|
||||||
forward["protocol"].(string), forward["public_port"].(int), vm.Id)
|
forward["protocol"].(string), forward["public_port"].(int), vm.Id)
|
||||||
|
|
||||||
// Set the network ID, needed when the public IP address
|
if vmGuestIP, ok := forward["vm_guest_ip"]; ok {
|
||||||
// is not associated with any network yet (VPC case)
|
p.SetVmguestip(vmGuestIP.(string))
|
||||||
|
|
||||||
|
// Set the network ID based on the guest IP, needed when the public IP address
|
||||||
|
// is not associated with any network yet
|
||||||
|
NICS:
|
||||||
|
for _, nic := range vm.Nic {
|
||||||
|
if vmGuestIP.(string) == nic.Ipaddress {
|
||||||
|
p.SetNetworkid(nic.Networkid)
|
||||||
|
break NICS
|
||||||
|
}
|
||||||
|
for _, ip := range nic.Secondaryip {
|
||||||
|
if vmGuestIP.(string) == ip.Ipaddress {
|
||||||
|
p.SetNetworkid(nic.Networkid)
|
||||||
|
break NICS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If no guest IP is configured, use the primary NIC
|
||||||
p.SetNetworkid(vm.Nic[0].Networkid)
|
p.SetNetworkid(vm.Nic[0].Networkid)
|
||||||
|
}
|
||||||
|
|
||||||
// Do not open the firewall automatically in any case
|
// Do not open the firewall automatically in any case
|
||||||
p.SetOpenfirewall(false)
|
p.SetOpenfirewall(false)
|
||||||
|
@ -248,6 +273,7 @@ func resourceCloudStackPortForwardRead(d *schema.ResourceData, meta interface{})
|
||||||
forward["private_port"] = privPort
|
forward["private_port"] = privPort
|
||||||
forward["public_port"] = pubPort
|
forward["public_port"] = pubPort
|
||||||
forward["virtual_machine_id"] = f.Virtualmachineid
|
forward["virtual_machine_id"] = f.Virtualmachineid
|
||||||
|
forward["vm_guest_ip"] = f.Vmguestip
|
||||||
|
|
||||||
forwards.Add(forward)
|
forwards.Add(forward)
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ The following arguments are supported:
|
||||||
* `endip` - (Optional) End of the IP block that will be available on the
|
* `endip` - (Optional) End of the IP block that will be available on the
|
||||||
network. Defaults to the last available IP in the range.
|
network. Defaults to the last available IP in the range.
|
||||||
|
|
||||||
|
* `network_domain` - (Optional) DNS domain for the network.
|
||||||
|
|
||||||
* `network_offering` - (Required) The name or ID of the network offering to use
|
* `network_offering` - (Required) The name or ID of the network offering to use
|
||||||
for this network.
|
for this network.
|
||||||
|
|
||||||
|
@ -72,3 +74,4 @@ The following attributes are exported:
|
||||||
|
|
||||||
* `id` - The ID of the network.
|
* `id` - The ID of the network.
|
||||||
* `display_text` - The display text of the network.
|
* `display_text` - The display text of the network.
|
||||||
|
* `network_domain` - DNS domain for the network.
|
||||||
|
|
|
@ -50,9 +50,14 @@ The `forward` block supports:
|
||||||
|
|
||||||
* `virtual_machine_id` - (Required) The ID of the virtual machine to forward to.
|
* `virtual_machine_id` - (Required) The ID of the virtual machine to forward to.
|
||||||
|
|
||||||
|
* `vm_guest_ip` - (Optional) The virtual machine IP address for the port
|
||||||
|
forwarding rule (useful when the virtual machine has secondairy NICs
|
||||||
|
or IP addresses).
|
||||||
|
|
||||||
## Attributes Reference
|
## Attributes Reference
|
||||||
|
|
||||||
The following attributes are exported:
|
The following attributes are exported:
|
||||||
|
|
||||||
* `id` - The ID of the IP address for which the port forwards are created.
|
* `id` - The ID of the IP address for which the port forwards are created.
|
||||||
|
* `vm_guest_ip` - The IP address of the virtual machine that is used
|
||||||
|
for the port forwarding rule.
|
||||||
|
|
|
@ -29,9 +29,9 @@ The following arguments are supported:
|
||||||
* `virtual_machine_id` - (Required) The virtual machine ID to enable the
|
* `virtual_machine_id` - (Required) The virtual machine ID to enable the
|
||||||
static NAT feature for. Changing this forces a new resource to be created.
|
static NAT feature for. Changing this forces a new resource to be created.
|
||||||
|
|
||||||
* `vm_guest_ip` - (Optional) The virtual machine IP address for the port
|
* `vm_guest_ip` - (Optional) The virtual machine IP address to forward the
|
||||||
forwarding rule (useful when the virtual machine has a secondairy NIC).
|
static NAT traffic to (useful when the virtual machine has secondary
|
||||||
Changing this forces a new resource to be created.
|
NICs or IP addresses). Changing this forces a new resource to be created.
|
||||||
|
|
||||||
* `project` - (Optional) The name or ID of the project to deploy this
|
* `project` - (Optional) The name or ID of the project to deploy this
|
||||||
instance to. Changing this forces a new resource to be created.
|
instance to. Changing this forces a new resource to be created.
|
||||||
|
@ -42,4 +42,4 @@ The following attributes are exported:
|
||||||
|
|
||||||
* `id` - The static nat ID.
|
* `id` - The static nat ID.
|
||||||
* `vm_guest_ip` - The IP address of the virtual machine that is used
|
* `vm_guest_ip` - The IP address of the virtual machine that is used
|
||||||
for the port forwarding rule.
|
to forward the static NAT traffic to.
|
||||||
|
|
|
@ -37,8 +37,8 @@ The following arguments are supported:
|
||||||
* `vpc_offering` - (Required) The name or ID of the VPC offering to use for this VPC.
|
* `vpc_offering` - (Required) The name or ID of the VPC offering to use for this VPC.
|
||||||
Changing this forces a new resource to be created.
|
Changing this forces a new resource to be created.
|
||||||
|
|
||||||
* `network_domain` - (Optional) DNS domain for guest
|
* `network_domain` - (Optional) The default DNS domain for networks created in
|
||||||
networks. Changing this forces a new resource to be created.
|
this VPC. Changing this forces a new resource to be created.
|
||||||
|
|
||||||
* `project` - (Optional) The name or ID of the project to deploy this
|
* `project` - (Optional) The name or ID of the project to deploy this
|
||||||
instance to. Changing this forces a new resource to be created.
|
instance to. Changing this forces a new resource to be created.
|
||||||
|
|
Loading…
Reference in New Issue