GetCloudFormationTemplate returns the CloudFormation template content
(cfg *config.CLIConfig, customTemplatePath string)
| 20 | |
| 21 | // GetCloudFormationTemplate returns the CloudFormation template content |
| 22 | func GetCloudFormationTemplate(cfg *config.CLIConfig, customTemplatePath string) (string, error) { |
| 23 | var templateContent string |
| 24 | |
| 25 | // Use custom template file if provided |
| 26 | if customTemplatePath != "" { |
| 27 | content, err := os.ReadFile(customTemplatePath) |
| 28 | if err != nil { |
| 29 | return "", fmt.Errorf("failed to read custom template file %s: %w", customTemplatePath, err) |
| 30 | } |
| 31 | templateContent = string(content) |
| 32 | } else { |
| 33 | // Use embedded template |
| 34 | templateContent = embeddedTemplate |
| 35 | } |
| 36 | |
| 37 | // Perform parameter substitution |
| 38 | params := TemplateParams{ |
| 39 | StackName: cfg.Deployment.StackName, |
| 40 | } |
| 41 | |
| 42 | substitutedTemplate, err := substituteTemplateParams(templateContent, params) |
| 43 | if err != nil { |
| 44 | return "", fmt.Errorf("failed to substitute template parameters: %w", err) |
| 45 | } |
| 46 | |
| 47 | return substitutedTemplate, nil |
| 48 | } |
| 49 | |
| 50 | // substituteTemplateParams performs basic parameter substitution in the template |
| 51 | func substituteTemplateParams(templateContent string, params TemplateParams) (string, error) { |