backend

package
v1.203.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateS3Backend

func CreateS3Backend(
	ctx context.Context,
	atmosConfig *schema.AtmosConfiguration,
	backendConfig map[string]any,
	authContext *schema.AuthContext,
) error

CreateS3Backend creates an S3 backend with opinionated, hardcoded defaults.

Hardcoded features: - Versioning: ENABLED (always) - Encryption: AES-256 (AWS-managed keys, always) - Public Access: BLOCKED (all 4 settings, always) - Locking: Native S3 locking (Terraform 1.10+, no DynamoDB) - Tags: Standard tags (Name, ManagedBy, always)

No configuration options beyond enabled: true. For production use, migrate to terraform-aws-tfstate-backend module.

func DeleteS3Backend

func DeleteS3Backend(
	ctx context.Context,
	atmosConfig *schema.AtmosConfiguration,
	backendConfig map[string]any,
	authContext *schema.AuthContext,
	force bool,
) error

DeleteS3Backend deletes an S3 backend and all its contents.

Safety mechanisms include requiring force=true flag, listing all objects and versions before deletion, detecting and counting .tfstate files, warning user about data loss, and deleting all objects/versions before bucket deletion.

The process validates bucket configuration, checks bucket exists, lists all objects and versions, counts state files for warning, deletes all objects in batches (AWS limit: 1000 per request), and finally deletes the bucket itself.

This operation is irreversible. State files will be permanently lost.

func ProvisionBackend

func ProvisionBackend(
	ctx context.Context,
	atmosConfig *schema.AtmosConfiguration,
	componentConfig map[string]any,
	authContext *schema.AuthContext,
) error

ProvisionBackend provisions a backend if provisioning is enabled. Returns an error if provisioning fails or no provisioner is registered.

func RegisterBackendCreate

func RegisterBackendCreate(backendType string, fn BackendCreateFunc)

RegisterBackendCreate registers a backend create function for a specific backend type.

func RegisterBackendDelete

func RegisterBackendDelete(backendType string, fn BackendDeleteFunc)

RegisterBackendDelete registers a backend delete function for a specific backend type.

func ResetRegistryForTesting

func ResetRegistryForTesting()

ResetRegistryForTesting clears the backend provisioner registry. This function is intended for use in tests to ensure test isolation. It should be called via t.Cleanup() to restore clean state after each test.

Types

type BackendCreateFunc

type BackendCreateFunc func(
	ctx context.Context,
	atmosConfig *schema.AtmosConfiguration,
	backendConfig map[string]any,
	authContext *schema.AuthContext,
) error

BackendCreateFunc is a function that creates a Terraform backend.

func GetBackendCreate

func GetBackendCreate(backendType string) BackendCreateFunc

GetBackendCreate returns the create function for a backend type. Returns nil if no create function is registered for the type.

type BackendDeleteFunc

type BackendDeleteFunc func(
	ctx context.Context,
	atmosConfig *schema.AtmosConfiguration,
	backendConfig map[string]any,
	authContext *schema.AuthContext,
	force bool,
) error

BackendDeleteFunc is a function that deletes a Terraform backend.

func GetBackendDelete

func GetBackendDelete(backendType string) BackendDeleteFunc

GetBackendDelete returns the delete function for a backend type. Returns nil if no delete function is registered for the type.

type S3ClientAPI

type S3ClientAPI interface {
	HeadBucket(ctx context.Context, params *s3.HeadBucketInput, optFns ...func(*s3.Options)) (*s3.HeadBucketOutput, error)
	CreateBucket(ctx context.Context, params *s3.CreateBucketInput, optFns ...func(*s3.Options)) (*s3.CreateBucketOutput, error)
	PutBucketVersioning(ctx context.Context, params *s3.PutBucketVersioningInput, optFns ...func(*s3.Options)) (*s3.PutBucketVersioningOutput, error)
	PutBucketEncryption(ctx context.Context, params *s3.PutBucketEncryptionInput, optFns ...func(*s3.Options)) (*s3.PutBucketEncryptionOutput, error)
	PutPublicAccessBlock(ctx context.Context, params *s3.PutPublicAccessBlockInput, optFns ...func(*s3.Options)) (*s3.PutPublicAccessBlockOutput, error)
	PutBucketTagging(ctx context.Context, params *s3.PutBucketTaggingInput, optFns ...func(*s3.Options)) (*s3.PutBucketTaggingOutput, error)
	ListObjectVersions(ctx context.Context, params *s3.ListObjectVersionsInput, optFns ...func(*s3.Options)) (*s3.ListObjectVersionsOutput, error)
	DeleteObjects(ctx context.Context, params *s3.DeleteObjectsInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectsOutput, error)
	DeleteBucket(ctx context.Context, params *s3.DeleteBucketInput, optFns ...func(*s3.Options)) (*s3.DeleteBucketOutput, error)
}

S3ClientAPI defines the interface for S3 operations. This interface allows for mocking in tests.

Jump to

Keyboard shortcuts

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