(ctx context.Context, stackName, templateBody string, parameters []*cloudformation.Parameter)
| 174 | } |
| 175 | |
| 176 | func (s *StackDeployer) updateStack(ctx context.Context, stackName, templateBody string, parameters []*cloudformation.Parameter) (*StackOutput, error) { |
| 177 | log.Printf("Updating existing stack...") |
| 178 | |
| 179 | input := &cloudformation.UpdateStackInput{ |
| 180 | StackName: aws.String(stackName), |
| 181 | TemplateBody: aws.String(templateBody), |
| 182 | Parameters: parameters, |
| 183 | Capabilities: []*string{ |
| 184 | aws.String(cloudformation.CapabilityCapabilityNamedIam), |
| 185 | }, |
| 186 | } |
| 187 | |
| 188 | _, err := s.clients.CloudFormation.UpdateStackWithContext(ctx, input) |
| 189 | if err != nil { |
| 190 | if awsErr, ok := err.(awserr.Error); ok { |
| 191 | if awsErr.Code() == "ValidationError" && strings.Contains(awsErr.Message(), "No updates are to be performed") { |
| 192 | log.Printf("No updates needed for stack") |
| 193 | return s.GetStackOutputs(ctx) |
| 194 | } |
| 195 | } |
| 196 | return nil, fmt.Errorf("failed to update stack: %w", err) |
| 197 | } |
| 198 | |
| 199 | // Wait for update to complete |
| 200 | log.Printf("Waiting for stack update to complete...") |
| 201 | err = s.waitForStackOperation(ctx, stackName, cloudformation.StackStatusUpdateComplete, 10*time.Minute) |
| 202 | if err != nil { |
| 203 | return nil, fmt.Errorf("stack update failed: %w", err) |
| 204 | } |
| 205 | |
| 206 | log.Printf("Stack updated successfully") |
| 207 | return s.GetStackOutputs(ctx) |
| 208 | } |
| 209 | |
| 210 | func (s *StackDeployer) stackExists(ctx context.Context, stackName string) (bool, error) { |
| 211 | input := &cloudformation.DescribeStacksInput{ |
no test coverage detected