@@ -32,6 +32,7 @@ const (
3232type inputModel struct {
3333 * globalflags.GlobalFlagModel
3434 Configuration * string
35+ Version * string
3536}
3637
3738func NewCmd (p * print.Printer ) * cobra.Command {
@@ -72,6 +73,11 @@ func NewCmd(p *print.Printer) *cobra.Command {
7273 }
7374 }
7475
76+ // for updates of an existing ALB the current version must be passed to the request
77+ model .Version , err = getCurrentAlbVersion (ctx , apiClient , model )
78+ if err != nil {
79+ return err
80+ }
7581 // Call API
7682 req , err := buildRequest (ctx , model , apiClient )
7783 if err != nil {
@@ -86,7 +92,8 @@ func NewCmd(p *print.Printer) *cobra.Command {
8692 if ! model .Async {
8793 s := spinner .New (p )
8894 s .Start ("updating loadbalancer" )
89- _ , err = wait .CreateOrUpdateLoadbalancerWaitHandler (ctx , apiClient , model .ProjectId , model .Region , * resp .Name ).WaitWithContext (ctx )
95+ _ , err = wait .CreateOrUpdateLoadbalancerWaitHandler (ctx , apiClient , model .ProjectId , model .Region , * resp .Name ).
96+ WaitWithContext (ctx )
9097 if err != nil {
9198 return fmt .Errorf ("wait for loadbalancer update: %w" , err )
9299 }
@@ -129,11 +136,34 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
129136 return & model , nil
130137}
131138
139+ func getCurrentAlbVersion (ctx context.Context , apiClient * alb.APIClient , model * inputModel ) (* string , error ) {
140+ // use the configuration file to find the name of the loadbalancer
141+ updatePayload , err := readPayload (ctx , model )
142+ if err != nil {
143+ return nil , err
144+ }
145+ if updatePayload .Name == nil {
146+ return nil , fmt .Errorf ("no name found in configuration" )
147+ }
148+ if err != nil {
149+ return nil , err
150+ }
151+ resp , err := apiClient .GetLoadBalancer (ctx , model .ProjectId , model .Region , * updatePayload .Name ).Execute ()
152+ if err != nil {
153+ return nil , err
154+ }
155+ return resp .Version , nil
156+ }
157+
132158func buildRequest (ctx context.Context , model * inputModel , apiClient * alb.APIClient ) (req alb.ApiUpdateLoadBalancerRequest , err error ) {
133159 payload , err := readPayload (ctx , model )
134160 if err != nil {
135161 return req , err
136162 }
163+ if payload .Name == nil {
164+ return req , fmt .Errorf ("no name found in loadbalancer configuration" )
165+ }
166+ payload .Version = model .Version
137167 req = apiClient .UpdateLoadBalancer (ctx , model .ProjectId , model .Region , * payload .Name )
138168 return req .UpdateLoadBalancerPayload (payload ), nil
139169}
0 commit comments