You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by "Curverneur (via GitHub)" <gi...@apache.org> on 2025/11/21 17:24:41 UTC
[PR] add support for vpc internal lb [cloudstack-terraform-provider]
Curverneur opened a new pull request, #264:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/264
## Description
Add support for creating internal load balancer resources with the possibility to assign instances to the load balancer rule.
## Reason
This feature allows users to create an internal load balancer for a certain vpc tier and assign instances to it in one step using the terraform provider following IaC principles.
## References
- Documentation: https://docs.cloudstack.apache.org/en/latest/adminguide/networking_and_traffic.html#load-balancing-across-tiers
- API:
- createLoadBalancer: https://cloudstack.apache.org/api/apidocs-4.22/apis/createLoadBalancer.html
- assignToLoadBalancerRule: https://cloudstack.apache.org/api/apidocs-4.22/apis/assignToLoadBalancerRule.html
## Changes
Added `cloudstack_loadbalancer` resource to the terraform provider and the corresponding documentation page.
- modified `cloudstack/provider.go`
- added `cloudstack/resource_cloudstack_loadbalancer.go`
- added `website/docs/r/loadbalancer.html.markdown`
## Deployment test
### Code:
```hcl
resource "cloudstack_loadbalancer" "test" {
algorithm = "Source"
instanceport = "8081"
name = "test3"
networkid = "0ae8fa84-c78e-441a-8628-917d276c7d5c"
scheme = "Internal"
sourceipaddressnetworkid = "0ae8fa84-c78e-441a-8628-917d276c7d5c"
sourceport = "8081"
virtualmachineids = [ "48600f99-d890-472c-bc1a-7379af22727c", "749485a1-4081-49cd-9668-1d160ac94488", "9bbf3c6d-c8b8-42e8-ab37-e4f60a71f61d" ]
}
```
### Terraform apply:
```
OpenTofu used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
OpenTofu will perform the following actions:
# cloudstack_loadbalancer.test will be created
+ resource "cloudstack_loadbalancer" "test" {
+ algorithm = "Source"
+ id = (known after apply)
+ instanceport = 8081
+ name = "test3"
+ networkid = "0ae8fa84-c78e-441a-8628-917d276c7d5c"
+ scheme = "Internal"
+ sourceipaddressnetworkid = "0ae8fa84-c78e-441a-8628-917d276c7d5c"
+ sourceport = 8081
+ virtualmachineids = [
+ "48600f99-d890-472c-bc1a-7379af22727c",
+ "749485a1-4081-49cd-9668-1d160ac94488",
+ "9bbf3c6d-c8b8-42e8-ab37-e4f60a71f61d",
]
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
OpenTofu will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
cloudstack_loadbalancer.test: Creating...
cloudstack_loadbalancer.test: Still creating... [10s elapsed]
cloudstack_loadbalancer.test: Still creating... [20s elapsed]
cloudstack_loadbalancer.test: Still creating... [30s elapsed]
cloudstack_loadbalancer.test: Creation complete after 31s [id=eefce154-e759-45a4-989a-9a432792801b]
```
### Verify using API:
```json
{
"listloadbalancersresponse": {
"count": 1,
"loadbalancer": [
{
"id": "eefce154-e759-45a4-989a-9a432792801b",
"name": "test3",
"algorithm": "Source",
"networkid": "0ae8fa84-c78e-441a-8628-917d276c7d5c",
"sourceipaddress": "10.0.0.13",
"sourceipaddressnetworkid": "0ae8fa84-c78e-441a-8628-917d276c7d5c",
"projectid": "850c3f62-94f5-497f-91f6-2a736af09b58",
"project": "Test",
"domainid": "96b987c6-a9a8-11f0-b71e-6c92cf3489d0",
"domain": "ROOT",
"domainpath": "ROOT",
"loadbalancerrule": [
{
"sourceport": 8081,
"instanceport": 8081,
"state": "Active"
}
],
"loadbalancerinstance": [
{
"id": "48600f99-d890-472c-bc1a-7379af22727c",
"name": "i-14-1286-VM",
"ipaddress": "10.0.0.12"
},
{
"id": "749485a1-4081-49cd-9668-1d160ac94488",
"name": "i-14-1282-VM",
"ipaddress": "10.0.0.11"
},
{
"id": "9bbf3c6d-c8b8-42e8-ab37-e4f60a71f61d",
"name": "i-14-1283-VM",
"ipaddress": "10.0.0.10"
}
],
"tags": [],
"fordisplay": true
}
]
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] add support for vpc internal lb [cloudstack-terraform-provider]
Posted by "MitchDrage (via GitHub)" <gi...@apache.org>.
MitchDrage commented on PR #264:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/264#issuecomment-5364026521
Hi @Curverneur,
I just finished building this same support for the Ansible collection and went through a few iterations to get it all working.
I ran into some issues along the way and checked how you've done it and I've spotted a few improvements that I'd like to suggest if I may?
1. Your Read path for importing an existing resource doesn't include sourceport, instanceport, description or sourceipaddress - so the first plan after an import proposes replacing it.
2. There's no Update option for changing `virtualmachineids`, so adding or removing a VM from a pool will tear down the loadbalancer and recreate it.
The most-common reason for changing membership would be for conducting backend server maintenance, so to rebuild the LB would cause an outage - the very thing that you'd be trying to avoid.
The APIs for `assignToLoadBalancerRule` and `removeFromLoadBalancerRule` both work against Internal LBs, so you could either add an Update path to call those APIs (and remove ForceNew on it), or alternatively make a separate resource for the members (e.g. `cloudstack_loadbalancer_member`) and handle it there. That second option is how I did it with the Ansible collection.
Hope that helps.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] add support for vpc internal lb [cloudstack-terraform-provider]
Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti merged PR #264:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/264
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org