aws

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: BSD-3-Clause Imports: 9 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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockClientFactoryForRegion added in v0.8.0

func NewMockClientFactoryForRegion(region string) (*MockClientFactory, *MockCloudFormationOperations)

NewMockClientFactoryForRegion creates a MockClientFactory with MockCloudFormationOperations for a region

Types

type ChangeSetInfo

type ChangeSetInfo struct {
	ChangeSetID string
	Status      string
	Changes     []ResourceChange
}

ChangeSetInfo contains information from AWS CloudFormation changeset

type ClientFactory added in v0.8.0

type ClientFactory interface {
	// GetCloudFormationOperations returns CloudFormation operations for specified region
	GetCloudFormationOperations(ctx context.Context, region string) (CloudFormationOperations, error)

	// GetBaseConfig returns the shared AWS configuration (for debugging)
	GetBaseConfig() aws.Config

	// ValidateRegion checks if a region is valid (optional validation)
	ValidateRegion(region string) error
}

ClientFactory creates AWS clients with proper region configuration

Example

ExampleClientFactory demonstrates how to create and use the AWS client factory

package main

import (
	"fmt"
)

func main() {
	// Example of client factory usage
	// ctx := context.Background()

	// Create a client factory (would use actual AWS credentials in real usage)
	// factory, _ := aws.NewClientFactory(ctx)

	// Example of getting CloudFormation operations for a specific region
	region := "us-east-1"
	// cfOps, _ := factory.GetCloudFormationOperations(ctx, region)

	fmt.Printf("ClientFactory would create operations for region: %s\n", region)
}
Output:

ClientFactory would create operations for region: us-east-1
Example (ExtensibleDesign)

ExampleClientFactory_extensibleDesign demonstrates how to extend for other AWS services

package main

import (
	"fmt"
)

func main() {
	// Example of how the client factory could be extended
	fmt.Println("CloudFormation operations available")
	fmt.Println("Future ClientFactory methods could include:")
	fmt.Println("- GetS3Operations(ctx, region)")
	fmt.Println("- GetEC2Operations(ctx, region)")
	fmt.Println("- GetIAMOperations(ctx, region)")
}
Output:

CloudFormation operations available
Future ClientFactory methods could include:
- GetS3Operations(ctx, region)
- GetEC2Operations(ctx, region)
- GetIAMOperations(ctx, region)

func NewClientFactory added in v0.8.0

func NewClientFactory(ctx context.Context) (ClientFactory, error)

NewClientFactory creates a client factory with shared authentication

type CloudFormationClient

type CloudFormationClient interface {
	CreateStack(ctx context.Context, params *cloudformation.CreateStackInput, optFns ...func(*cloudformation.Options)) (*cloudformation.CreateStackOutput, error)
	UpdateStack(ctx context.Context, params *cloudformation.UpdateStackInput, optFns ...func(*cloudformation.Options)) (*cloudformation.UpdateStackOutput, error)
	DeleteStack(ctx context.Context, params *cloudformation.DeleteStackInput, optFns ...func(*cloudformation.Options)) (*cloudformation.DeleteStackOutput, error)
	DescribeStacks(ctx context.Context, params *cloudformation.DescribeStacksInput, optFns ...func(*cloudformation.Options)) (*cloudformation.DescribeStacksOutput, error)
	ListStacks(ctx context.Context, params *cloudformation.ListStacksInput, optFns ...func(*cloudformation.Options)) (*cloudformation.ListStacksOutput, error)
	ValidateTemplate(ctx context.Context, params *cloudformation.ValidateTemplateInput, optFns ...func(*cloudformation.Options)) (*cloudformation.ValidateTemplateOutput, error)
	GetTemplate(ctx context.Context, params *cloudformation.GetTemplateInput, optFns ...func(*cloudformation.Options)) (*cloudformation.GetTemplateOutput, error)
	CreateChangeSet(ctx context.Context, params *cloudformation.CreateChangeSetInput, optFns ...func(*cloudformation.Options)) (*cloudformation.CreateChangeSetOutput, error)
	ExecuteChangeSet(ctx context.Context, params *cloudformation.ExecuteChangeSetInput, optFns ...func(*cloudformation.Options)) (*cloudformation.ExecuteChangeSetOutput, error)
	DeleteChangeSet(ctx context.Context, params *cloudformation.DeleteChangeSetInput, optFns ...func(*cloudformation.Options)) (*cloudformation.DeleteChangeSetOutput, error)
	DescribeChangeSet(ctx context.Context, params *cloudformation.DescribeChangeSetInput, optFns ...func(*cloudformation.Options)) (*cloudformation.DescribeChangeSetOutput, error)
	DescribeStackEvents(ctx context.Context, params *cloudformation.DescribeStackEventsInput, optFns ...func(*cloudformation.Options)) (*cloudformation.DescribeStackEventsOutput, error)
}

