cfnstack

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cfnstack is the toolkit's view of stacks deployed in CloudFormation, as upstream's api/cloudformation is: a deployed stack and its template, outputs and parameters, and the deployed templates of its nested stacks.

Deploy, diff, drift, destroy and rollback all look stacks up through it, which is why it isn't part of a deploy package. It reads templates with internal/cfntemplate, so a deployed template, YAML or JSON, has the values upstream's parser gives.

Stabilize, WaitForDeploy and WaitForDelete wait for an operation on a stack to finish, as upstream's stabilizeStack and its callers do. Upstream waits as long as CloudFormation takes; here the caller's context bounds the wait, and a cancelled wait's error wraps the context's, not cdkerr.KindAborted, which means a declined confirmation (G.3-D1).

BodyParameter decides how a deployment passes a stack's template to CloudFormation, as upstream's makeBodyParameter does: by URL when the assembly published it, inline as YAML when it is small enough, and otherwise uploaded to the bootstrap bucket through the deployment's asset manifest. The bootstrap stack and the asset manifest come in through small interfaces, which deploy provides (F.3-D3). ResourceIdentifierSummaries reads the import identifiers of a template body's resource types, for orphaning's import mapping and G.13's import (M.5-D8).

The CloudFormation client is an interface of the few operations used, which *cloudformation.Client satisfies, so tests run real SDK clients against internal/awsfake.

Index

Constants

View Source
const DefaultPollingInterval = 5 * time.Second

DefaultPollingInterval is how long Stabilize waits between reads of a stack's status when its options don't say.

View Source
const EndpointForCloudFormationEnv = "AWS_ENDPOINT_URL_S3_FOR_CLOUDFORMATION"

EndpointForCloudFormationEnv names the environment variable that sets the S3 endpoint RestURL writes into a template URL, for a CloudFormation that needs one other than AWS's, such as LocalStack's. It is one of the process globals the library reads (F.3-D4).

View Source
const LargeTemplateSize = 50 * 1024

LargeTemplateSize is the size, in bytes, of the largest template BodyParameter passes as a body; a larger one is uploaded to S3 and passed by URL. It is CloudFormation's limit for TemplateBody.

View Source
const StatusNotFound = "NOT_FOUND"

StatusNotFound is the Name of the status of a stack that doesn't exist.

Variables

This section is empty.

Functions

func LoadNested

func LoadNested(ctx context.Context, cfn CloudFormation, stack *cloudassembly.Stack, generated *cfntemplate.Object) (map[string]NestedStack, error)

LoadNested returns the deployed and synthesized templates of every CDK-managed nested stack in generated, the template stack deploys, at every depth, as LoadWithNestedStacks finds them, for a caller that has read the root's deployed template already.

func LoadWithNestedStacks

func LoadWithNestedStacks(ctx context.Context, cfn CloudFormation, stack *cloudassembly.Stack, processed bool) (*cfntemplate.Object, map[string]NestedStack, error)

LoadWithNestedStacks returns the deployed template of stack and of every CDK-managed nested stack in it, at every depth, beside their synthesized templates: upstream's loadCurrentTemplateWithNestedStacks.

A CDK-managed nested stack is a resource of type AWS::CloudFormation::Stack in a synthesized template whose metadata names its template in the assembly, as "aws:asset:path". The deployed nested stack is found among its parent's deployed resources by its logical ID, and its name is taken from the middle of its ARN, because CloudFormation adds a suffix to it that the toolkit can't compute. A nested stack that isn't deployed, or whose parent isn't, has an empty deployed template.

When processed is set, the root stack's template is the one after CloudFormation processed its transforms; nested stacks' templates are always the original ones, as upstream reads them.

func ResourceIdentifierSummaries

func ResourceIdentifierSummaries(ctx context.Context, cfn TemplateSummarizer, io *iohelper.Helper, body TemplateBody) ([]types.ResourceIdentifierSummary, error)

ResourceIdentifierSummaries returns the import identifiers of the resource types of the template body passes, from GetTemplateSummary: the call that ends upstream's resourceIdentifierSummaries, which orphaning's import mapping and G.13's import share (M.5-D8). A response without them sends a debug message, as upstream's does, and returns none.

func RestURL

func RestURL(u string, env cloudassembly.Environment) (string, error)

RestURL returns the URL of a template published to S3, as CloudFormation takes it: upstream's restUrlFromManifest.

The account and region placeholders in u are replaced with env's. An s3://bucket/key URL becomes https://<S3 endpoint for env's region>/bucket/key, in the region's partition, and any other URL is returned as it is.

