#!/bin/bash # ═══════════════════════════════════════════════════════════════════════════ # AWS Discovery — Fas 1 # Mål: Komplett inventering utan förändring # Princip: "Importera verkligheten innan du försöker ersätta den" # ═══════════════════════════════════════════════════════════════════════════ set -e REGION="eu-north-1" OUTPUT_DIR="/home/bernt/.openclaw/workspace/terraform/discovery" TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ") echo "=== AWS Discovery påbörjad: $TIMESTAMP ===" # 1. Konton echo "--- Konton ---" aws sts get-caller-identity --output json > "$OUTPUT_DIR/account.json" 2>/dev/null || echo "{\"error\": \"no access\"}" > "$OUTPUT_DIR/account.json" # 2. Regioner echo "--- Regioner ---" aws ec2 describe-regions --output json > "$OUTPUT_DIR/regions.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/regions.json" # 3. VPC echo "--- VPC ---" aws ec2 describe-vpcs --region $REGION --output json > "$OUTPUT_DIR/vpcs.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/vpcs.json" # 4. Subnets echo "--- Subnets ---" aws ec2 describe-subnets --region $REGION --output json > "$OUTPUT_DIR/subnets.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/subnets.json" # 5. Route Tables echo "--- Route Tables ---" aws ec2 describe-route-tables --region $REGION --output json > "$OUTPUT_DIR/route-tables.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/route-tables.json" # 6. NAT Gateways echo "--- NAT Gateways ---" aws ec2 describe-nat-gateways --region $REGION --output json > "$OUTPUT_DIR/nat-gateways.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/nat-gateways.json" # 7. Internet Gateways echo "--- Internet Gateways ---" aws ec2 describe-internet-gateways --region $REGION --output json > "$OUTPUT_DIR/internet-gateways.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/internet-gateways.json" # 8. Security Groups echo "--- Security Groups ---" aws ec2 describe-security-groups --region $REGION --output json > "$OUTPUT_DIR/security-groups.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/security-groups.json" # 9. IAM echo "--- IAM Roles ---" aws iam list-roles --output json > "$OUTPUT_DIR/iam-roles.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/iam-roles.json" echo "--- IAM Policies ---" aws iam list-policies --scope Local --output json > "$OUTPUT_DIR/iam-policies.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/iam-policies.json" echo "--- IAM Users ---" aws iam list-users --output json > "$OUTPUT_DIR/iam-users.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/iam-users.json" # 10. EC2 echo "--- EC2 Instances ---" aws ec2 describe-instances --region $REGION --output json > "$OUTPUT_DIR/ec2-instances.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/ec2-instances.json" # 11. ALB/NLB echo "--- Load Balancers ---" aws elbv2 describe-load-balancers --region $REGION --output json > "$OUTPUT_DIR/load-balancers.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/load-balancers.json" echo "--- Target Groups ---" aws elbv2 describe-target-groups --region $REGION --output json > "$OUTPUT_DIR/target-groups.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/target-groups.json" # 12. Auto Scaling echo "--- Auto Scaling Groups ---" aws autoscaling describe-auto-scaling-groups --region $REGION --output json > "$OUTPUT_DIR/auto-scaling.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/auto-scaling.json" # 13. RDS echo "--- RDS Instances ---" aws rds describe-db-instances --region $REGION --output json > "$OUTPUT_DIR/rds-instances.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/rds-instances.json" echo "--- RDS Clusters ---" aws rds describe-db-clusters --region $REGION --output json > "$OUTPUT_DIR/rds-clusters.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/rds-clusters.json" # 14. ElastiCache echo "--- ElastiCache ---" aws elasticache describe-cache-clusters --region $REGION --output json > "$OUTPUT_DIR/elasticache.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/elasticache.json" # 15. S3 echo "--- S3 Buckets ---" aws s3api list-buckets --output json > "$OUTPUT_DIR/s3-buckets.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/s3-buckets.json" # 16. CloudFront echo "--- CloudFront ---" aws cloudfront list-distributions --output json > "$OUTPUT_DIR/cloudfront.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/cloudfront.json" # 17. Route53 echo "--- Route53 ---" aws route53 list-hosted-zones --output json > "$OUTPUT_DIR/route53.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/route53.json" # 18. ACM echo "--- ACM Certificates ---" aws acm list-certificates --region $REGION --output json > "$OUTPUT_DIR/acm.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/acm.json" # 19. Secrets Manager echo "--- Secrets Manager ---" aws secretsmanager list-secrets --region $REGION --output json > "$OUTPUT_DIR/secrets.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/secrets.json" # 20. CloudWatch echo "--- CloudWatch Alarms ---" aws cloudwatch describe-alarms --region $REGION --output json > "$OUTPUT_DIR/cloudwatch-alarms.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/cloudwatch-alarms.json" echo "--- CloudWatch Log Groups ---" aws logs describe-log-groups --region $REGION --output json > "$OUTPUT_DIR/cloudwatch-logs.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/cloudwatch-logs.json" # 21. EventBridge echo "--- EventBridge ---" aws events list-rules --region $REGION --output json > "$OUTPUT_DIR/eventbridge.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/eventbridge.json" # 22. Lambda echo "--- Lambda Functions ---" aws lambda list-functions --region $REGION --output json > "$OUTPUT_DIR/lambda.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/lambda.json" # 23. ECR echo "--- ECR Repositories ---" aws ecr describe-repositories --region $REGION --output json > "$OUTPUT_DIR/ecr.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/ecr.json" # 24. ECS/EKS echo "--- ECS Clusters ---" aws ecs list-clusters --region $REGION --output json > "$OUTPUT_DIR/ecs.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/ecs.json" echo "--- EKS Clusters ---" aws eks list-clusters --region $REGION --output json > "$OUTPUT_DIR/eks.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/eks.json" # 25. KMS echo "--- KMS Keys ---" aws kms list-keys --region $REGION --output json > "$OUTPUT_DIR/kms.json" 2>/dev/null || echo "[]" > "$OUTPUT_DIR/kms.json" echo "=== Discovery avslutad ===" echo "Resultat i: $OUTPUT_DIR/" echo "Tidsstämpel: $TIMESTAMP"