CloudFormationClient defines the interface for CloudFormation client operations This allows for easier testing with mock implementations

type CloudFormationOperations

type CloudFormationOperations interface {
	DeployStack(ctx context.Context, input DeployStackInput) error
	DeployStackWithCallback(ctx context.Context, input DeployStackInput, eventCallback func(StackEvent)) error
	UpdateStack(ctx context.Context, input UpdateStackInput) error
	DeleteStack(ctx context.Context, input DeleteStackInput) error
	GetStack(ctx context.Context, stackName string) (*Stack, error)
	ListStacks(ctx context.Context) ([]*Stack, error)
	ValidateTemplate(ctx context.Context, templateBody string) error
	StackExists(ctx context.Context, stackName string) (bool, error)
	GetTemplate(ctx context.Context, stackName string) (string, error)
	DescribeStack(ctx context.Context, stackName string) (*StackInfo, error)
	ExecuteChangeSet(ctx context.Context, changeSetID string) error
	DeleteChangeSet(ctx context.Context, changeSetID string) error
	DescribeStackEvents(ctx context.Context, stackName string) ([]StackEvent, error)
	WaitForStackOperation(ctx context.Context, stackName string, startTime time.Time, eventCallback func(StackEvent)) error
	CreateChangeSetPreview(ctx context.Context, stackName string, template string, parameters map[string]string, capabilities []string) (*ChangeSetInfo, error)
	CreateChangeSetForDeployment(ctx context.Context, stackName string, template string, parameters map[string]string, capabilities []string, tags map[string]string) (*ChangeSetInfo, error)
}

CloudFormationOperations defines the interface for CloudFormation operations

Example

ExampleCloudFormationOperations demonstrates CloudFormation operations

package main

import (
	"fmt"

	"github.com/orien/stackaroo/internal/aws"
)

func main() {
	// Example template structure
	template := `{
		"AWSTemplateFormatVersion": "2010-09-09",
		"Resources": {
			"MyBucket": {
				"Type": "AWS::S3::Bucket"
			}
		}
	}`

	// Example of deploy stack input structure
	deployInput := aws.DeployStackInput{
		StackName:    "my-example-stack",
		TemplateBody: template,
		Parameters: []aws.Parameter{
			{Key: "Environment", Value: "dev"},
		},
		Tags: map[string]string{
			"Project": "stackaroo-example",
		},
		Capabilities: []string{"CAPABILITY_IAM"},
	}

	fmt.Printf("Stack deployment would use template with %d resources\n", 1)
	fmt.Printf("Stack name: %s\n", deployInput.StackName)
}
Output:

Stack deployment would use template with 1 resources
Stack name: my-example-stack

type DefaultClientFactory added in v0.8.0

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

DefaultClientFactory implements ClientFactory with caching and shared authentication

func (*DefaultClientFactory) GetBaseConfig added in v0.8.0

func (f *DefaultClientFactory) GetBaseConfig() aws.Config

GetBaseConfig returns the shared AWS configuration

func (*DefaultClientFactory) GetCloudFormationOperations added in v0.8.0

func (f *DefaultClientFactory) GetCloudFormationOperations(ctx context.Context, region string) (CloudFormationOperations, error)

GetCloudFormationOperations returns CloudFormation operations for the specified region

func (*DefaultClientFactory) ValidateRegion added in v0.8.0

func (f *DefaultClientFactory) ValidateRegion(region string) error

ValidateRegion performs basic region validation

type DefaultCloudFormationOperations

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

DefaultCloudFormationOperations provides CloudFormation-specific operations

func NewCloudFormationOperationsWithClient

func NewCloudFormationOperationsWithClient(client CloudFormationClient) *DefaultCloudFormationOperations

NewCloudFormationOperationsWithClient creates operations with a custom client (for testing)

func (*DefaultCloudFormationOperations) CreateChangeSetForDeployment

func (cf *DefaultCloudFormationOperations) CreateChangeSetForDeployment(ctx context.Context, stackName string, template string, parameters map[string]string, capabilities []string, tags map[string]string) (*ChangeSetInfo, error)

