Add resource teardown, CLI validation, and idempotent provisioning#6
Draft
Copilot wants to merge 3 commits intocopilot/add-cloud-resource-provisioningfrom
Draft
Conversation
Co-authored-by: Karthik777 <7102951+Karthik777@users.noreply.github.com>
Co-authored-by: Karthik777 <7102951+Karthik777@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add error handling and resource teardown features for resources.py
Add resource teardown, CLI validation, and idempotent provisioning
Feb 25, 2026
This was referenced Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds production safety features: CLI validation before cloud API calls, idempotent provisioning (no crash on already-exists), and resource teardown functions to prevent cloud bill accumulation.
New Module:
fastops/teardown.py(362 lines)destroy(resource_type, name, provider, **kw)- Destroy individual resourcesdestroy_stack(resources, provider, **kw)- Bulk teardown in reverse dependency orderstatus(resource_type, name, provider, **kw)- Resource health checks_infer_resource_type(env_dict)- Infer resource type from environment variablesAll teardown operations are idempotent and return structured responses instead of raising on not-found.
Updates:
fastops/resources.pyCLI Validation:
_check_cli(cli_name)validates CLI presence before API calls with actionable error messagesaws), Azure (az), and GCP (gcloud) provider branchesIdempotent Provisioning:
DBInstanceAlreadyExists,CacheClusterAlreadyExists,BucketAlreadyOwnedByYou,ResourceAlreadyExistsException,ResourceConflictException→ describes existing resourceResourceAlreadyExistsand text-based "already exists" patterns → shows existing resource--quietflags, catches "already exists" in stderrUsage
Coverage
All 7 resource types (database, cache, queue, bucket, llm, search, function) × all providers (Docker, AWS, Azure, GCP, OpenAI).
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
metadata.google.internal/usr/bin/../lib/google-cloud-sdk/platform/bundledpythonunix/bin/python3 /usr/bin/../lib/google-cloud-sdk/platform/bundledpythonunix/bin/python3 /usr/bin/../lib/google-cloud-sdk/lib/gcloud.py pubsub topics create testqueue --quiet(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
P1: Error handling, idempotency, and resource teardown for fastops/resources.py
This PR adds production-critical safety features to
resources.py: proper error handling so CLI-not-installed and resource-already-exists don't crash, idempotent provisioning, anddestroy()functions so users don't accumulate cloud bills.Branch off
copilot/add-cloud-resource-provisioning.Part 1: New file
fastops/teardown.pyModule docstring
"""Resource teardown and lifecycle management. Safely destroy provisioned resources."""__all__['destroy', 'destroy_stack', 'status']Imports
import os, json, subprocess, shutilFunction:
destroy(resource_type, name, provider='docker', **kw)Destroy a single provisioned resource.
resource_typeis one of:'database','cache','queue','bucket','llm','search','function'.Dispatches to
_destroy_{resource_type}(name, provider, **kw).Each destroyer should:
{'destroyed': True/False, 'resource': name, 'provider': provider, 'message': str}_destroy_database(name, provider, **kw)Docker: No-op for compose-managed resources (handled by
docker compose down -v). Return{'destroyed': True, 'message': 'Remove via docker compose down -v'}.AWS:
Azure:
_destroy_cache(name, provider, **kw)callaws('elasticache', 'delete-cache-cluster', '--cache-cluster-id', name)callaz('redis', 'delete', '--name', name, '--resource-group', rg, '--yes')_destroy_queue(name, provider, **kw)callaws('sqs', 'get-queue-url', '--queue-name', name), thencallaws('sqs', 'delete-queue', '--queue-url', url)callaz('servicebus', 'namespace', 'delete', '--name', kw.get('namespace', f'{name}-ns'), '--resource-group', rg, '--yes')subprocess.run(['gcloud', 'pubsub', 'topics', 'delete', name, '--quiet'])and delete subscriptionf'{name}-sub'_destroy_bucket(name, provider, **kw)callaws('s3', 'rm', f's3://{name}', '--recursive'), thencallaws('s3api', 'delete-bucket', '--bucket', name)callaz('storage', 'container', 'delete', '--name', name, '--account-name', account_name, '--yes'), thencallaz('storage', 'account', 'delete', '--name', account_name, '--resource-group', rg, '--yes')subprocess.run(['gcloud', 'storage', 'rm', '-r', f'gs://{name}', '--quiet'])_destroy_llm(name, provider, **kw)callaz('cognitiveservices', 'account', 'deployment', 'delete', ...)thencallaz('cognitiveservices', 'account', 'delete', ...)_destroy_search(name, provider, **kw)callaws('opensearch', 'delete-domain', '--domain-name', name)callaz('search', 'service', 'delete', '--name', name, '--resource-group', rg, '--yes')_destroy_function(name, provider, **kw)callaws('lambda', 'delete-function', '--function-name', name)callaz('functionapp', 'delete', '--name', name, '--resource-group', rg, '--yes')subprocess.run(['gcloud', 'functions', 'delete', name, '--quiet', '--region', kw.get('region', 'us-central1')])Function:
destroy_stack(resources, provider='docker', **kw)Takes the same
resourcesdict format asstack()in resources.py. Tears down all resources in reverse order.