Skip to content

Commit b15157f

Browse files
committed
handle situation with not enough credits [EC-899]
1 parent 057b89f commit b15157f

2 files changed

Lines changed: 41 additions & 12 deletions

File tree

skills/aiven-kafka-setup-avn/SKILL.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ Verify the following are installed:
6565
- For Java: `java` (17+), `mvn`
6666
- For Python: `python3` (3.9+), `pip`
6767

68+
Before creating a service, ask the customer to confirm they have enough credits (they can check with):
69+
70+
```bash
71+
avn project details --json
72+
```
73+
74+
Use the AskQuestion tool to collect this confirmation without interrupting the flow.
75+
76+
**AI Agent MUST NOT check credits itself.** Only the customer should run the credit-check command and confirm.
77+
6878
**Missing Requirements Policy:**
6979
- If a library or CLI tool (like `avn`) is missing, advise the user on how to install it (e.g., `python3 -m pip install aiven-client` for `avn`). However, check first if `python3` is available before suggesting a `pip` command.
7080
- If a core language runtime (`python3` or `java`) is requested but missing, **interrupt the flow immediately**. Do NOT advise the user on how to install programming languages.
@@ -75,12 +85,17 @@ Verify the following are installed:
7585

7686
Follow **[SERVICE_CREATION_AVN.md](SERVICE_CREATION_AVN.md)** sections 1–4 in order:
7787

78-
1. **Choose a region** — ask the user with AskQuestion, mapping their choice to the **EXACT** `CLOUD_NAME` from the table in **[SERVICE_CREATION_AVN.md](SERVICE_CREATION_AVN.md)**.
79-
2. **Choose a plan** — default `startup-4`; **never** use `free-0` or `startup-2`.
80-
3. **Run the setup script** — a single command creates the service, tags it with
88+
1. **Choose a service name (if missing)** — if the customer did not provide a service name, use AskQuestion with:
89+
- `aiven-kafka-service-test`
90+
- `Other` (if selected, ask the customer to provide their custom service name)
91+
2. **Choose a region** — ask the user with AskQuestion, mapping their choice to the **EXACT** `CLOUD_NAME` from the table in **[SERVICE_CREATION_AVN.md](SERVICE_CREATION_AVN.md)**.
92+
3. **Choose a plan** — default `startup-4`; **never** use `free-0` or `startup-2`.
93+
4. **Run the setup script** — a single command creates the service, tags it with
8194
`AI-skill-generated=true`, creates users and ACLs, registers the schema,
8295
extracts all connection details, and writes them to `env.sh`.
83-
4. **Source `env.sh`** — loads `KAFKA_HOST`, `KAFKA_PORT`, `SCHEMA_REGISTRY_URL`,
96+
- If service creation returns `Payment method is not set and there is not enough credits for the service`,
97+
the script fails fast and the flow must stop immediately.
98+
5. **Source `env.sh`** — loads `KAFKA_HOST`, `KAFKA_PORT`, `SCHEMA_REGISTRY_URL`,
8499
`AVNADMIN_PASS`, `PRODUCER_PASSWORD`, `CONSUMER_PASSWORD` into the shell.
85100

86101
```bash

skills/aiven-kafka-setup-avn/scripts/setup_aiven_kafka.sh

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CLOUD_NAME="${2:?Usage: $0 <service-name> <cloud-name> [plan] [kafka-version]}"
2121
PLAN="${3:-startup-4}"
2222
KAFKA_VERSION="${4:-4.1}"
2323
TOPIC="orders"
24+
BILLING_ERROR_MSG="Payment method is not set and there is not enough credits for the service"
2425

2526
echo "==> Checking avn login..."
2627
set +e
@@ -48,14 +49,27 @@ fi
4849

4950
echo "==> Creating Kafka service: $KAFKA_SERVICE (cloud=$CLOUD_NAME, plan=$PLAN, kafka=$KAFKA_VERSION)"
5051
if ! avn service get "$KAFKA_SERVICE" >/dev/null 2>&1; then
51-
avn service create "$KAFKA_SERVICE" \
52-
--service-type kafka \
53-
--cloud "$CLOUD_NAME" \
54-
--plan "$PLAN" \
55-
--no-project-vpc \
56-
-c kafka_version="$KAFKA_VERSION" \
57-
-c kafka_authentication_methods.sasl=true \
58-
-c schema_registry=true
52+
set +e
53+
SERVICE_CREATE_OUTPUT=$(
54+
avn service create "$KAFKA_SERVICE" \
55+
--service-type kafka \
56+
--cloud "$CLOUD_NAME" \
57+
--plan "$PLAN" \
58+
--no-project-vpc \
59+
-c kafka_version="$KAFKA_VERSION" \
60+
-c kafka_authentication_methods.sasl=true \
61+
-c schema_registry=true 2>&1
62+
)
63+
SERVICE_CREATE_EXIT=$?
64+
set -e
65+
66+
if [ "$SERVICE_CREATE_EXIT" -ne 0 ]; then
67+
printf '%s\n' "$SERVICE_CREATE_OUTPUT" >&2
68+
if [[ "$SERVICE_CREATE_OUTPUT" == *"$BILLING_ERROR_MSG"* ]]; then
69+
echo "ERROR: Service creation stopped immediately due to insufficient credits and missing payment method." >&2
70+
fi
71+
exit 1
72+
fi
5973
fi
6074

6175
echo "==> Waiting for service to be RUNNING..."

0 commit comments

Comments
 (0)