CreateChangeSetForDeployment creates a changeset for deployment (doesn't auto-delete)

func (*DefaultCloudFormationOperations) CreateChangeSetPreview

func (cf *DefaultCloudFormationOperations) CreateChangeSetPreview(ctx context.Context, stackName string, template string, parameters map[string]string, capabilities []string) (*ChangeSetInfo, error)

CreateChangeSetPreview creates a CloudFormation changeset for preview, describes it, then deletes it

func (*DefaultCloudFormationOperations) DeleteChangeSet

func (cf *DefaultCloudFormationOperations) DeleteChangeSet(ctx context.Context, changeSetID string) error

DeleteChangeSet deletes a CloudFormation changeset

func (*DefaultCloudFormationOperations) DeleteStack

DeleteStack deletes a CloudFormation stack

func (*DefaultCloudFormationOperations) DeployStack

DeployStack creates or updates a CloudFormation stack and waits for completion

func (*DefaultCloudFormationOperations) DeployStackWithCallback

func (cf *DefaultCloudFormationOperations) DeployStackWithCallback(ctx context.Context, input DeployStackInput, eventCallback func(StackEvent)) error

DeployStackWithCallback creates or updates a CloudFormation stack and waits for completion, calling the provided callback for each event

func (*DefaultCloudFormationOperations) DescribeStack

func (cf *DefaultCloudFormationOperations) DescribeStack(ctx context.Context, stackName string) (*StackInfo, error)

DescribeStack retrieves detailed information about a specific stack including template

func (*DefaultCloudFormationOperations) DescribeStackEvents

func (cf *DefaultCloudFormationOperations) DescribeStackEvents(ctx context.Context, stackName string) ([]StackEvent, error)

DescribeStackEvents retrieves events for a CloudFormation stack

func (*DefaultCloudFormationOperations) ExecuteChangeSet

func (cf *DefaultCloudFormationOperations) ExecuteChangeSet(ctx context.Context, changeSetID string) error

ExecuteChangeSet executes a CloudFormation changeset by ID, abstracting AWS SDK details

func (*DefaultCloudFormationOperations) GetStack

func (cf *DefaultCloudFormationOperations) GetStack(ctx context.Context, stackName string) (*Stack, error)

GetStack retrieves information about a specific stack

func (*DefaultCloudFormationOperations) GetTemplate

func (cf *DefaultCloudFormationOperations) GetTemplate(ctx context.Context, stackName string) (string, error)

GetTemplate retrieves the template for a CloudFormation stack

func (*DefaultCloudFormationOperations) ListStacks

func (cf *DefaultCloudFormationOperations) ListStacks(ctx context.Context) ([]*Stack, error)

ListStacks returns a list of all CloudFormation stacks

func (*DefaultCloudFormationOperations) StackExists

func (cf *DefaultCloudFormationOperations) StackExists(ctx context.Context, stackName string) (bool, error)

StackExists checks if a stack exists

func (*DefaultCloudFormationOperations) UpdateStack

UpdateStack updates an existing CloudFormation stack

func (*DefaultCloudFormationOperations) ValidateTemplate

func (cf *DefaultCloudFormationOperations) ValidateTemplate(ctx context.Context, templateBody string) error

ValidateTemplate validates a CloudFormation template

func (*DefaultCloudFormationOperations) WaitForStackOperation

func (cf *DefaultCloudFormationOperations) WaitForStackOperation(ctx context.Context, stackName string, startTime time.Time, eventCallback func(StackEvent)) error

WaitForStackOperation waits for a CloudFormation stack operation to complete, calling the provided callback for each new event

type DeleteStackInput

type DeleteStackInput struct {
	StackName string
}

DeleteStackInput contains parameters for deleting a stack

type DeployStackInput

type DeployStackInput struct {
	StackName    string
	TemplateBody string
	Parameters   []Parameter
	Tags         map[string]string
	Capabilities []string
}

DeployStackInput contains parameters for deploying a stack

type MockClientFactory added in v0.8.0

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

MockClientFactory provides a test implementation of ClientFactory

func NewMockClientFactory added in v0.8.0

func NewMockClientFactory() *MockClientFactory

NewMockClientFactory creates a mock factory for testing

func NewMockClientFactoryWithOperations added in v0.8.0

func NewMockClientFactoryWithOperations(region string, ops CloudFormationOperations) *MockClientFactory

NewMockClientFactoryWithOperations creates a MockClientFactory and sets up operations for a region

func SetupMockFactoryForMultiRegion added in v0.8.0

func SetupMockFactoryForMultiRegion(regions map[string]CloudFormationOperations) *MockClientFactory

SetupMockFactoryForMultiRegion creates a factory with operations for multiple regions

func (*MockClientFactory) GetBaseConfig added in v0.8.0

func (m *MockClientFactory) GetBaseConfig() aws.Config

GetBaseConfig returns the mock base configuration

func (*MockClientFactory) GetCloudFormationOperations added in v0.8.0

func (m *MockClientFactory) GetCloudFormationOperations(ctx context.Context, region string) (CloudFormationOperations, error)

GetCloudFormationOperations returns mock operations for the specified region

func (*MockClientFactory) SetOperations added in v0.8.0

func (m *MockClientFactory) SetOperations(region string, ops CloudFormationOperations)

SetOperations sets mock operations for a specific region

func (*MockClientFactory) ValidateRegion added in v0.8.0

func (m *MockClientFactory) ValidateRegion(region string) error

ValidateRegion always returns nil for mock

type MockCloudFormationClient added in v0.3.0

type MockCloudFormationClient struct {
	mock.Mock
}

MockCloudFormationClient implements the AWS CloudFormation service client interface for testing

func (*MockCloudFormationClient) CreateChangeSet added in v0.3.0

func (*MockCloudFormationClient) CreateStack added in v0.3.0

func (*MockCloudFormationClient) DeleteChangeSet added in v0.3.0

func (*MockCloudFormationClient) DeleteStack added in v0.3.0

func (*MockCloudFormationClient) DescribeChangeSet added in v0.3.0

func (*MockCloudFormationClient) DescribeStackEvents added in v0.3.0

func (*MockCloudFormationClient) DescribeStacks added in v0.3.0

func (*MockCloudFormationClient) ExecuteChangeSet added in v0.3.0

func (*MockCloudFormationClient) GetTemplate added in v0.3.0

func (*MockCloudFormationClient) ListStacks added in v0.3.0

func (*MockCloudFormationClient) UpdateStack added in v0.3.0

func (*MockCloudFormationClient) ValidateTemplate added in v0.3.0

type MockCloudFormationOperations added in v0.3.0

type MockCloudFormationOperations struct {
	mock.Mock
}

MockCloudFormationOperations implements CloudFormationOperations for testing

func (*MockCloudFormationOperations) CreateChangeSetForDeployment added in v0.3.0

func (m *MockCloudFormationOperations) CreateChangeSetForDeployment(ctx context.Context, stackName string, template string, parameters map[string]string, capabilities []string, tags map[string]string) (*ChangeSetInfo, error)

func (*MockCloudFormationOperations) CreateChangeSetPreview added in v0.3.0

func (m *MockCloudFormationOperations) CreateChangeSetPreview(ctx context.Context, stackName string, template string, parameters map[string]string, capabilities []string) (*ChangeSetInfo, error)

func (*MockCloudFormationOperations) DeleteChangeSet added in v0.3.0

func (m *MockCloudFormationOperations) DeleteChangeSet(ctx context.Context, changeSetID string) error

func (*MockCloudFormationOperations) DeleteStack added in v0.3.0

func (*MockCloudFormationOperations) DeployStack added in v0.3.0

func (*MockCloudFormationOperations) DeployStackWithCallback added in v0.3.0

func (m *MockCloudFormationOperations) DeployStackWithCallback(ctx context.Context, input DeployStackInput, eventCallback func(StackEvent)) error

func (*MockCloudFormationOperations) DescribeStack added in v0.3.0

func (m *MockCloudFormationOperations) DescribeStack(ctx context.Context, stackName string) (*StackInfo, error)

func (*MockCloudFormationOperations) DescribeStackEvents added in v0.3.0

func (m *MockCloudFormationOperations) DescribeStackEvents(ctx context.Context, stackName string) ([]StackEvent, error)

func (*MockCloudFormationOperations) ExecuteChangeSet added in v0.3.0

func (m *MockCloudFormationOperations) ExecuteChangeSet(ctx context.Context, changeSetID string) error

func (*MockCloudFormationOperations) GetStack added in v0.3.0

func (m *MockCloudFormationOperations) GetStack(ctx context.Context, stackName string) (*Stack, error)

func (*MockCloudFormationOperations) GetTemplate added in v0.3.0

func (m *MockCloudFormationOperations) GetTemplate(ctx context.Context, stackName string) (string, error)

func (*MockCloudFormationOperations) ListStacks added in v0.3.0

func (m *MockCloudFormationOperations) ListStacks(ctx context.Context) ([]*Stack, error)

func (*MockCloudFormationOperations) StackExists added in v0.3.0

func (m *MockCloudFormationOperations) StackExists(ctx context.Context, stackName string) (bool, error)

func (*MockCloudFormationOperations) UpdateStack added in v0.3.0

func (*MockCloudFormationOperations) ValidateTemplate added in v0.3.0

func (m *MockCloudFormationOperations) ValidateTemplate(ctx context.Context, templateBody string) error

func (*MockCloudFormationOperations) WaitForStackOperation added in v0.3.0

func (m *MockCloudFormationOperations) WaitForStackOperation(ctx context.Context, stackName string, startTime time.Time, eventCallback func(StackEvent)) error

type NoChangesError

type NoChangesError struct {
	StackName string
}

NoChangesError indicates that a stack operation had no changes to apply

func (NoChangesError) Error

func (e NoChangesError) Error() string

type Parameter

type Parameter struct {
	Key   string
	Value string
}

Parameter represents a CloudFormation stack parameter

type ResourceChange

type ResourceChange struct {
	Action       string // CREATE, UPDATE, DELETE
	ResourceType string
	LogicalID    string
	PhysicalID   string
	Replacement  string // True, False, or Conditional
	Details      []string
}

ResourceChange represents a change to a CloudFormation resource

type Stack

type Stack struct {
	Name        string
	Status      StackStatus
	CreatedTime *time.Time
	UpdatedTime *time.Time
	Description string
	Parameters  map[string]string
	Outputs     map[string]string
	Tags        map[string]string
}

Stack represents a CloudFormation stack with essential information

type StackEvent

type StackEvent struct {
	EventId              string
	StackName            string
	LogicalResourceId    string
	PhysicalResourceId   string
	ResourceType         string
	Timestamp            time.Time
	ResourceStatus       string
	ResourceStatusReason string
}

StackEvent represents a CloudFormation stack event

type StackInfo

type StackInfo struct {
	Name        string
	Status      StackStatus
	CreatedTime *time.Time
	UpdatedTime *time.Time
	Description string
	Parameters  map[string]string
	Outputs     map[string]string
	Tags        map[string]string
	Template    string // The actual template content
}

StackInfo represents detailed CloudFormation stack information for diff operations

type StackStatus

type StackStatus string

StackStatus represents the status of a CloudFormation stack

const (
	StackStatusCreateInProgress         StackStatus = "CREATE_IN_PROGRESS"
	StackStatusCreateComplete           StackStatus = "CREATE_COMPLETE"
	StackStatusCreateFailed             StackStatus = "CREATE_FAILED"
	StackStatusDeleteInProgress         StackStatus = "DELETE_IN_PROGRESS"
	StackStatusDeleteComplete           StackStatus = "DELETE_COMPLETE"
	StackStatusDeleteFailed             StackStatus = "DELETE_FAILED"
	StackStatusUpdateInProgress         StackStatus = "UPDATE_IN_PROGRESS"
	StackStatusUpdateComplete           StackStatus = "UPDATE_COMPLETE"
	StackStatusUpdateFailed             StackStatus = "UPDATE_FAILED"
	StackStatusUpdateRollbackInProgress StackStatus = "UPDATE_ROLLBACK_IN_PROGRESS"
	StackStatusUpdateRollbackComplete   StackStatus = "UPDATE_ROLLBACK_COMPLETE"
	StackStatusUpdateRollbackFailed     StackStatus = "UPDATE_ROLLBACK_FAILED"
	StackStatusRollbackInProgress       StackStatus = "ROLLBACK_IN_PROGRESS"
	StackStatusRollbackComplete         StackStatus = "ROLLBACK_COMPLETE"
	StackStatusRollbackFailed           StackStatus = "ROLLBACK_FAILED"
	StackStatusReviewInProgress         StackStatus = "REVIEW_IN_PROGRESS"
	StackStatusImportInProgress         StackStatus = "IMPORT_IN_PROGRESS"
	StackStatusImportComplete           StackStatus = "IMPORT_COMPLETE"
	StackStatusImportRollbackInProgress StackStatus = "IMPORT_ROLLBACK_IN_PROGRESS"
	StackStatusImportRollbackComplete   StackStatus = "IMPORT_ROLLBACK_COMPLETE"
	StackStatusImportRollbackFailed     StackStatus = "IMPORT_ROLLBACK_FAILED"
)

type UpdateStackInput

type UpdateStackInput struct {
	StackName    string
	TemplateBody string
	Parameters   []Parameter
	Tags         map[string]string
	Capabilities []string
}

UpdateStackInput contains parameters for updating a stack

Jump to

Keyboard shortcuts

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