diff

package
v0.15.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Copyright © 2025 Stackaroo Contributors SPDX-License-Identifier: BSD-3-Clause

Copyright © 2025 Stackaroo Contributors SPDX-License-Identifier: BSD-3-Clause

Copyright © 2025 Stackaroo Contributors SPDX-License-Identifier: BSD-3-Clause

Copyright © 2025 Stackaroo Contributors SPDX-License-Identifier: BSD-3-Clause

Copyright © 2025 Stackaroo Contributors SPDX-License-Identifier: BSD-3-Clause

Copyright © 2025 Stackaroo Contributors SPDX-License-Identifier: BSD-3-Clause

Copyright © 2025 Stackaroo Contributors SPDX-License-Identifier: BSD-3-Clause

Copyright © 2025 Stackaroo Contributors SPDX-License-Identifier: BSD-3-Clause

Copyright © 2025 Stackaroo Contributors SPDX-License-Identifier: BSD-3-Clause

Index

Constants

View Source
const CloudFormationDocsBaseURL = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/"

CloudFormationDocsBaseURL is the base URL for CloudFormation resource documentation

Variables

This section is empty.

Functions

func ColorizeUnifiedDiff

func ColorizeUnifiedDiff(diff string, styles *Styles) string

ColorizeUnifiedDiff applies color formatting to unified diff output

func GetResourceTypeURL

func GetResourceTypeURL(resourceType string) string

GetResourceTypeURL returns the CloudFormation documentation URL for a given resource type.

CloudFormation resource types follow the pattern: AWS::Service::ResourceType Documentation URLs follow the pattern: aws-resource-service-resourcetype.html

Parameters:

  • resourceType: A CloudFormation resource type (e.g., "AWS::S3::Bucket")

Returns the full documentation URL, or an empty string if the resource type is invalid or doesn't match the expected format.

Examples:

GetResourceTypeURL("AWS::S3::Bucket")
// Returns: "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-s3-bucket.html"

GetResourceTypeURL("AWS::EC2::Instance")
// Returns: "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-instance.html"

GetResourceTypeURL("InvalidFormat")
// Returns: ""

func Highlight

func Highlight(text string) string

Highlight returns the text highlighted in the accent color if colours are enabled

func Hyperlink(url, text string) string

Hyperlink wraps text with terminal hyperlink escape codes (OSC 8). This allows terminals that support it to display clickable links.

The OSC 8 format is: ESC ]8;;URL ESC \ TEXT ESC ]8;; ESC \ Where ESC is the escape character (\033).

Supported terminals include:

  • iTerm2 (3.1+)
  • Terminal.app (macOS 10.15+)
  • GNOME Terminal (3.26+)
  • Konsole
  • VS Code integrated terminal
  • Windows Terminal

Terminals without hyperlink support will display the text normally without any visual artifacts.

Parameters:

  • url: The target URL for the hyperlink
  • text: The visible text to display

Returns the text wrapped with hyperlink escape codes, or just the text if either url or text is empty.

Example:

link := Hyperlink("https://example.com", "Example")
fmt.Println(link) // Displays "Example" as a clickable link

func HyperlinkResourceType

func HyperlinkResourceType(resourceType string) string

HyperlinkResourceType creates a clickable hyperlink for a CloudFormation resource type.

This is a convenience function that combines GetResourceTypeURL with Hyperlink to create a terminal hyperlink pointing to the CloudFormation documentation for the given resource type.

Parameters:

  • resourceType: A CloudFormation resource type (e.g., "AWS::S3::Bucket")

Returns the resource type text wrapped with hyperlink escape codes, or just the original text if the resource type is invalid or empty.

Example:

link := HyperlinkResourceType("AWS::S3::Bucket")
// In supported terminals, displays "AWS::S3::Bucket" as a clickable link
// to the S3 Bucket CloudFormation documentation

func ShouldUseColour

func ShouldUseColour() bool

ShouldUseColour determines if colour output should be used

Types

type ChangeType

type ChangeType string

