Skip to content

Conversation

@Curverneur
Copy link

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

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:

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:

{
  "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
      }
    ]
  }
}

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants