Skip to content

Deployment

Represents a cloud deployment, exposing Python methods to manage infrastructure.

This class wraps a module or stack resource and provides methods to apply, plan, and destroy deployments. It also supports context-manager protocol for automatic cleanup.

Example

from infraweave import Deployment, S3Bucket

# Given that `S3Bucket` is a valid module in your platform
bucket_module = S3Bucket(
    version='0.0.11-dev',
    track="dev"
)

bucket1 = Deployment(
    name="bucket1",
    namespace="playground",
    module=bucket_module,
    region="us-west-2"
)
with bucket1:
    bucket1.set_variables(
        bucket_name="my-bucket12347ydfs3",
        enable_acl=False
    )
    result = bucket1.apply()
    print(f"Job ID: {result.job_id}")
    print(f"Changes: {result.changes}")
    # Run some tests here

Properties

outputs

Retrieves the outputs from the last deployment as a Python object.

Example

>>> from infraweave import Deployment
...
>>> # (assume `bucket1` has just been applied, and has terraform outputs "bucket_arn" and "tags")
...
>>> print(bucket1.outputs.bucket_arn)
'arn:aws:s3:::my-bucket12347ydfs3'
>>> print(bucket1.outputs.tags)
{'Test': 'test-tag123', 'Env': 'test'}

Returns None if no deployment has run yet.

Methods

__enter__()

Enter the context manager block (with Deployment(...) as d:).

__exit__(_exc_type, _exc_value, _traceback)

Exit the context manager, automatically destroying or cleaning up.

__new__(args, kwargs)

Create and return a new object. See help(type) for accurate signature.

apply()

Applies the deployment, creating or updating infrastructure.

Returns a DeploymentResult containing the job ID and changes on success, or raises DeploymentFailure on error.

destroy()

Destroys the deployment, tearing down infrastructure.

Returns the job ID string on success, or raises DeploymentFailure on error.

plan()

Plans the deployment, showing prospective changes without applying.

Returns a PlanResult containing the job ID and methods to analyze the plan on success, or raises DeploymentFailure on error.

set_module_version(track, version)

Sets the version for the module deployment.

Arguments

  • track - The release track (e.g., "stable", "dev") to use.
  • version - The version string to set for the module.

Errors

Returns a PyException if the deployment is a stack (not a module), or if the specified version does not exist.

Example

deployment.set_module_version("stable", "1.2.3")

set_stack_version(track, version)

Sets the version for the stack deployment.

Arguments

  • track - The release track (e.g., "stable", "dev") to use.
  • version - The version string to set for the stack.

Errors

Returns a PyException if the deployment is a module (not a stack), or if the specified version does not exist.

Example

deployment.set_stack_version("dev", "1.6.2-dev")

set_variables(kwargs)

Sets variables for the deployment using keyword arguments.

Converts Python kwargs to JSON, then merges with existing variables. This allows setting individual variables without removing existing ones.