ChangeType indicates the type of change detected

const (
	ChangeTypeAdd    ChangeType = "ADD"
	ChangeTypeModify ChangeType = "MODIFY"
	ChangeTypeRemove ChangeType = "REMOVE"
)

type DefaultParameterComparator

type DefaultParameterComparator struct{}

DefaultParameterComparator implements ParameterComparator interface

func (*DefaultParameterComparator) Compare

func (c *DefaultParameterComparator) Compare(currentParams, proposedParams map[string]string) ([]ParameterDiff, error)

Compare compares current and proposed parameters, returning differences

type DefaultTagComparator

type DefaultTagComparator struct{}

DefaultTagComparator implements TagComparator interface

func (*DefaultTagComparator) Compare

func (c *DefaultTagComparator) Compare(currentTags, proposedTags map[string]string) ([]TagDiff, error)

Compare compares current and proposed tags, returning differences

type Differ

type Differ interface {
	// DiffStack compares a resolved stack configuration with the deployed stack
	DiffStack(ctx context.Context, stack *model.Stack, options Options) (*Result, error)
}

Differ defines the interface for performing stack diffs

type MockDiffer

type MockDiffer struct {
	mock.Mock
}

MockDiffer implements Differ for testing

func (*MockDiffer) DiffStack

func (m *MockDiffer) DiffStack(ctx context.Context, stack *model.Stack, options Options) (*Result, error)

type MockParameterComparator

type MockParameterComparator struct {
	mock.Mock
}

MockParameterComparator implements ParameterComparator for testing

func (*MockParameterComparator) Compare

func (m *MockParameterComparator) Compare(currentParams, proposedParams map[string]string) ([]ParameterDiff, error)

type MockTagComparator

type MockTagComparator struct {
	mock.Mock
}

MockTagComparator implements TagComparator for testing

func (*MockTagComparator) Compare

func (m *MockTagComparator) Compare(currentTags, proposedTags map[string]string) ([]TagDiff, error)

type MockTemplateComparator

type MockTemplateComparator struct {
	mock.Mock
}

MockTemplateComparator implements TemplateComparator for testing

func (*MockTemplateComparator) Compare

func (m *MockTemplateComparator) Compare(ctx context.Context, currentTemplate, proposedTemplate string) (*TemplateChange, error)

type Options

type Options struct {
	// Filter options - if all are false, compare everything
	TemplateOnly   bool // Only compare templates
	ParametersOnly bool // Only compare parameters
	TagsOnly       bool // Only compare tags

	// Changeset lifecycle control
	KeepChangeSet bool // Keep changeset alive after diff (for deployment use)
}

Options configures what aspects of the stack to compare

type ParameterComparator

type ParameterComparator interface {
	Compare(currentParams, proposedParams map[string]string) ([]ParameterDiff, error)
}

ParameterComparator handles parameter comparisons

func NewParameterComparator

func NewParameterComparator() ParameterComparator

NewParameterComparator creates a new parameter comparator

type ParameterDiff

type ParameterDiff struct {
	Key           string
	CurrentValue  string
	ProposedValue string
	ChangeType    ChangeType
}

ParameterDiff represents a difference in stack parameters

type Result

type Result struct {
	StackName      string
	Context        string
	StackExists    bool // Whether the stack exists in AWS
	TemplateChange *TemplateChange
	ParameterDiffs []ParameterDiff
	TagDiffs       []TagDiff
	ChangeSet      *aws.ChangeSetInfo // AWS changeset information when available
	ChangeSetError error              // Error encountered during changeset generation (if any)
	Options        Options            // Options used for this diff
}

Result contains the results of a stack diff operation

func (*Result) HasChanges

func (r *Result) HasChanges() bool

HasChanges returns true if any changes were detected

func (*Result) String

func (r *Result) String() string

String returns a human-readable representation of the diff results

type StackDiffer

type StackDiffer struct {
	// contains filtered or unexported fields
}

StackDiffer implements the Differ interface using AWS CloudFormation

func NewStackDiffer

func NewStackDiffer(clientFactory aws.ClientFactory) *StackDiffer

NewStackDiffer creates a new StackDiffer with provided client factory

func (*StackDiffer) DiffStack

func (d *StackDiffer) DiffStack(ctx context.Context, stack *model.Stack, options Options) (*Result, error)

DiffStack compares a resolved stack configuration with the deployed stack

type Styles

type Styles struct {
	// Change type styles (with background - for template diffs only)
	Added       lipgloss.Style
	Removed     lipgloss.Style
	Modified    lipgloss.Style
	DiffContext lipgloss.Style
	DiffHunk    lipgloss.Style

	// Change type styles (text only - for parameters, tags, plan)
	AddedText    lipgloss.Style
	RemovedText  lipgloss.Style
	ModifiedText lipgloss.Style

	// Status styles
	StatusNew      lipgloss.Style
	StatusChanges  lipgloss.Style
	StatusNoChange lipgloss.Style

	// Header styles
	Header      lipgloss.Style
	HeaderTitle lipgloss.Style
	HeaderValue lipgloss.Style

	// Section styles
	SectionHeader         lipgloss.Style
	SectionHeaderInactive lipgloss.Style
	SectionActive         lipgloss.Style
	SectionInactive       lipgloss.Style
	SubSection            lipgloss.Style

	// Content styles
	Key    lipgloss.Style
	Value  lipgloss.Style
	Arrow  lipgloss.Style
	Subtle lipgloss.Style
	Bold   lipgloss.Style

	// Semantic styles
	Success lipgloss.Style
	Warning lipgloss.Style
	Error   lipgloss.Style

	// Risk level styles
	RiskLow    lipgloss.Style
	RiskMedium lipgloss.Style
	RiskHigh   lipgloss.Style

	// Layout styles
	Footer    lipgloss.Style
	Separator lipgloss.Style

	// Whether colours are enabled
	UseColour bool
}

Styles contains all the styles for rendering diff output

func NewStyles

func NewStyles(useColour bool) *Styles

Colours are optimised based on terminal background (dark vs light).

func (*Styles) GetChangeSetSymbol

func (s *Styles) GetChangeSetSymbol(action string) string

GetChangeSetSymbol returns the appropriate symbol for a changeset action

func (*Styles) GetChangeSymbol

func (s *Styles) GetChangeSymbol(changeType ChangeType) string

GetChangeSymbol returns the appropriate symbol for a change type

type TagComparator

type TagComparator interface {
	Compare(currentTags, proposedTags map[string]string) ([]TagDiff, error)
}

TagComparator handles tag comparisons

func NewTagComparator

func NewTagComparator() TagComparator

NewTagComparator creates a new tag comparator

type TagDiff

type TagDiff struct {
	Key           string
	CurrentValue  string
	ProposedValue string
	ChangeType    ChangeType
}

TagDiff represents a difference in stack tags

type TemplateChange

type TemplateChange struct {
	HasChanges    bool
	CurrentHash   string // Hash of currently deployed template
	ProposedHash  string // Hash of proposed template
	Diff          string // Human-readable diff output
	ResourceCount struct {
		Added    int
		Modified int
		Removed  int
	}
}

TemplateChange represents differences in CloudFormation templates

type TemplateComparator

type TemplateComparator interface {
	Compare(ctx context.Context, currentTemplate, proposedTemplate string) (*TemplateChange, error)
}

TemplateComparator handles CloudFormation template comparisons

func NewYAMLTemplateComparator

func NewYAMLTemplateComparator() TemplateComparator

NewYAMLTemplateComparator creates a new YAML template comparator

type YAMLTemplateComparator

type YAMLTemplateComparator struct{}

YAMLTemplateComparator implements TemplateComparator for YAML CloudFormation templates

func (*YAMLTemplateComparator) Compare

func (c *YAMLTemplateComparator) Compare(ctx context.Context, currentTemplate, proposedTemplate string) (*TemplateChange, error)

Compare compares two CloudFormation templates and returns the differences

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL