Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lb): parse load balander id in frontend #1110

Merged
merged 5 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion scaleway/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func parseLocalizedNestedID(localizedID string) (locality string, innerID, outer
func parseZonedID(zonedID string) (zone scw.Zone, id string, err error) {
locality, id, err := parseLocalizedID(zonedID)
if err != nil {
return
return zone, id, err
}

zone, err = scw.ParseZone(locality)
Expand Down
28 changes: 4 additions & 24 deletions scaleway/resource_lb_frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ func resourceScalewayLbFrontend() *schema.Resource {
}

func resourceScalewayLbFrontendCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
lbAPI, _, err := lbAPIWithZone(d, meta)
lbAPI, zone, err := lbAPIWithZone(d, meta)
if err != nil {
return diag.FromErr(err)
}

zone, lbID, err := parseZonedID(d.Get("lb_id").(string))
if err != nil {
return diag.FromErr(err)
lbID := expandID(d.Get("lb_id"))
Monitob marked this conversation as resolved.
Show resolved Hide resolved
if lbID == "" {
return diag.Errorf("load balancer id wrong format: %v", d.Get("lb_id").(string))
}

retryInterval := defaultWaitLBRetryInterval
Expand Down Expand Up @@ -211,26 +211,6 @@ func resourceScalewayLbFrontendRead(ctx context.Context, d *schema.ResourceData,
return diag.FromErr(err)
}

_, lbID, err := parseZonedID(d.Get("lb_id").(string))
if err != nil {
return diag.FromErr(err)
}

retryInterval := defaultWaitLBRetryInterval
_, err = lbAPI.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
Zone: zone,
LBID: lbID,
Timeout: scw.TimeDurationPtr(defaultInstanceServerWaitTimeout),
RetryInterval: &retryInterval,
}, scw.WithContext(ctx))
if err != nil {
if is403Error(err) {
d.SetId("")
return nil
}
return diag.FromErr(err)
}

res, err := lbAPI.GetFrontend(&lb.ZonedAPIGetFrontendRequest{
Zone: zone,
FrontendID: ID,
Expand Down