Advanced

Cloud Resource Protection Mechanisms

Cloud providers offer native protection mechanisms that prevent resource deletion regardless of the caller's IAM permissions. These are your last line of defense when an AI agent has the permissions to delete but the resource itself refuses to be destroyed.

AWS Resource Protection

EC2 Termination Protection

When enabled, any API call to terminate-instances will fail, forcing the caller to first disable protection:

AWS - Enable EC2 termination protection
# Enable termination protection on existing instances
aws ec2 modify-instance-attribute \
  --instance-id i-0abc123def456 \
  --disable-api-termination

# Enable at launch time via Terraform
resource "aws_instance" "production" {
  ami                     = "ami-0abcdef1234567890"
  instance_type           = "m6i.xlarge"
  disable_api_termination = true

  tags = {
    Name        = "production-web-server"
    Environment = "production"
    Protected   = "true"
  }
}

RDS Deletion Protection

AWS - Enable RDS deletion protection
# Enable on existing database
aws rds modify-db-instance \
  --db-instance-identifier prod-database \
  --deletion-protection \
  --apply-immediately

# Terraform configuration
resource "aws_rds_instance" "production" {
  identifier          = "prod-database"
  engine              = "postgres"
  instance_class      = "db.r6g.xlarge"
  deletion_protection = true

  lifecycle {
    prevent_destroy = true
  }
}

S3 Object Lock

S3 Object Lock prevents objects from being deleted or overwritten for a specified retention period. This is critical for compliance and backup data:

AWS - S3 Object Lock configuration
# Create bucket with Object Lock enabled (must be set at creation)
aws s3api create-bucket \
  --bucket critical-backups \
  --object-lock-enabled-for-bucket

# Set default retention policy (Governance mode - admin can override)
aws s3api put-object-lock-configuration \
  --bucket critical-backups \
  --object-lock-configuration '{
    "ObjectLockEnabled": "Enabled",
    "Rule": {
      "DefaultRetention": {
        "Mode": "GOVERNANCE",
        "Days": 90
      }
    }
  }'

# Compliance mode - NOBODY can delete, not even root
# Use for regulatory requirements
aws s3api put-object-lock-configuration \
  --bucket regulatory-data \
  --object-lock-configuration '{
    "ObjectLockEnabled": "Enabled",
    "Rule": {
      "DefaultRetention": {
        "Mode": "COMPLIANCE",
        "Days": 2555
      }
    }
  }'

Azure Resource Locks

Azure provides two types of resource locks that apply at the resource, resource group, or subscription level:

Lock Type Effect Use Case
CanNotDelete Allows read and modify, blocks delete Production resources that may need updates but must never be deleted
ReadOnly Allows read only, blocks modify and delete Critical infrastructure that should never change (DNS zones, core networking)
Azure CLI - Apply resource locks
# Lock an entire resource group against deletion
az lock create \
  --name "protect-production" \
  --resource-group production-rg \
  --lock-type CanNotDelete \
  --notes "AI agent safety: prevent accidental resource group deletion"

# Lock a specific resource as read-only
az lock create \
  --name "protect-prod-db" \
  --resource-group production-rg \
  --resource-name prod-sql-server \
  --resource-type Microsoft.Sql/servers \
  --lock-type ReadOnly

# Lock at subscription level (protects everything)
az lock create \
  --name "subscription-delete-lock" \
  --lock-type CanNotDelete \
  --notes "Subscription-wide deletion protection"

GCP Resource Protection

Project Liens

Project liens prevent a GCP project from being deleted. This is the strongest protection available:

GCP - Create project liens and instance protection
# Create a lien to prevent project deletion
gcloud alpha resource-manager liens create \
  --project=production-project \
  --restrictions=resourcemanager.projects.delete \
  --reason="Production project - deletion blocked for AI agent safety"

# Enable deletion protection on a Compute Engine instance
gcloud compute instances update prod-web-server \
  --zone=us-central1-a \
  --deletion-protection

# Enable deletion protection on a Cloud SQL instance
gcloud sql instances patch prod-database \
  --deletion-protection

Cross-Cloud Tagging Strategies

Use consistent tagging across all clouds to identify which resources are protected and why:

Recommended tagging schema for AI agent safety
# Standard tags for all critical resources:
tags = {
  Environment       = "production"          # production, staging, development
  CriticalityLevel  = "high"                # high, medium, low
  DeletionProtected = "true"                # Indicates protection is enabled
  Owner             = "platform-team"       # Team responsible
  AgentAccess       = "read-only"           # What AI agents are allowed to do
  BackupRetention   = "90-days"             # How long backups are kept
  LastReviewDate    = "2026-03-15"          # When protection was last reviewed
}
Tip: Configure your AI agent wrapper scripts to check for the DeletionProtected tag before allowing any destructive operation. Even if cloud-native protection is somehow bypassed, the tag check adds another layer of defense.

Backup and Recovery as Safety Nets

Even with all protections in place, maintain backup and recovery capabilities as your ultimate safety net:

Automated Snapshots

Schedule automated EBS snapshots, RDS snapshots, Azure VM backups, and GCP persistent disk snapshots. Retain for at least 30 days with cross-region replication.

S3/Blob Versioning

Enable versioning on all storage buckets. Even if an AI agent deletes objects, previous versions are retained and recoverable.

Database Point-in-Time Recovery

Enable automated backups with point-in-time recovery on all databases. AWS RDS, Azure SQL, and Cloud SQL all support this natively.

Infrastructure State Backups

Maintain versioned copies of Terraform state files, Pulumi state, and CloudFormation templates so you can rebuild infrastructure from known-good state.

💡
Next Up: Resource protection prevents destruction, but you also need to know when an agent attempts destructive actions. The next lesson covers monitoring, alerting, and incident response for AI agent activity.

Ready to Go Deeper?

Live instructor-led courses from our partners. Affiliate disclosure.