Skip to content

Commit

Permalink
Merge pull request #158 from alrayyes/feat/load-balancer-listener-res…
Browse files Browse the repository at this point in the history
…ource

feat: implement load balancer listener resource
  • Loading branch information
alrayyes authored Nov 19, 2024
2 parents abe6803 + 6e1aa29 commit b392033
Show file tree
Hide file tree
Showing 9 changed files with 1,279 additions and 3 deletions.
86 changes: 86 additions & 0 deletions docs/resources/public_cloud_load_balancer_listener.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "leaseweb_public_cloud_load_balancer_listener Resource - leaseweb"
subcategory: ""
description: |-
---

# leaseweb_public_cloud_load_balancer_listener (Resource)



## Example Usage

```terraform
# Manage non HTTPS example Public Cloud load balancer listener
resource "leaseweb_public_cloud_load_balancer_listener" "example" {
protocol = "HTTP"
port = 80
default_rule = {
target_group_id = "b05917e1-96a4-442a-900c-c41f273d95c9"
}
load_balancer_id = "695ddd91-051f-4dd6-9120-938a927a47d0"
}
# Manage HTTPS example Public Cloud load balancer listener
resource "leaseweb_public_cloud_load_balancer_listener" "example2" {
protocol = "HTTPS"
port = 443
certificate = {
certificate = "-----BEGIN CERTIFICATE-----MIIBhDCB7gIBADBFMQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCtWdKNbZxvkXKAADjJMJ7VTJz6uFoMD403C+gMIF8hwqIsHggzCao6iXrW9sZoyZtUBVBiiq5RumHbbpwvOdMmXrShEB4sTJkWRMDy7yD4D91WCU1fc10E/zBJMwssAvmHZo5kGW1Pj1N9ktb+O/TMsEc6yd5suvdQj6aaJbQlTQIDAQABoAAwDQYJKoZIhvcNAQELBQADgYEAWOQ2CJLRo8MQgJgvhdoSIkHITnrbjB5hS3f/dx0lIcnyI6Q9nOyuQHXkCgkdBaV8lz7l+IbqcGc3CaIRP2ZIVFvo2252n630tOOSsqoqJS1tYIoIKsohi3T3d8T1i/s0BWbTJi8Xgd186wyUn/jHwXROKx2rq6yYsAO6fISDKw8=-----END CERTIFICATE-----"
private_key = "-----BEGIN EC PRIVATE KEY-----MIHcAgEBBEIBVlC0IObonfQZIQ81l/WILKfWT5Fv96eNnYmQZ7uleu73igfiVESVuPfNlbW9oNEK1XcXli4YNZMxWMkKuzC3w8CgBwYFK4EEACOhgYkDgYYABAHvOqz9d2xeSpm1FNdw0NR5j/q6PMd6whZFsTPNYNj0/PsTpsHk78ZB4MYnJUXwHJjpj+gnKkLNc02f4w/vSF8VXADX4l40XU/w82TAOCftQwoxO5o0jZcwEUIYzl02Zd7uNxhjtKJQnYFi9x8WI8L8zQ6GZB/fJKYwoHaUr0I1h/5LzQ==-----END EC PRIVATE KEY-----"
}
default_rule = {
target_group_id = "b05917e1-96a4-442a-900c-c41f273d95c9"
}
load_balancer_id = "695ddd91-051f-4dd6-9120-938a927a47d0"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `default_rule` (Attributes) (see [below for nested schema](#nestedatt--default_rule))
- `load_balancer_id` (String) Load balancer ID
- `port` (Number) Port that the listener listens to
- `protocol` (String) Valid options are
- *HTTP*
- *HTTPS*
- *TCP*

### Optional

- `certificate` (Attributes) Required only if protocol is HTTPS (see [below for nested schema](#nestedatt--certificate))

### Read-Only

- `listener_id` (String) Listener ID

<a id="nestedatt--default_rule"></a>
### Nested Schema for `default_rule`

Optional:

- `target_group_id` (String) Client Private Key. Required only if protocol is `HTTPS`


<a id="nestedatt--certificate"></a>
### Nested Schema for `certificate`

Optional:

- `certificate` (String, Sensitive) Client Certificate. Required only if protocol is `HTTPS`
- `chain` (String, Sensitive) CA certificate. Not required, but can be added if protocol is `HTTPS`
- `private_key` (String, Sensitive) Client Private Key. Required only if protocol is `HTTPS`

## Import

Import is supported using the following syntax:

```shell
# Public Cloud load balancer listener can be imported by passing "load_balancer_id,listener_id".
terraform import leaseweb_public_cloud_load_balancer_listener.example 695ddd91-051f-4dd6-9120-938a927a47d0,695ddd91-051f-4dd6-9120-938a927a47d0
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Public Cloud load balancer listener can be imported by passing "load_balancer_id,listener_id".
terraform import leaseweb_public_cloud_load_balancer_listener.example 695ddd91-051f-4dd6-9120-938a927a47d0,695ddd91-051f-4dd6-9120-938a927a47d0
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Manage non HTTPS example Public Cloud load balancer listener
resource "leaseweb_public_cloud_load_balancer_listener" "example" {
protocol = "HTTP"
port = 80
default_rule = {
target_group_id = "b05917e1-96a4-442a-900c-c41f273d95c9"
}
load_balancer_id = "695ddd91-051f-4dd6-9120-938a927a47d0"
}

