Documentation
¶
Index ¶
- func BackendExists(ctx context.Context, atmosConfig *schema.AtmosConfiguration, ...) (bool, error)
- func BackendName(backendType string, backendConfig map[string]any) string
- func DeleteS3Backend(ctx context.Context, atmosConfig *schema.AtmosConfiguration, ...) error
- func RegisterBackendCreate(backendType string, fn BackendCreateFunc)
- func RegisterBackendDelete(backendType string, fn BackendDeleteFunc)
- func RegisterBackendExists(backendType string, fn BackendExistsFunc)
- func RegisterBackendName(backendType string, fn BackendNameFunc)
- func ResetRegistryForTesting()
- func ResetS3ClientFactory()
- func S3BackendExists(ctx context.Context, atmosConfig *schema.AtmosConfiguration, ...) (bool, error)
- func S3BackendName(backendConfig map[string]any) string
- func SetS3ClientFactory(f func(aws.Config) S3ClientAPI)
- func SetS3SkipUnsupportedTestOps(skip bool)
- type BackendCreateFunc
- type BackendDeleteFunc
- type BackendExistsFunc
- type BackendNameFunc
- type ProvisionResult
- type S3ClientAPI
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BackendExists ¶ added in v1.204.0
func BackendExists( ctx context.Context, atmosConfig *schema.AtmosConfiguration, backendType string, backendConfig map[string]any, authContext *schema.AuthContext, ) (bool, error)
BackendExists checks if a backend already exists. Returns (true, nil) if backend exists, (false, nil) if it doesn't exist, or (false, error) if the check fails.
func BackendName ¶ added in v1.204.0
BackendName extracts the backend resource name from config. Returns "unknown" if no name extractor is registered or if extraction fails.
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 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 RegisterBackendExists ¶ added in v1.204.0
func RegisterBackendExists(backendType string, fn BackendExistsFunc)
RegisterBackendExists registers a backend exists function for a specific backend type.
func RegisterBackendName ¶ added in v1.204.0
func RegisterBackendName(backendType string, fn BackendNameFunc)
RegisterBackendName registers a backend name 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.
func ResetS3ClientFactory ¶ added in v1.204.0
func ResetS3ClientFactory()
ResetS3ClientFactory resets the S3 client factory to default.
func S3BackendExists ¶ added in v1.204.0
func S3BackendExists( ctx context.Context, atmosConfig *schema.AtmosConfiguration, backendConfig map[string]any, authContext *schema.AuthContext, ) (bool, error)
S3BackendExists checks if an S3 backend bucket exists. This function is registered in the backend registry and called during auto-provisioning to check if the backend already exists before attempting to create it.
func S3BackendName ¶ added in v1.204.0
S3BackendName returns the bucket name from S3 backend config.
func SetS3ClientFactory ¶ added in v1.204.0
func SetS3ClientFactory(f func(aws.Config) S3ClientAPI)
SetS3ClientFactory sets a custom S3 client factory for testing.
func SetS3SkipUnsupportedTestOps ¶ added in v1.204.0
func SetS3SkipUnsupportedTestOps(skip bool)
SetS3SkipUnsupportedTestOps sets whether to skip unsupported S3 operations. This should only be called in tests using gofakes3.
Types ¶
type BackendCreateFunc ¶
type BackendCreateFunc func( ctx context.Context, atmosConfig *schema.AtmosConfiguration, backendConfig map[string]any, authContext *schema.AuthContext, ) (*ProvisionResult, 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 BackendExistsFunc ¶ added in v1.204.0
type BackendExistsFunc func( ctx context.Context, atmosConfig *schema.AtmosConfiguration, backendConfig map[string]any, authContext *schema.AuthContext, ) (bool, error)
BackendExistsFunc is a function that checks if a backend exists.
func GetBackendExists ¶ added in v1.204.0
func GetBackendExists(backendType string) BackendExistsFunc
GetBackendExists returns the exists function for a backend type. Returns nil if no exists function is registered for the type.
type BackendNameFunc ¶ added in v1.204.0
BackendNameFunc is a function that extracts the backend resource name from config. For S3, this returns the bucket name. For GCS, the bucket name. For Azure, the container name.
func GetBackendName ¶ added in v1.204.0
func GetBackendName(backendType string) BackendNameFunc
GetBackendName returns the name function for a backend type. Returns nil if no name function is registered for the type.
type ProvisionResult ¶ added in v1.204.0
type ProvisionResult struct {
Warnings []string // Warning messages to display after spinner completes.
}
ProvisionResult holds the result of a backend provisioning operation.
func CreateS3Backend ¶
func CreateS3Backend( ctx context.Context, atmosConfig *schema.AtmosConfiguration, backendConfig map[string]any, authContext *schema.AuthContext, ) (*ProvisionResult, 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 ProvisionBackend ¶
func ProvisionBackend( ctx context.Context, atmosConfig *schema.AtmosConfiguration, componentConfig map[string]any, authContext *schema.AuthContext, ) (*ProvisionResult, error)
ProvisionBackend provisions a backend if provisioning is enabled. Returns ProvisionResult with any warnings, and an error if provisioning fails or no provisioner is registered.
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.