The endpoint is AWS's, from the SDK's endpoint rules, even when AWS_ENDPOINT_URL_S3 sets another, because CloudFormation is unlikely to reach it. EndpointForCloudFormationEnv sets the endpoint instead, for a CloudFormation that can.

Upstream means to ignore every configured endpoint, as its comment says, but it sets aside only AWS_ENDPOINT_URL_S3, so the JavaScript SDK still applies AWS_ENDPOINT_URL and the profile's endpoint_url. This ignores those too.

A partition placeholder isn't supported, and fails with a cdkerr.KindToolkit error with code "PartitionPlaceholderNotSupported".

Types

type AssetManifest

type AssetManifest interface {
	// AddFileAsset adds a file asset to publish to one destination, with the given ID.
	// The source's path is relative to the assembly directory.
	AddFileAsset(id string, source cloudassembly.FileSource, destination cloudassembly.FileDestination)
}

AssetManifest is the manifest of the assets a deployment publishes before it creates its change set: upstream's AssetManifestBuilder.

type CloudFormation

CloudFormation is the part of the CloudFormation API the package uses.

type NestedStack

type NestedStack struct {
	// PhysicalName is the deployed nested stack's name, or empty when it isn't deployed.
	PhysicalName string

	// Deployed is the deployed template, empty when the nested stack isn't deployed.
	Deployed *cfntemplate.Object

	// Generated is the synthesized template, from the cloud assembly.
	Generated *cfntemplate.Object

	// Nested are the nested stacks in this one, by logical ID.
	Nested map[string]NestedStack
}

NestedStack is a CDK-managed nested stack: its deployed template beside its synthesized one, and its own nested stacks, by logical ID.

type RollbackChoice

type RollbackChoice int

RollbackChoice is how a stack can be rolled back from its status: upstream's RollbackChoice.

const (
	// RollbackNone means the stack's status calls for no rollback.
	RollbackNone RollbackChoice = iota

	// RollbackStart means a rollback can be started, with RollbackStack.
	RollbackStart

	// RollbackContinueUpdate means a failed update rollback can be continued, with ContinueUpdateRollback.
	RollbackContinueUpdate

	// RollbackFailed means the stack's creation and its rollback both failed; it can't be recovered other than by recreating it.
	RollbackFailed
)

type StabilizeOptions

type StabilizeOptions struct {
	// PollingInterval is how long to wait between reads of the stack's status; zero means DefaultPollingInterval.
	PollingInterval time.Duration

	// ChangeSetExecuted says a change set has been executed against the stack.
	// REVIEW_IN_PROGRESS is a status the stack should then have left, so reading it back means DescribeStacks served a status from before the execution, and Stabilize keeps waiting rather than fail a deployment that is still running.
	ChangeSetExecuted bool

	// LeftStatus is the status the stack had when an operation was started on it, such as UPDATE_FAILED for a rollback (G.7-D2).
	// Read back before any operation has been seen in progress, it may be a status from before the operation, so it is believed only after three more reads.
	// Read after an operation was in progress, it is the operation's outcome, as when a continued rollback fails again, and is believed at once.
	LeftStatus string
}

StabilizeOptions are the options for Stabilize.

type Stack

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

Stack is a stack as CloudFormation describes it, or one that doesn't exist: upstream's CloudFormationStack. It reads its template once, when first asked for it.

func DoesNotExist

func DoesNotExist(cfn CloudFormation, name string) *Stack

DoesNotExist returns the named stack as one that doesn't exist, without asking CloudFormation, as after it was deleted: upstream's CloudFormationStack.doesNotExist.

func Lookup

func Lookup(ctx context.Context, cfn CloudFormation, name string, processed bool) (*Stack, error)

Lookup describes the named stack. A stack that doesn't exist isn't an error: the result's Exists is false. When processed is set, Template returns the template after CloudFormation has processed its transforms, rather than the original.

func Stabilize

func Stabilize(ctx context.Context, io *iohelper.Helper, cfn CloudFormation, nameOrARN string, opts StabilizeOptions) (*Stack, error)

Stabilize waits until no operation is in progress on the named stack, and returns it, or nil when the stack doesn't exist or has been deleted: upstream's stabilizeStack.

After its first read it asks for the stack by its ARN, so that a stack another operation creates under the same name isn't mistaken for it. A stack that is REVIEW_IN_PROGRESS is stable, unless opts.ChangeSetExecuted says it should have left that status: then the read is stale once an operation has been seen in progress, and before that it is believed after three more reads, because nothing moves an unexecuted change set on its own.