# Manage HTTPS example Public Cloud load balancer listener
resource "leaseweb_public_cloud_load_balancer_listener" "example2" {
protocol = "HTTPS"
port = 443
certificate = {
certificate = "-----BEGIN CERTIFICATE-----MIIBhDCB7gIBADBFMQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCtWdKNbZxvkXKAADjJMJ7VTJz6uFoMD403C+gMIF8hwqIsHggzCao6iXrW9sZoyZtUBVBiiq5RumHbbpwvOdMmXrShEB4sTJkWRMDy7yD4D91WCU1fc10E/zBJMwssAvmHZo5kGW1Pj1N9ktb+O/TMsEc6yd5suvdQj6aaJbQlTQIDAQABoAAwDQYJKoZIhvcNAQELBQADgYEAWOQ2CJLRo8MQgJgvhdoSIkHITnrbjB5hS3f/dx0lIcnyI6Q9nOyuQHXkCgkdBaV8lz7l+IbqcGc3CaIRP2ZIVFvo2252n630tOOSsqoqJS1tYIoIKsohi3T3d8T1i/s0BWbTJi8Xgd186wyUn/jHwXROKx2rq6yYsAO6fISDKw8=-----END CERTIFICATE-----"
private_key = "-----BEGIN EC PRIVATE KEY-----MIHcAgEBBEIBVlC0IObonfQZIQ81l/WILKfWT5Fv96eNnYmQZ7uleu73igfiVESVuPfNlbW9oNEK1XcXli4YNZMxWMkKuzC3w8CgBwYFK4EEACOhgYkDgYYABAHvOqz9d2xeSpm1FNdw0NR5j/q6PMd6whZFsTPNYNj0/PsTpsHk78ZB4MYnJUXwHJjpj+gnKkLNc02f4w/vSF8VXADX4l40XU/w82TAOCftQwoxO5o0jZcwEUIYzl02Zd7uNxhjtKJQnYFi9x8WI8L8zQ6GZB/fJKYwoHaUr0I1h/5LzQ==-----END EC PRIVATE KEY-----"
}
default_rule = {
target_group_id = "b05917e1-96a4-442a-900c-c41f273d95c9"
}
load_balancer_id = "695ddd91-051f-4dd6-9120-938a927a47d0"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-testing v1.10.0
github.com/leaseweb/leaseweb-go-sdk/dedicatedServer v0.0.0-20241114082959-9d682d73a40d
github.com/leaseweb/leaseweb-go-sdk/publicCloud v0.0.0-20241114082959-9d682d73a40d
github.com/leaseweb/leaseweb-go-sdk/publicCloud v0.0.0-20241118100223-cb6c58ec7524
github.com/stretchr/testify v1.9.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/leaseweb/leaseweb-go-sdk/dedicatedServer v0.0.0-20241114082959-9d682d73a40d h1:p+eFICnmxAUq8eK32xcMHQtP98SO3bnpemZYDi1NSJ4=
github.com/leaseweb/leaseweb-go-sdk/dedicatedServer v0.0.0-20241114082959-9d682d73a40d/go.mod h1:MSrebSkGmRy0OzTJd+lDXsILYms/13QO7GfNNK/5Mds=
github.com/leaseweb/leaseweb-go-sdk/publicCloud v0.0.0-20241114082959-9d682d73a40d h1:ZqDkKULZCaY9+UPWixX6KdsJWVBGnX4PPHWlVEu7gns=
github.com/leaseweb/leaseweb-go-sdk/publicCloud v0.0.0-20241114082959-9d682d73a40d/go.mod h1:nh4tvDxdD+xNL9qjFqtL1ZL49w+HJq5kMeTKkPs2XHI=
github.com/leaseweb/leaseweb-go-sdk/publicCloud v0.0.0-20241118100223-cb6c58ec7524 h1:vkv7RmPoXvg2AcW9mTpJ82IWYw5H5KXwP+icMnvXl/U=
github.com/leaseweb/leaseweb-go-sdk/publicCloud v0.0.0-20241118100223-cb6c58ec7524/go.mod h1:nh4tvDxdD+xNL9qjFqtL1ZL49w+HJq5kMeTKkPs2XHI=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand Down
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,6 @@ func (p *leasewebProvider) Resources(_ context.Context) []func() resource.Resour
dedicatedserver.NewInstallationResource,
publiccloud.NewImageResource,
publiccloud.NewLoadBalancerResource,
publiccloud.NewLoadBalancerListenerResource,
}
}
114 changes: 114 additions & 0 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1744,3 +1744,117 @@ data "leaseweb_public_cloud_target_groups" "test" {
})
})
}

