Attach a resource to an app
attach_resourceAttach a resource to an app: a named set of environment variables, such as a database's connection string, that the app reads as secrets. Name the resource. When the organization has none by that name, pass a provider from list_catalog_resources and the first call creates it, returning at once with state provisioning. Call again with the same arguments, env_prefix included, until the state is attached: the call that finds the resource ready attaches it and sets its variables, then asks for a restart if the app is running. The state is attaching while Valet still owes the restart or the variables, and conflicted when a name the resource sets is already set on the app; the answer gives the reason. An existing resource attaches by name alone, including one another app holds. The call is safe to repeat: one name is one resource however many times it is called, and an app can hold several under different names. Pass env_prefix when two resources would set the same variables. Pass vars to set the app's own variables in the same restart, such as settings the app needs beside the database: they are set on the call that attaches, never while the resource provisions or once it is attached, so repeat them on every call. A value given here passes through this conversation; say the user could enter it on the dashboard instead. Read the names an attachment sets from list_catalog_resources before writing the app's code. A new database is empty, so the app creates its own tables, and its URL carries the TLS settings it needs. The app must exist, so publish it first. The running process does not see the variables until the restart completes; get_service shows the attachment's status and when the new process is running. Provisioning takes about a minute; call again every ten seconds. Values are never returned here. Requires connecting a Valet account.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Required. The app's name. | |
| plan | No | The provider's plan. Omit to use its first plan. Repeat it on every call for one resource. | |
| vars | No | The app's own variables to set in the restart the attach requests, as name to value. They are set on the call that attaches. Leave out the names the resource sets. | |
| secret | No | Whether vars are stored as secrets, which are encrypted and never shown again. Omit for true; pass false for plain configuration, readable from the dashboard. | |
| org_name | No | The Valet organization the app belongs to. Omit to use the organization the account joined first. | |
| provider | No | The provider to create the resource from, from list_catalog_resources. Required when the organization has no resource by this name. | |
| resource | Yes | Required. The resource's name in the organization, such as shop-db: 3 to 63 lowercase letters, digits, and hyphens. Repeat it on every call for one resource. | |
| env_prefix | No | Set the resource's variables under PREFIX_NAME rather than NAME: an uppercase letter, then up to 31 uppercase letters, digits, and underscores. Omit to use the names as they are. Repeat it on every call for one resource: it applies on the call that attaches. |