It waits as long as CloudFormation takes, as upstream does; ctx bounds the wait, and when ctx is done it returns an error that wraps ctx's error and names the stack and the last status read, since the operation goes on in CloudFormation (G.10-D1).

func WaitForDelete

func WaitForDelete(ctx context.Context, io *iohelper.Helper, cfn CloudFormation, nameOrARN string, interval time.Duration) (*Stack, error)

WaitForDelete waits for the named stack after its deletion was requested, and returns nil once it is deleted or doesn't exist, or the stack when it stabilized without being deleted: upstream's waitForStackDelete.

It fails with a cdkerr.Error of Code "StackDeleteFailed" when the stack is in a failed state.

func WaitForDeploy

func WaitForDeploy(ctx context.Context, io *iohelper.Helper, cfn CloudFormation, nameOrARN string, interval time.Duration) (*Stack, error)

WaitForDeploy waits for the named stack after a change set or a create or update was executed, and returns it, or nil when it doesn't exist or has been deleted: upstream's waitForStackDeploy.

It fails with a cdkerr.Error of Kind cdkerr.KindDeployment when the deployment didn't succeed: DeploymentCode "StackCreationFailed" when the stack's creation failed, and "StackDeployFailed" otherwise. The error names the stack, not its ARN.

func (*Stack) DeploymentMode

func (s *Stack) DeploymentMode() types.DeploymentConfigMode

DeploymentMode returns how CloudFormation ran the stack's most recent operation, EXPRESS or STANDARD, or "" when the stack doesn't exist or CloudFormation doesn't say: upstream's deploymentMode. It doesn't say whether a restriction from that operation is still in force.

func (*Stack) Exists

func (s *Stack) Exists() bool

Exists reports whether the stack exists.

func (*Stack) Name

func (s *Stack) Name() string

Name returns the name the stack was looked up by.

func (*Stack) NotificationARNs

func (s *Stack) NotificationARNs() []string

NotificationARNs returns the ARNs of the SNS topics that receive the stack's events, or none when the stack doesn't exist.

func (*Stack) Outputs

func (s *Stack) Outputs() map[string]string

Outputs returns the stack's outputs by key, or none when the stack doesn't exist.

func (*Stack) ParameterNames

func (s *Stack) ParameterNames() []string

ParameterNames returns the names of the stack's parameters, in the order CloudFormation lists them, or none when the stack doesn't exist.

func (*Stack) Parameters

func (s *Stack) Parameters() map[string]string

Parameters returns the stack's parameter values by name, taking a parameter's resolved value when it has one, as for an SSM parameter; or none when the stack doesn't exist.

func (*Stack) StackID

func (s *Stack) StackID() (string, error)

StackID returns the stack's ID, which is its ARN. It fails with a cdkerr.Error of Code "StackNotFound" when the stack doesn't exist.

func (*Stack) Status

func (s *Stack) Status() StackStatus

Status returns the stack's status, or one named StatusNotFound when the stack doesn't exist.

func (*Stack) Tags

func (s *Stack) Tags() []types.Tag

Tags returns the stack's tags, or none when the stack doesn't exist.

func (*Stack) Template

func (s *Stack) Template(ctx context.Context) (*cfntemplate.Object, error)

Template returns the stack's deployed template, or an empty one when the stack doesn't exist, has no template, or is REVIEW_IN_PROGRESS: a shell a change set created, which has never been deployed. It calls GetTemplate the first time, except for a stack that doesn't exist or is REVIEW_IN_PROGRESS, and returns the same template after that. Upstream calls GetTemplate on a REVIEW_IN_PROGRESS stack too, though its own comment says such a stack has no template.

func (*Stack) TerminationProtection

func (s *Stack) TerminationProtection() *bool

TerminationProtection returns whether the stack has termination protection, or nil when the stack doesn't exist or CloudFormation doesn't say.

type StackStatus

type StackStatus struct {
	// Name is the status, such as "UPDATE_COMPLETE", or "NOT_FOUND" for a stack that doesn't exist.
	Name string

	// Reason is CloudFormation's reason for the status, if any.
	Reason string
}

StackStatus is a stack's status and the reason CloudFormation gives for it: upstream's StackStatus.

func (StackStatus) IsCreationFailure

func (s StackStatus) IsCreationFailure() bool

IsCreationFailure reports whether the stack's creation failed and was rolled back, or failed to roll back.

func (StackStatus) IsDeleted

func (s StackStatus) IsDeleted() bool