func TestAccPublicCloudLoadBalancerListenerResource(t *testing.T) {
t.Run(
"can create/import/update/delete load balancer listeners",
func(t *testing.T) {
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and Read testing
{
Config: providerConfig + `
resource "leaseweb_public_cloud_load_balancer_listener" "test" {
certificate = {
certificate = "-----BEGIN CERTIFICATE-----MIIBhDCB7gIBADBFMQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCtWdKNbZxvkXKAADjJMJ7VTJz6uFoMD403C+gMIF8hwqIsHggzCao6iXrW9sZoyZtUBVBiiq5RumHbbpwvOdMmXrShEB4sTJkWRMDy7yD4D91WCU1fc10E/zBJMwssAvmHZo5kGW1Pj1N9ktb+O/TMsEc6yd5suvdQj6aaJbQlTQIDAQABoAAwDQYJKoZIhvcNAQELBQADgYEAWOQ2CJLRo8MQgJgvhdoSIkHITnrbjB5hS3f/dx0lIcnyI6Q9nOyuQHXkCgkdBaV8lz7l+IbqcGc3CaIRP2ZIVFvo2252n630tOOSsqoqJS1tYIoIKsohi3T3d8T1i/s0BWbTJi8Xgd186wyUn/jHwXROKx2rq6yYsAO6fISDKw8=-----END CERTIFICATE-----"
chain = "-----BEGIN CERTIFICATE-----MIICNDCCAZ2gAwIBAgIUEby6nzM+o7vkKfzcMS/DGA8tgwQwDQYJKoZIhvcNAQELBQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yNDA0MjUwODE3MjZaFw0yNTA0MjUwODE3MjZaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMMiux2r1AFLVpIhdZ0bvgIvhiT9XCnfHJlGE7OarGKDKJDQ6XAquCfosLws2XAugGcMJWrsqVWtJEYSu6OMsDLYCJhh39AKqZIW0pktkr8LGlo4VLvzGPqwpHnzWthyCEFsE6p+JJQumDA/izJm2zjZL+xHDocOlNqDTB87AIdrAgMBAAGjITAfMB0GA1UdDgQWBBT3sXUrIR2vcwak0QCXoIsxHa4dDDANBgkqhkiG9w0BAQsFAAOBgQCh/l+5s713J02b8sWicUK2KjTPfyKmZFkoS+Mlo+//B/aM612ZJpGL2tAKGF3v0NDOrRYLZj0t/tlZI55pUNJI9cNj/RExvnfTSSNJIbV+8kQt5AHo50wGxj/apkuEtQre2Fpf4pyovcfIoF6HJvvp1jy96yL14UoEehZypR8FlA==-----END CERTIFICATE-----"
private_key = "-----BEGIN EC PRIVATE KEY-----MIHcAgEBBEIBVlC0IObonfQZIQ81l/WILKfWT5Fv96eNnYmQZ7uleu73igfiVESVuPfNlbW9oNEK1XcXli4YNZMxWMkKuzC3w8CgBwYFK4EEACOhgYkDgYYABAHvOqz9d2xeSpm1FNdw0NR5j/q6PMd6whZFsTPNYNj0/PsTpsHk78ZB4MYnJUXwHJjpj+gnKkLNc02f4w/vSF8VXADX4l40XU/w82TAOCftQwoxO5o0jZcwEUIYzl02Zd7uNxhjtKJQnYFi9x8WI8L8zQ6GZB/fJKYwoHaUr0I1h/5LzQ==-----END EC PRIVATE KEY-----"
}
default_rule = {
target_group_id = "b05917e1-96a4-442a-900c-c41f273d95c9"
}
load_balancer_id = "695ddd91-051f-4dd6-9120-938a927a47d0"
port = 443
protocol = "HTTPS"
}`,
},
// ImportState testing
{
ResourceName: "leaseweb_public_cloud_load_balancer_listener.test",
ImportStateId: "695ddd91-051f-4dd6-9120-938a927a47d0,fac06878-6655-4956-8ea7-124a97f133ab",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIdentifierAttribute: "listener_id",
},
// Update and Read testing
{
Config: providerConfig + `
resource "leaseweb_public_cloud_load_balancer_listener" "test" {
certificate = {
certificate = "-----BEGIN CERTIFICATE-----MIIBhDCB7gIBADBFMQswCQYD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BT3sXUrIR2vcwak0QCXoIsxHa4dDDANBgkqhkiG9w0BAQsFAAOBgQCh/l+5s713J02b8sWicUK2KjTPfyKmZFkoS+Mlo+//B/aM612ZJpGL2tAKGF3v0NDOrRYLZj0t/tlZI55pUNJI9cNj/RExvnfTSSNJIbV+8kQt5AHo50wGxj/apkuEtQre2Fpf4pyovcfIoF6HJvvp1jy96yL14UoEehZypR8FlA==-----END CERTIFICATE-----"
private_key = "-----BEGIN EC PRIVATE KEY-----MIHcAgEBBEIBVlC0IObonfQZIQ81l/WILKfWT5Fv96eNnYmQZ7uleu73igfiVESVuPfNlbW9oNEK1XcXli4YNZMxWMkKuzC3w8CgBwYFK4EEACOhgYkDgYYABAHvOqz9d2xeSpm1FNdw0NR5j/q6PMd6whZFsTPNYNj0/PsTpsHk78ZB4MYnJUXwHJjpj+gnKkLNc02f4w/vSF8VXADX4l40XU/w82TAOCftQwoxO5o0jZcwEUIYzl02Zd7uNxhjtKJQnYFi9x8WI8L8zQ6GZB/fJKYwoHaUr0I1h/5LzQ==-----END EC PRIVATE KEY-----"
}
default_rule = {
target_group_id = "b05917e1-96a4-442a-900c-c41f273d95c9"
}
load_balancer_id = "695ddd91-051f-4dd6-9120-938a927a47d0"
port = 443
protocol = "HTTPS"
}`,
},
// Delete testing automatically occurs in TestCase
},
})
},
)

