-
Notifications
You must be signed in to change notification settings - Fork 71
Description
Is your feature request related to a problem? Please describe.
When creating a shared resource such as a KV Store or Config Store, developers must manually run a separate fastly resource-link create command to attach the resource to a service version.
This requires looking up the resource ID and repeatedly issuing commands, for example:
% fastly kv-store create --name="my-kv-store"
SUCCESS: Created KV Store 'my-kv-store' (xxxxxxxxxxxxxxxx123456)
% fastly resource-link create --resource-id=xxxxxxxxxxxxxxxx123456 \
--service-id=xxyyzzXXYYZZabcd123456 --name="my-kv-store" --version=latest --autoclone
SUCCESS: Created service resource link "my-kv-store" (xxxxxxxxxxxxxxxx7890ab) on service xxyyzzXXYYZZabcd123456 version 1
This approach is explicit, but feels unnecessarily cumbersome for common workflows.
Describe the solution you'd like
Augment fastly kv-store create (and config-store, etc.) with an optional flag --create-link to automatically link the newly created resource to a specified service/version.
e.g.:
fastly kv-store create --name=my-kv-store --create-link --link-name=my-kv-store --version=latest --autoclone
When --create-link is provided, the CLI would, after creating the resource, immediately link it by invoking the Resources API.
--link-name would serve to specify the name to give to the resource link, equivalent to the --name parameter in fastly resource-link create.
While fastly kv-store create typically requires only the resource name (created in the account associated with the API token), this mode would require identifying a target service (from fastly.toml or via --service-id) and version (--version=latest, etc.), with flags such as --autoclone also applying.
Although this technically extends the “one command = one API call” principle, this shouldn’t be problematic: there is precedent for multi-call commands (e.g. the --autoclone mechanism).
As an additional enhancement, a flag such as --if-exist-create-link could optionally create only the link if a resource with that name already exists. This would make the command idempotent and safer to reuse across multiple projects within the same account.
Describe alternatives you've considered
A simpler alternative would be to expand fastly resource-link with --resource-type and --resource-name flags.
This still requires a separate linking step but removes the need to manually look up resource IDs, allowing the CLI to resolve them automatically (e.g. by internally calling kv-store list).
e.g.:
fastly resource-link create --resource-type="kv-store" --resource-name="my-kv-store" --service-id=xxyyzzXXYYZZabcd123456 --name="my-kv-store" --version=latest --autoclone
Additional context
The [setup] section of fastly.toml already performs similar logic on an application’s first deploy, so some of this functionality likely exists in the CLI (or API stack?) today.