IsDeleted reports whether the stack is being, or has been, deleted, successfully or not.

func (StackStatus) IsDeploySuccess

func (s StackStatus) IsDeploySuccess() bool

IsDeploySuccess reports whether the stack's last create, update or import succeeded.

func (StackStatus) IsFailure

func (s StackStatus) IsFailure() bool

IsFailure reports whether the stack's last operation failed.

func (StackStatus) IsInProgress

func (s StackStatus) IsInProgress() bool

IsInProgress reports whether an operation on the stack is in progress; REVIEW_IN_PROGRESS, a created change set not yet executed, isn't.

func (StackStatus) IsNotFound

func (s StackStatus) IsNotFound() bool

IsNotFound reports whether the stack doesn't exist.

func (StackStatus) IsReviewInProgress

func (s StackStatus) IsReviewInProgress() bool

IsReviewInProgress reports whether the stack is REVIEW_IN_PROGRESS: created by a change set that hasn't been executed.

func (StackStatus) IsRollbackSuccess

func (s StackStatus) IsRollbackSuccess() bool

IsRollbackSuccess reports whether the stack's last rollback succeeded.

func (StackStatus) IsRollbackable

func (s StackStatus) IsRollbackable() bool

IsRollbackable reports whether the stack can be rolled back from its status: whether its RollbackChoice is RollbackStart or RollbackContinueUpdate.

func (StackStatus) RollbackChoice

func (s StackStatus) RollbackChoice() RollbackChoice

RollbackChoice returns how the stack can be rolled back from its status, as after a deployment with rollback disabled.

func (StackStatus) String

func (s StackStatus) String() string

String returns the status, followed by its reason in parentheses when there is one.

type TemplateBody

type TemplateBody struct {
	Body string
	URL  string
}

TemplateBody is how a template is passed to CloudFormation: as the template itself, Body, or as the URL of its copy in S3, URL. Exactly one is set. It is upstream's TemplateBodyParameter.

func BodyParameter

func BodyParameter(ctx context.Context, io *iohelper.Helper, stack *cloudassembly.Stack, env cloudassembly.Environment, manifest AssetManifest, toolkit func(context.Context) (ToolkitInfo, error), override *cfntemplate.Object) (TemplateBody, error)

BodyParameter returns how to pass the stack's template to CloudFormation: upstream's makeBodyParameter.

  • A template the assembly has already published, the stack's StackTemplateAssetObjectURL, is passed by its URL, from RestURL, unless override is set.
  • Otherwise the template, or override when it is set, is written as YAML, as upstream's toYAML writes it, and passed as the body when it is at most LargeTemplateSize bytes.
  • A larger template is added to manifest, to be uploaded to the bootstrap stack's staging bucket with the key cdk/<stack artifact ID>/<SHA-256 of the YAML>.yml, as the CLI uploads it, and passed by its URL in the bucket. It is published with the role and region of the stack's own template asset, if the assembly publishes one. An override is first written to the assembly directory, beside the stack's template, as <template file>-<SHA-256>.yaml, so that the manifest can name it.

toolkit looks up the environment's bootstrap stack; it is called only for a template too large to pass as a body. When the environment isn't bootstrapped, BodyParameter sends an error message saying to bootstrap it and fails with a cdkerr.KindToolkit error with code "TemplateTooLargeToDeploy". It fails with code "PartitionPlaceholderNotSupported" as RestURL does.

Upstream compares the length of the YAML in UTF-16 code units with the limit, so a template with enough characters outside ASCII passes as a body and CloudFormation then rejects it. This measures bytes, as CloudFormation does (F.3-D2).

type TemplateSummarizer

type TemplateSummarizer interface {
	GetTemplateSummary(ctx context.Context, in *cloudformation.GetTemplateSummaryInput, opts ...func(*cloudformation.Options)) (*cloudformation.GetTemplateSummaryOutput, error)
}

TemplateSummarizer is the CloudFormation operation ResourceIdentifierSummaries calls, which *cloudformation.Client satisfies.

type ToolkitInfo

type ToolkitInfo interface {
	// Found reports whether the environment is bootstrapped.
	Found() bool

	// BucketName returns the name of the bootstrap stack's staging bucket.
	BucketName() (string, error)

	// BucketURL returns the staging bucket's URL.
	BucketURL() (string, error)
}

ToolkitInfo is the bootstrap stack of an environment, which BodyParameter uploads large templates to. *bootstrap.ToolkitInfo satisfies it.

Jump to

Keyboard shortcuts

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