t.Run("invalid protocol causes error to be thrown", func(t *testing.T) {
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: providerConfig + `
resource "leaseweb_public_cloud_load_balancer_listener" "test" {
default_rule = {
target_group_id = "b05917e1-96a4-442a-900c-c41f273d95c9"
}
load_balancer_id = "695ddd91-051f-4dd6-9120-938a927a47d0"
port = 80
protocol = "tralala"
}`,
ExpectError: regexp.MustCompile(
`Attribute protocol value must be one of:`,
),
},
},
})
})

t.Run("invalid port causes error to be thrown", func(t *testing.T) {
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: providerConfig + `
resource "leaseweb_public_cloud_load_balancer_listener" "test" {
default_rule = {
target_group_id = "b05917e1-96a4-442a-900c-c41f273d95c9"
}
load_balancer_id = "695ddd91-051f-4dd6-9120-938a927a47d0"
port = -8
protocol = "HTTP"
}`,
ExpectError: regexp.MustCompile(
`Attribute port value must be between`,
),
},
{
Config: providerConfig + `
resource "leaseweb_public_cloud_load_balancer_listener" "test" {
default_rule = {
target_group_id = "b05917e1-96a4-442a-900c-c41f273d95c9"
}
load_balancer_id = "695ddd91-051f-4dd6-9120-938a927a47d0"
port = 400000
protocol = "HTTP"
}`,
ExpectError: regexp.MustCompile(
`Attribute port value must be between`,
),
},
},
})
})
}
Loading

0 comments on commit b392033

Please sign in to comment.