mirror of
https://github.com/BagelHole/DevOps-Security-Agent-Skills.git
synced 2026-08-22 12:49:53 +02:00
.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
---
|
||||
name: gcp-cloud-functions
|
||||
description: Deploy serverless functions on Google Cloud Functions. Configure triggers and manage deployments. Use when implementing serverless workloads on GCP.
|
||||
license: MIT
|
||||
metadata:
|
||||
author: devops-skills
|
||||
version: "1.0"
|
||||
---
|
||||
|
||||
# GCP Cloud Functions
|
||||
|
||||
Build serverless applications with Cloud Functions.
|
||||
|
||||
## Deploy Function
|
||||
|
||||
```bash
|
||||
# Deploy HTTP function
|
||||
gcloud functions deploy hello \
|
||||
--runtime=python311 \
|
||||
--trigger-http \
|
||||
--allow-unauthenticated \
|
||||
--entry-point=hello_http
|
||||
|
||||
# Deploy Pub/Sub triggered function
|
||||
gcloud functions deploy process-message \
|
||||
--runtime=python311 \
|
||||
--trigger-topic=my-topic \
|
||||
--entry-point=process
|
||||
```
|
||||
|
||||
## Function Code
|
||||
|
||||
```python
|
||||
# main.py
|
||||
def hello_http(request):
|
||||
return 'Hello, World!'
|
||||
|
||||
def process(event, context):
|
||||
import base64
|
||||
data = base64.b64decode(event['data']).decode('utf-8')
|
||||
print(f"Received: {data}")
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
- Use 2nd gen functions for better performance
|
||||
- Implement proper error handling
|
||||
- Use environment variables for configuration
|
||||
- Monitor with Cloud Logging
|
||||
@@ -0,0 +1,49 @@
|
||||
---
|
||||
name: gcp-cloud-sql
|
||||
description: Provision Cloud SQL and Spanner databases. Configure high availability, backups, and security. Use when deploying managed databases on GCP.
|
||||
license: MIT
|
||||
metadata:
|
||||
author: devops-skills
|
||||
version: "1.0"
|
||||
---
|
||||
|
||||
# GCP Cloud SQL
|
||||
|
||||
Deploy managed databases on Google Cloud.
|
||||
|
||||
## Create Instance
|
||||
|
||||
```bash
|
||||
gcloud sql instances create mydb \
|
||||
--database-version=POSTGRES_15 \
|
||||
--tier=db-f1-micro \
|
||||
--region=us-central1 \
|
||||
--root-password=secretpassword \
|
||||
--storage-auto-increase \
|
||||
--backup-start-time=02:00
|
||||
|
||||
# Create database
|
||||
gcloud sql databases create myapp --instance=mydb
|
||||
|
||||
# Create user
|
||||
gcloud sql users create appuser \
|
||||
--instance=mydb \
|
||||
--password=userpassword
|
||||
```
|
||||
|
||||
## High Availability
|
||||
|
||||
```bash
|
||||
gcloud sql instances create mydb \
|
||||
--database-version=POSTGRES_15 \
|
||||
--tier=db-custom-2-8192 \
|
||||
--region=us-central1 \
|
||||
--availability-type=REGIONAL
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
- Enable automated backups
|
||||
- Use Cloud SQL Proxy for connections
|
||||
- Implement private IP
|
||||
- Use read replicas for scaling
|
||||
@@ -0,0 +1,42 @@
|
||||
---
|
||||
name: gcp-compute
|
||||
description: Manage Compute Engine instances and instance templates. Configure managed instance groups and preemptible VMs. Use when deploying compute resources on GCP.
|
||||
license: MIT
|
||||
metadata:
|
||||
author: devops-skills
|
||||
version: "1.0"
|
||||
---
|
||||
|
||||
# GCP Compute Engine
|
||||
|
||||
Deploy and manage Compute Engine instances.
|
||||
|
||||
## Create Instance
|
||||
|
||||
```bash
|
||||
gcloud compute instances create web-server \
|
||||
--machine-type=e2-medium \
|
||||
--zone=us-central1-a \
|
||||
--image-family=debian-11 \
|
||||
--image-project=debian-cloud \
|
||||
--boot-disk-size=20GB \
|
||||
--tags=http-server
|
||||
|
||||
# Create from instance template
|
||||
gcloud compute instance-templates create web-template \
|
||||
--machine-type=e2-medium \
|
||||
--image-family=debian-11 \
|
||||
--image-project=debian-cloud
|
||||
|
||||
gcloud compute instance-groups managed create web-group \
|
||||
--template=web-template \
|
||||
--size=3 \
|
||||
--zone=us-central1-a
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
- Use managed instance groups
|
||||
- Implement preemptible VMs for cost savings
|
||||
- Use custom images for consistency
|
||||
- Enable shielded VMs
|
||||
@@ -0,0 +1,55 @@
|
||||
---
|
||||
name: gcp-gke
|
||||
description: Deploy and manage Google Kubernetes Engine clusters. Configure node pools, networking, and workload identity. Use when running Kubernetes on GCP.
|
||||
license: MIT
|
||||
metadata:
|
||||
author: devops-skills
|
||||
version: "1.0"
|
||||
---
|
||||
|
||||
# Google Kubernetes Engine
|
||||
|
||||
Deploy managed Kubernetes clusters on GCP.
|
||||
|
||||
## Create Cluster
|
||||
|
||||
```bash
|
||||
gcloud container clusters create my-cluster \
|
||||
--num-nodes=3 \
|
||||
--machine-type=e2-medium \
|
||||
--zone=us-central1-a \
|
||||
--enable-autoscaling \
|
||||
--min-nodes=1 \
|
||||
--max-nodes=5 \
|
||||
--workload-pool=${PROJECT_ID}.svc.id.goog
|
||||
|
||||
# Get credentials
|
||||
gcloud container clusters get-credentials my-cluster --zone=us-central1-a
|
||||
```
|
||||
|
||||
## Node Pools
|
||||
|
||||
```bash
|
||||
gcloud container node-pools create gpu-pool \
|
||||
--cluster=my-cluster \
|
||||
--zone=us-central1-a \
|
||||
--machine-type=n1-standard-4 \
|
||||
--accelerator=type=nvidia-tesla-k80,count=1 \
|
||||
--num-nodes=1
|
||||
```
|
||||
|
||||
## Workload Identity
|
||||
|
||||
```bash
|
||||
gcloud iam service-accounts add-iam-policy-binding \
|
||||
--role=roles/iam.workloadIdentityUser \
|
||||
--member="serviceAccount:${PROJECT_ID}.svc.id.goog[NAMESPACE/KSA_NAME]" \
|
||||
GSA_NAME@${PROJECT_ID}.iam.gserviceaccount.com
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
- Use Workload Identity
|
||||
- Enable VPC-native clusters
|
||||
- Implement node auto-provisioning
|
||||
- Use regional clusters for HA
|
||||
@@ -0,0 +1,59 @@
|
||||
---
|
||||
name: gcp-networking
|
||||
description: Configure VPCs, firewall rules, and Cloud NAT. Implement shared VPC and private service connect. Use when designing GCP network infrastructure.
|
||||
license: MIT
|
||||
metadata:
|
||||
author: devops-skills
|
||||
version: "1.0"
|
||||
---
|
||||
|
||||
# GCP Networking
|
||||
|
||||
Design and implement GCP network infrastructure.
|
||||
|
||||
## Create VPC
|
||||
|
||||
```bash
|
||||
gcloud compute networks create my-vpc --subnet-mode=custom
|
||||
|
||||
gcloud compute networks subnets create my-subnet \
|
||||
--network=my-vpc \
|
||||
--region=us-central1 \
|
||||
--range=10.0.0.0/24
|
||||
```
|
||||
|
||||
## Firewall Rules
|
||||
|
||||
```bash
|
||||
gcloud compute firewall-rules create allow-http \
|
||||
--network=my-vpc \
|
||||
--allow=tcp:80,tcp:443 \
|
||||
--source-ranges=0.0.0.0/0 \
|
||||
--target-tags=http-server
|
||||
|
||||
gcloud compute firewall-rules create allow-internal \
|
||||
--network=my-vpc \
|
||||
--allow=tcp,udp,icmp \
|
||||
--source-ranges=10.0.0.0/8
|
||||
```
|
||||
|
||||
## Cloud NAT
|
||||
|
||||
```bash
|
||||
gcloud compute routers create my-router \
|
||||
--network=my-vpc \
|
||||
--region=us-central1
|
||||
|
||||
gcloud compute routers nats create my-nat \
|
||||
--router=my-router \
|
||||
--region=us-central1 \
|
||||
--nat-all-subnet-ip-ranges \
|
||||
--auto-allocate-nat-external-ips
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
- Use Shared VPC for multi-project
|
||||
- Implement Cloud Armor for DDoS
|
||||
- Use Private Google Access
|
||||
- Enable VPC Flow Logs
|
||||
@@ -0,0 +1,66 @@
|
||||
---
|
||||
name: terraform-gcp
|
||||
description: Provision GCP infrastructure with Terraform. Configure providers and deploy Google Cloud resources. Use when implementing IaC for GCP.
|
||||
license: MIT
|
||||
metadata:
|
||||
author: devops-skills
|
||||
version: "1.0"
|
||||
---
|
||||
|
||||
# Terraform GCP
|
||||
|
||||
Provision Google Cloud infrastructure with Terraform.
|
||||
|
||||
## Provider Configuration
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
google = {
|
||||
source = "hashicorp/google"
|
||||
version = "~> 5.0"
|
||||
}
|
||||
}
|
||||
backend "gcs" {
|
||||
bucket = "tf-state-bucket"
|
||||
prefix = "terraform/state"
|
||||
}
|
||||
}
|
||||
|
||||
provider "google" {
|
||||
project = var.project_id
|
||||
region = var.region
|
||||
}
|
||||
```
|
||||
|
||||
## Example Resources
|
||||
|
||||
```hcl
|
||||
resource "google_compute_network" "vpc" {
|
||||
name = "main-vpc"
|
||||
auto_create_subnetworks = false
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "vm" {
|
||||
name = "web-server"
|
||||
machine_type = "e2-micro"
|
||||
zone = "us-central1-a"
|
||||
|
||||
boot_disk {
|
||||
initialize_params {
|
||||
image = "debian-cloud/debian-11"
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
network = google_compute_network.vpc.name
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
- Use service accounts for authentication
|
||||
- Store state in GCS
|
||||
- Use labels consistently
|
||||
- Implement least-privilege IAM
|
||||
@@ -0,0 +1,114 @@
|
||||
# GCP VPC Module Template
|
||||
|
||||
variable "network_name" {
|
||||
description = "VPC network name"
|
||||
type = string
|
||||
default = "main"
|
||||
}
|
||||
|
||||
# VPC Network
|
||||
resource "google_compute_network" "main" {
|
||||
name = "${var.project_name}-${var.environment}-vpc"
|
||||
auto_create_subnetworks = false
|
||||
project = var.project_id
|
||||
}
|
||||
|
||||
# Public Subnet
|
||||
resource "google_compute_subnetwork" "public" {
|
||||
name = "${var.project_name}-${var.environment}-public"
|
||||
ip_cidr_range = "10.0.1.0/24"
|
||||
region = var.region
|
||||
network = google_compute_network.main.id
|
||||
project = var.project_id
|
||||
|
||||
secondary_ip_range {
|
||||
range_name = "gke-pods"
|
||||
ip_cidr_range = "10.1.0.0/16"
|
||||
}
|
||||
|
||||
secondary_ip_range {
|
||||
range_name = "gke-services"
|
||||
ip_cidr_range = "10.2.0.0/20"
|
||||
}
|
||||
}
|
||||
|
||||
# Private Subnet
|
||||
resource "google_compute_subnetwork" "private" {
|
||||
name = "${var.project_name}-${var.environment}-private"
|
||||
ip_cidr_range = "10.0.2.0/24"
|
||||
region = var.region
|
||||
network = google_compute_network.main.id
|
||||
project = var.project_id
|
||||
private_ip_google_access = true
|
||||
}
|
||||
|
||||
# Cloud Router (for NAT)
|
||||
resource "google_compute_router" "main" {
|
||||
name = "${var.project_name}-${var.environment}-router"
|
||||
region = var.region
|
||||
network = google_compute_network.main.id
|
||||
project = var.project_id
|
||||
}
|
||||
|
||||
# Cloud NAT
|
||||
resource "google_compute_router_nat" "main" {
|
||||
name = "${var.project_name}-${var.environment}-nat"
|
||||
router = google_compute_router.main.name
|
||||
region = var.region
|
||||
project = var.project_id
|
||||
nat_ip_allocate_option = "AUTO_ONLY"
|
||||
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
|
||||
}
|
||||
|
||||
# Firewall - Allow SSH
|
||||
resource "google_compute_firewall" "allow_ssh" {
|
||||
name = "${var.project_name}-${var.environment}-allow-ssh"
|
||||
network = google_compute_network.main.name
|
||||
project = var.project_id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["22"]
|
||||
}
|
||||
|
||||
source_ranges = ["0.0.0.0/0"]
|
||||
target_tags = ["ssh"]
|
||||
}
|
||||
|
||||
# Firewall - Allow Internal
|
||||
resource "google_compute_firewall" "allow_internal" {
|
||||
name = "${var.project_name}-${var.environment}-allow-internal"
|
||||
network = google_compute_network.main.name
|
||||
project = var.project_id
|
||||
|
||||
allow {
|
||||
protocol = "icmp"
|
||||
}
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["0-65535"]
|
||||
}
|
||||
|
||||
allow {
|
||||
protocol = "udp"
|
||||
ports = ["0-65535"]
|
||||
}
|
||||
|
||||
source_ranges = ["10.0.0.0/8"]
|
||||
}
|
||||
|
||||
output "network_name" {
|
||||
value = google_compute_network.main.name
|
||||
}
|
||||
|
||||
output "network_id" {
|
||||
value = google_compute_network.main.id
|
||||
}
|
||||
|
||||
output "subnet_ids" {
|
||||
value = {
|
||||
public = google_compute_subnetwork.public.id
|
||||
private = google_compute_subnetwork.private.id
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
#!/bin/bash
|
||||
# Terraform GCP Project Initialization Script
|
||||
# Usage: ./tf-init-gcp.sh <project-name> <gcp-project-id> [region]
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
PROJECT_NAME="${1:-}"
|
||||
GCP_PROJECT="${2:-}"
|
||||
REGION="${3:-us-central1}"
|
||||
|
||||
if [ -z "$PROJECT_NAME" ] || [ -z "$GCP_PROJECT" ]; then
|
||||
echo "Usage: $0 <project-name> <gcp-project-id> [region]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "========================================="
|
||||
echo "Terraform GCP Project Setup"
|
||||
echo "Project: $PROJECT_NAME"
|
||||
echo "GCP Project: $GCP_PROJECT"
|
||||
echo "Region: $REGION"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
|
||||
mkdir -p "$PROJECT_NAME"
|
||||
cd "$PROJECT_NAME"
|
||||
|
||||
# Create main.tf
|
||||
cat > main.tf << EOF
|
||||
terraform {
|
||||
required_version = ">= 1.0"
|
||||
|
||||
required_providers {
|
||||
google = {
|
||||
source = "hashicorp/google"
|
||||
version = "~> 5.0"
|
||||
}
|
||||
}
|
||||
|
||||
# Uncomment for remote state
|
||||
# backend "gcs" {
|
||||
# bucket = "${PROJECT_NAME}-tfstate"
|
||||
# prefix = "terraform/state"
|
||||
# }
|
||||
}
|
||||
|
||||
provider "google" {
|
||||
project = var.project_id
|
||||
region = var.region
|
||||
}
|
||||
|
||||
locals {
|
||||
common_labels = {
|
||||
project = var.project_name
|
||||
environment = var.environment
|
||||
managed-by = "terraform"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Create variables.tf
|
||||
cat > variables.tf << EOF
|
||||
variable "project_name" {
|
||||
description = "Project name for resource naming"
|
||||
type = string
|
||||
default = "${PROJECT_NAME}"
|
||||
}
|
||||
|
||||
variable "project_id" {
|
||||
description = "GCP Project ID"
|
||||
type = string
|
||||
default = "${GCP_PROJECT}"
|
||||
}
|
||||
|
||||
variable "environment" {
|
||||
description = "Environment (dev, staging, prod)"
|
||||
type = string
|
||||
default = "dev"
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "GCP region"
|
||||
type = string
|
||||
default = "${REGION}"
|
||||
}
|
||||
EOF
|
||||
|
||||
# Create outputs.tf
|
||||
cat > outputs.tf << EOF
|
||||
output "project_id" {
|
||||
description = "GCP Project ID"
|
||||
value = var.project_id
|
||||
}
|
||||
|
||||
output "region" {
|
||||
description = "GCP region"
|
||||
value = var.region
|
||||
}
|
||||
EOF
|
||||
|
||||
# Create terraform.tfvars
|
||||
cat > terraform.tfvars << EOF
|
||||
project_name = "${PROJECT_NAME}"
|
||||
project_id = "${GCP_PROJECT}"
|
||||
environment = "dev"
|
||||
region = "${REGION}"
|
||||
EOF
|
||||
|
||||
# Create .gitignore
|
||||
cat > .gitignore << EOF
|
||||
.terraform/
|
||||
*.tfstate
|
||||
*.tfstate.*
|
||||
*.tfvars.json
|
||||
crash.log
|
||||
*.tfplan
|
||||
!terraform.tfvars.example
|
||||
.idea/
|
||||
*.swp
|
||||
.vscode/
|
||||
EOF
|
||||
|
||||
# Initialize Terraform
|
||||
echo ""
|
||||
echo "Initializing Terraform..."
|
||||
terraform init
|
||||
|
||||
echo ""
|
||||
echo "========================================="
|
||||
echo "Project created successfully!"
|
||||
echo "========================================="
|
||||
Reference in New Issue
Block a user