Concepts
Resources
Overview
Resources are any cloud resource that you want to manage with LaunchFlow. They can be anything from a Postgres Database to a Cloud Storage Bucket. LaunchFlow creates your resources in an environment and is only responsible for creating and destroying the resources. Once created you are free to update the resource however you like. Such as click-ops in the cloud console or using the cloud provider's CLI.
Creating Resources
CLI
We recommend the CLI approach if you are using LaunchFlow resources as part of backend system such as a web server.
First define your resources in a python file:
1import launchflow as lf
2
3bucket = lf.gcp.GCSBucket("my-bucket")
Next run the following command from the root of your project to create the resources:
1launchflow create
This will scan your current directory to find any resources that need to create (or replaced) This will prompt you to select a project and environment to create the resource in. You can also specify the project and environment with the --project
and --environment
flags.
You can also target specific resources if you only want to create an individual resource. For example if in main.py
you had one bucket you wanted to create you could run the following:
1launchflow create main:bucket
In Python Code
You can also use pure python if you don't want to use the CLI. We recommend this approach for things like scripts or notebooks.
To do this we wrap our resource definitions in the allow context manager. This will allow the resource to be created when you first run this block of code. Without this when you instantiate the bucket it would fail to connect since the resource does not yet exist.
Next we call create with a project and environment to create the resources.
1import launchflow as lf
2
3bucket = lf.gcp.GCSBucket("my-bucket")
4
5bucket.create(project_name="project", resource_name="env")
6bucket.connect()
Deleting Resources
This will delete your service from LaunchFlow and turn down all cloud infrastructure associated with it. To delete an individual resource run:
1launchflow resources delete \
2 --project <project-name> \
3 --environment <environment-name> \
4 <resource-name>
LaunchFlow can also automatically clean up unused resources that were previously part of your environment but are no longer used. To do this you can use launchflow clean
. This takes in a list of active resources in your environment and will prompt you to delete any resources that are not in the list but are part of your environment. This is the opposite of launchflow create
.
1launchflow clean
This will scan your directory to find all active resources and prompt to delete any resources that are not in the list but are part of your environment.
Listing Resources
1launchflow resources list