import
CLI command to download all your UI-managed resources as code and start managing your entire Checkly setup from the CLI.
How import
works
When importing an existing resource the CLI will both generate the code neccessary to manage the resource through code, and mark the resource itself as managed by the CLI, and not the UI. This allows you to start editing, and also deleting the resource through the CLI.
To ensure that you can go through this process safely, and test your setup along the way the import process is done in three separate steps: Plan, apply and commit.
npx checkly import
: This generates the code for all resources in your account not already managed through the CLI, allowing for a review of all resources that will be imported. At this point no mapping have been created between imported resources and the existing ones in your account. Adeploy
in this state will duplicate your UI-managed resources as CLI-managed ones. If you cancel here, nothing will change for existing resources that are managed through the UI on your account.npx checkly import apply
: Links the imported resources to your CLI project, but keeps the mapping in a pending state. You can now make changes to resources in your account via the CLI, as the mapping has been established. As long as this mapping is pending you cannot delete any of the imported resources via the CLI. You are free to test your setup and deploy changes, but you will be prevented from deleting any resources until you commit your plan. You can cancel your import at this stage, but any changes made to resources through adeploy
will persist.npx checkly import commit
: Commits the plan, removing the pending state from all imported resources. Imported resources can now be deleted through the CLI by removing their constructs. At this point theimport
is completed and cannot be canceled.
Importing step-by-step
1
Install the CLI
Install the CLI. At the end of the process ensure you have a
checkly.config.ts/js
file, and that you have logged in to the account you want to import resources from. You can verify the current account with npx checkly whoami
. If you already have installed the CLI but don’t have a Checkly config file, one will be created for you as part of the import process.2
Import resources
Run
npx checkly import
and select import everything
to import all resources from your account. You can also import individual resources. You can specify where the generated code should be placed using --root
. If your Checkly config file is not in the current directory, specify the path using --config
.3
Review imported code
Review the imported code before continuing. You can verify imported checks with
npx checkly test
. At this point, avoid running npx checkly deploy
as this will duplicate your UI-managed resources as CLI-managed ones.4
Apply the import
Run
npx checkly import apply
to create the link between the imported resources and your CLI project. You can try out editing resources and pushing these updates to your account with npx checkly deploy
.5
Commit the import
When you are satisfied with your setup, run
npx checkly import commit
to finalize the import.npx checkly import cancel
at any point before running npx checkly import commit
, but changes made to existing resources after the apply-stage will persist after cancelling.
Importing individual resources
There are two ways to import individual resources:- Run
npx checkly import
and in the first step selectLet me choose resources manually
. In the following menu usespace
to select/deselect resources for import andreturn
to finalize your selection. From there, follow steps 3 - 5 in the Importing step-by-step guide. - Specify a single resource as part of the
import
command with the following syntax:npx checkly import resource-type:resource-id
.
Using export
when creating CLI resources
The import process will automatically export
resouces to make them available in other constructs. It is recommended to also export manually created resources so that future import processes can take advantage of the same process.
Here is an example of an exported alert channel:
Alert-Channel.check.ts
import
and refer to it directly in the alertChannels
section:
Alert-Channel.check.ts
export
is not used, the CLI code generation will still reference the correct resources when generating code, but will use fromId
instead.