Skip to content

Commit

Permalink
feat(lbaas): add support for lb redirect rule status (#702)
Browse files Browse the repository at this point in the history
* Upgrading pre-commit version

* feat(lbaas): add support for lb redirect rule status

* Pointing to the go-api version with changes in the api

* Point to the latest release

* chore: Updating CHANGELOG.md

* chore: prefix changelog entry with resource name

---------

Co-authored-by: Toni Kangas <[email protected]>
  • Loading branch information
paketeserrano and kangasta authored Feb 6, 2025
1 parent 0785c41 commit 1c9eccb
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.52.2
rev: v1.63.4
hooks:
- id: golangci-lint
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

### Added

- upcloud_loadbalancer_frontend_rule: add support for load balancer redirect rule status

## [5.18.0] - 2025-01-30

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,19 @@ resource "upcloud_loadbalancer" "lb" {
name = "lb-test"
plan = "development"
zone = var.lb_zone
network = resource.upcloud_network.lb_network.id

networks {
type = "public"
family = "IPv4"
name = "public"
}

networks {
type = "private"
family = "IPv4"
name = "private"
network = resource.upcloud_network.lb_network.id
}
}

resource "upcloud_loadbalancer_backend" "lb_be_1" {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.0
toolchain go1.23.2

require (
github.com/UpCloudLtd/upcloud-go-api/v8 v8.13.0
github.com/UpCloudLtd/upcloud-go-api/v8 v8.15.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/hashicorp/go-uuid v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
github.com/UpCloudLtd/upcloud-go-api/v8 v8.13.0 h1:QrHfrdGb2HjJiUezO+N46c9pZEiwKPGyDJHHRmXimmI=
github.com/UpCloudLtd/upcloud-go-api/v8 v8.13.0/go.mod h1:bFnrOkfsDDmsb94nnBV5eSQjjsfDnwAzLnCt9+b4t/4=
github.com/UpCloudLtd/upcloud-go-api/v8 v8.15.0 h1:pE+WQh/rVG8PBR91C68KIZ58z3R/t5i5RuYa4/IdZb4=
github.com/UpCloudLtd/upcloud-go-api/v8 v8.15.0/go.mod h1:bFnrOkfsDDmsb94nnBV5eSQjjsfDnwAzLnCt9+b4t/4=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
Expand Down
8 changes: 8 additions & 0 deletions internal/service/loadbalancer/frontend_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ func (r *frontendRuleResource) Schema(_ context.Context, _ resource.SchemaReques
),
},
},
"status": schema.Int64Attribute{
MarkdownDescription: "HTTP status code.",
Optional: true,
Computed: true,
Validators: []validator.Int64{
int64validator.OneOf(301, 302, 303, 307, 308),
},
},
},
},
Validators: []validator.List{
Expand Down
7 changes: 5 additions & 2 deletions internal/service/loadbalancer/frontend_rule_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type frontendRuleActionModel struct {
type frontendRuleActionHTTPRedirectModel struct {
Location types.String `tfsdk:"location"`
Scheme types.String `tfsdk:"scheme"`
Status types.Int64 `tfsdk:"status"`
}

type frontendRuleActionHTTPReturnModel struct {
Expand Down Expand Up @@ -142,9 +143,9 @@ func buildFrontendRuleActions(ctx context.Context, dataActions types.List) ([]up
for _, httpRedirect := range httpRedirects {
var action upcloud.LoadBalancerAction
if httpRedirect.Scheme.ValueString() != "" {
action = request.NewLoadBalancerHTTPRedirectSchemeAction(upcloud.LoadBalancerActionHTTPRedirectScheme(httpRedirect.Scheme.ValueString()))
action = request.NewLoadBalancerHTTPRedirectSchemeActionWithStatus(upcloud.LoadBalancerActionHTTPRedirectScheme(httpRedirect.Scheme.ValueString()), int(httpRedirect.Status.ValueInt64()))
} else if httpRedirect.Location.ValueString() != "" {
action = request.NewLoadBalancerHTTPRedirectAction(httpRedirect.Location.ValueString())
action = request.NewLoadBalancerHTTPRedirectActionWithStatus(httpRedirect.Location.ValueString(), int(httpRedirect.Status.ValueInt64()))
}

actions = append(actions, action)
Expand Down Expand Up @@ -228,6 +229,8 @@ func setFrontendRuleActionsValues(ctx context.Context, data *frontendRuleModel,
httpRedirect.Location = types.StringValue(a.HTTPRedirect.Location)
}

httpRedirect.Status = types.Int64Value(int64(a.HTTPRedirect.Status))

httpRedirects = append(httpRedirects, httpRedirect)
}

Expand Down

0 comments on commit 1c9eccb

Please sign in to comment.