backend

package
v1.227.0-test.4 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AzurermBackendExists added in v1.226.0

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

AzurermBackendExists reports whether the azurerm backend is fully provisioned — i.e. both the storage account and the container exist. Returning false when the container is missing lets the (idempotent) create path finish provisioning it. Registered in the backend registry and called during auto-provisioning to decide whether to skip creation.

func AzurermBackendName added in v1.226.0

func AzurermBackendName(backendConfig map[string]any) string

AzurermBackendName returns the storage account name from azurerm backend config. The storage account is the primary provisioned artifact (the S3-bucket analog).

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

func BackendName(backendType string, backendConfig map[string]any) string

BackendName extracts the backend resource name from config. Returns "unknown" if no name extractor is registered or if extraction fails.

func DeleteAzurermBackend added in v1.226.0

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

DeleteAzurermBackend deletes an azurerm backend by permanently deleting the storage account and everything in it — the Azure analog of DeleteS3Backend deleting an S3 bucket.

The storage account is the backend's top-level provisioned artifact and holds the container and every state blob (one per component `key`). Deleting it removes them all, exactly as deleting an S3 bucket removes every state object. The resource group is intentionally left in place, since it commonly holds unrelated resources.

This runs inside a spinner (see DeleteBackendWithParams), so it emits no direct UI output — the spinner reports progress and completion, and `--force` is the destructive-action gate.

This operation is irreversible. All Terraform state stored in the account will be lost.

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 ResetAzureBackendClientFactory added in v1.226.0

func ResetAzureBackendClientFactory()

ResetAzureBackendClientFactory resets the Azure backend client factory to default.

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

func S3BackendName(backendConfig map[string]any) string

S3BackendName returns the bucket name from S3 backend config.

func SetAzureBackendClientFactory added in v1.226.0

func SetAzureBackendClientFactory(f func(string, *schema.AuthContext) (azureBackendAPI, error))

SetAzureBackendClientFactory sets a custom Azure backend client factory for testing.

func SetS3ClientFactory added in v1.204.0

func SetS3ClientFactory(f func(aws.Config, ...func(*s3.Options)) 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

type BackendNameFunc func(backendConfig map[string]any) string

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 CreateAzurermBackend added in v1.226.0

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

CreateAzurermBackend creates an azurerm backend with opinionated, hardcoded defaults — the Azure analog of CreateS3Backend.

Hardcoded features:

  • Resource group: created if missing (in the identity's location).
  • Storage account: StorageV2, Standard_LRS, TLS 1.2 minimum, HTTPS-only, public blob access BLOCKED. Shared-key access is disabled when the backend uses `use_azuread_auth: true` (Entra-ID-only), otherwise left at the Azure default.
  • Blob data protection: versioning ENABLED (the S3-versioning analog) + 30-day soft delete.
  • Container: created if missing, PRIVATE (no public access).
  • Tags: Name + ManagedBy=Atmos.

State locking needs NO extra resource on Azure: the azurerm backend serializes writes with native blob leases on the state blob (the DynamoDB-lock analog is built into Blob Storage).

No configuration options beyond `provision.backend.enabled: true`. For production use, migrate to a managed module (e.g. Azure/avm-res-storage-storageaccount).

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.

Jump to

Keyboard shortcuts

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