Projeto Terraform modular que padroniza e automatiza a segurança de rede em 4 clouds com políticas unificadas.
"Se você não consegue destruir sua rede inteira e reconstruí-la em 10 minutos via Terraform com todas as regras de segurança aplicadas, você ainda tem um perímetro legado."
- O Problema
- A Solução
- Arquitetura
- Estrutura do Projeto
- Início Rápido
- Módulos
- Regras de Segurança
- Conectividade
- Monitoramento
- Ambientes
- Contribuindo
- Referências
Empresas que operam em ambientes híbridos e multi-cloud enfrentam diariamente:
| Desafio | Impacto |
|---|---|
| 🔓 Regras de segurança inconsistentes entre clouds | Brechas de segurança não detectadas |
| ⏱️ Impossibilidade de reproduzir infra rapidamente | Disaster Recovery lento (horas/dias) |
| 👀 Falta de visibilidade centralizada | Shadow IT e compliance gaps |
| ✋ Configurações manuais | Erros humanos, drift de configuração |
| 📊 4 dashboards diferentes para 4 clouds | Complexidade operacional insustentável |
Uma fonte única de verdade para regras de segurança, implementada como Infrastructure as Code:
graph TB
subgraph "🔒 Fonte Única de Verdade"
SP["security-policy<br/>Regras Normalizadas"]
end
SP -->|"Traduz para SG + NACL"| AWS["☁️ AWS<br/>Security Groups<br/>Network ACLs<br/>VPC Flow Logs"]
SP -->|"Traduz para NSG + Firewall"| AZ["☁️ Azure<br/>NSGs<br/>Azure Firewall<br/>Log Analytics"]
SP -->|"Traduz para Firewall Rules"| GCP["☁️ GCP<br/>Compute Firewall<br/>Cloud NAT"]
SP -->|"Traduz para SL + NSG"| OCI["☁️ OCI<br/>Security Lists<br/>Network Security Groups"]
style SP fill:#2d6a4f,stroke:#40916c,color:#fff
style AWS fill:#ff9900,stroke:#cc7a00,color:#fff
style AZ fill:#0078d4,stroke:#005a9e,color:#fff
style GCP fill:#4285f4,stroke:#2a6acf,color:#fff
style OCI fill:#f80000,stroke:#c60000,color:#fff
Resultado: Altere uma regra no security-policy → ela se propaga automaticamente para AWS, Azure, GCP e OCI.
graph TB
subgraph "🏢 On-Premises"
DC["Data Center"]
PAB["PABs / Lojas"]
end
subgraph "☁️ AWS — 10.10.0.0/16"
direction TB
AVPC["VPC"]
APUB["Subnet Pública<br/>10.10.1.0/24"]
APRIV["Subnet Privada<br/>10.10.10.0/24"]
ASG["Security Groups"]
ANACL["Network ACLs"]
AFL["VPC Flow Logs → CloudWatch"]
AVPC --> APUB & APRIV
ASG & ANACL -.->|protegem| AVPC
AVPC -.-> AFL
end
subgraph "☁️ Azure — 10.20.0.0/16"
direction TB
BVNET["VNet"]
BPUB["Subnet Pública<br/>10.20.1.0/24"]
BPRIV["Subnet Privada<br/>10.20.10.0/24"]
BFW["Azure Firewall<br/>10.20.250.0/26"]
BNSG["NSGs"]
BLOG["Log Analytics"]
BVNET --> BPUB & BPRIV & BFW
BNSG -.->|protegem| BVNET
BFW -.->|inspeciona| BPRIV
BVNET -.-> BLOG
end
subgraph "☁️ GCP — 10.30.0.0/16"
direction TB
GVPC["VPC Custom"]
GSUB["Subnet<br/>10.30.1.0/24"]
GFW["Firewall Rules"]
GNAT["Cloud NAT + Router"]
GVPC --> GSUB
GFW -.->|protegem| GVPC
GSUB --> GNAT
end
subgraph "☁️ OCI — 10.40.0.0/16"
direction TB
OVCN["VCN"]
OPUB["Subnet Pública<br/>10.40.1.0/24"]
OPRIV["Subnet Privada<br/>10.40.10.0/24"]
OSL["Security Lists"]
ONSG["NSGs (VNIC-level)"]
OVCN --> OPUB & OPRIV
OSL & ONSG -.->|protegem| OVCN
end
DC & PAB ---|"🔐 VPN / SD-WAN"| AVPC
AVPC ---|"🔐 VPN Site-to-Site"| BVNET
BVNET ---|"⚡ Interconnect<br/>sub-2ms"| OVCN
AVPC ---|"🔐 VPN"| GVPC
style DC fill:#555,stroke:#777,color:#fff
style PAB fill:#555,stroke:#777,color:#fff
style AVPC fill:#ff9900,stroke:#cc7a00,color:#fff
style BVNET fill:#0078d4,stroke:#005a9e,color:#fff
style GVPC fill:#4285f4,stroke:#2a6acf,color:#fff
style OVCN fill:#f80000,stroke:#c60000,color:#fff
style BFW fill:#e63946,stroke:#c5303c,color:#fff
graph LR
subgraph Input
R1["HTTPS :443 ✅"]
R2["SSH :22 🔒"]
R3["Deny All ❌"]
R4["Allow Egress ✅"]
end
R1 & R2 & R3 & R4 --> SP["🔒 security-policy"]
SP --> AWS_SG["aws_security_group_rule"]
SP --> AWS_NACL["aws_network_acl"]
SP --> AZ_NSG["azurerm_network_security_rule"]
SP --> AZ_FW["azurerm_firewall_network_rule"]
SP --> GCP_FW["google_compute_firewall"]
SP --> OCI_SL["oci_core_security_list"]
SP --> OCI_NSG["oci_core_nsg_security_rule"]
style SP fill:#2d6a4f,stroke:#40916c,color:#fff
📦 multicloud-security/
├── 📄 main.tf # Composição de todos os módulos
├── 📄 providers.tf # Declaração dos 4 providers
├── 📄 variables.tf # Variáveis globais (CIDRs, regiões, tags)
├── 📄 outputs.tf # IDs de rede de cada cloud
├── 📄 backend.tf # Config do state remoto (S3/Blob/GCS)
├── 📄 terraform.tfvars.example # Template de configuração
├── 📄 .gitignore # Protege state e credenciais
│
├── 📂 modules/
│ ├── 📂 security-policy/ # 🔒 Regras normalizadas (FONTE ÚNICA)
│ │ └── main.tf # Baseline + regras por ambiente
│ │
│ ├── 📂 aws/ # ☁️ Amazon Web Services
│ │ ├── main.tf # VPC, Subnets, SGs, NACLs, Flow Logs
│ │ ├── variables.tf
│ │ └── outputs.tf
│ │
│ ├── 📂 azure/ # ☁️ Microsoft Azure
│ │ ├── main.tf # VNet, NSGs, Firewall, UDRs, Logs
│ │ ├── variables.tf
│ │ └── outputs.tf
│ │
│ ├── 📂 gcp/ # ☁️ Google Cloud Platform
│ │ ├── main.tf # VPC, Firewall Rules, Cloud NAT
│ │ ├── variables.tf
│ │ └── outputs.tf
│ │
│ ├── 📂 oci/ # ☁️ Oracle Cloud Infrastructure
│ │ ├── main.tf # VCN, Security Lists, NSGs, Gateways
│ │ ├── variables.tf
│ │ └── outputs.tf
│ │
│ └── 📂 connectivity/ # 🔗 VPN, Peering, Interconnect
│ └── main.tf # AWS↔Azure, AWS↔On-prem
│
├── 📂 environments/
│ ├── 📂 dev/ # 🟢 Desenvolvimento
│ │ └── main.tf
│ ├── 📂 staging/ # 🟡 Staging
│ │ └── main.tf
│ └── 📂 prod/ # 🔴 Produção (Firewall habilitado)
│ └── main.tf
│
└── 📂 docs/ # 📖 Documentação adicional
├── ARCHITECTURE.md # Detalhes da arquitetura
├── MODULES.md # Referência dos módulos
├── SECURITY.md # Políticas e compliance
└── RUNBOOK.md # Procedimentos operacionais
| Ferramenta | Versão | Instalação |
|---|---|---|
| Terraform | >= 1.5.0 | Download |
| AWS CLI | >= 2.0 | aws configure |
| Azure CLI | >= 2.0 | az login |
| gcloud CLI | latest | gcloud auth application-default login |
| OCI CLI | latest | ~/.oci/config |
git clone https://github.com/SEU_USUARIO/multicloud-network-security.git
cd multicloud-network-security
# Copiar e preencher variáveis
cp terraform.tfvars.example terraform.tfvars
# ⚠️ Editar com seus valores reais (credenciais, CIDRs, etc.)# Inicializar providers e módulos
terraform init
# Validar sintaxe e referências
terraform validate
# Verificar formatação
terraform fmt -check -recursive# Ver o plano completo (dry-run)
terraform plan -out=tfplan
# Aplicar as mudanças
terraform apply tfplan# Exemplo: deploy em desenvolvimento
cd environments/dev
terraform init
terraform plan
terraform apply# Destruir TUDO
terraform destroy -auto-approve
# Reconstruir do ZERO — todas as regras reaplicadas automaticamente
terraform apply -auto-approve
# Tempo esperado: < 10 minutos 🎯O coração do projeto. Define regras em formato agnóstico que cada provider consome:
# Exemplo de regra normalizada
{
name = "allow-https"
port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
description = "Permitir HTTPS"
}Comportamento por ambiente:
- prod: Apenas HTTPS e SSH restrito
- dev/staging: Adiciona HTTP interno (porta 80)
📖 Documentação detalhada dos módulos →
| Regra | Porta | Protocolo | Direção | Ambiente | CIDR |
|---|---|---|---|---|---|
| ✅ HTTPS | 443 | TCP | Ingress | Todos | 0.0.0.0/0 |
| 🔒 SSH restrito | 22 | TCP | Ingress | Todos | 10.0.0.0/8 |
| 🌐 HTTP interno | 80 | TCP | Ingress | dev/staging | 10.0.0.0/8 |
| ❌ Deny All | * | * | Ingress | Todos | 0.0.0.0/0 |
| ✅ Allow All | * | * | Egress | Todos | 0.0.0.0/0 |
# No terraform.tfvars
additional_ingress_rules = [
{
name = "allow-rdp"
port = 3389
protocol = "tcp"
cidr_blocks = ["10.0.0.0/8"]
description = "RDP para redes internas"
},
{
name = "allow-k8s-api"
port = 6443
protocol = "tcp"
cidr_blocks = ["10.0.0.0/8"]
description = "Kubernetes API Server"
}
]📖 Política de segurança completa →
graph LR
ONPREM["🏢 On-Premises<br/>PABs / Lojas"] ---|"🔐 VPN IPSec<br/>SD-WAN"| AWS
AWS["☁️ AWS<br/>10.10.0.0/16"] ---|"🔐 VPN<br/>Site-to-Site"| AZURE["☁️ Azure<br/>10.20.0.0/16"]
AZURE ---|"⚡ Interconnect<br/>Latência sub-2ms"| OCI["☁️ OCI<br/>10.40.0.0/16"]
AWS ---|"🔐 VPN"| GCP["☁️ GCP<br/>10.30.0.0/16"]
style AWS fill:#ff9900,stroke:#cc7a00,color:#fff
style AZURE fill:#0078d4,stroke:#005a9e,color:#fff
style GCP fill:#4285f4,stroke:#2a6acf,color:#fff
style OCI fill:#f80000,stroke:#c60000,color:#fff
style ONPREM fill:#555,stroke:#777,color:#fff
| Conexão | Tipo | Criptografia | Latência |
|---|---|---|---|
| AWS ↔ Azure | VPN Site-to-Site (IPSec) | AES-256 | ~15ms |
| Azure ↔ OCI | Interconnect Direto | Nativo | < 2ms |
| AWS ↔ On-prem | VPN + SD-WAN | AES-256 | Variável |
| GCP ↔ Hub | Cloud VPN | AES-256 | ~10ms |
Habilite via variáveis:
enable_aws_azure_vpn = true
enable_onprem_vpn = trueCada cloud envia logs de tráfego para seu serviço nativo:
| Cloud | Recurso Monitorado | Destino | Retenção |
|---|---|---|---|
| AWS | VPC Flow Logs | CloudWatch Logs | 30 dias |
| Azure | NSG Diagnostics | Log Analytics Workspace | 30 dias |
| GCP | Subnet Flow Logs | Cloud Logging | Padrão GCP |
| OCI | VCN Flow Logs | OCI Logging | Padrão OCI |
graph LR
DEV["🟢 DEV<br/>CIDRs menores<br/>1 AZ<br/>Sem Firewall"] --> STG["🟡 STAGING<br/>CIDRs médios<br/>2 AZs<br/>Sem Firewall"]
STG --> PROD["🔴 PROD<br/>CIDRs completos<br/>3 AZs<br/>Firewall ATIVO<br/>DMZ"]
style DEV fill:#2d6a4f,stroke:#40916c,color:#fff
style STG fill:#e9c46a,stroke:#d4a843,color:#333
style PROD fill:#e63946,stroke:#c5303c,color:#fff
| Característica | Dev | Staging | Prod |
|---|---|---|---|
| Availability Zones | 1 | 2 | 3 |
| Azure Firewall | ❌ | ❌ | ✅ |
| HTTP (porta 80) | ✅ | ✅ | ❌ |
| Subnet DMZ | ❌ | ❌ | ✅ |
| CIDR /24 Subnets | 1 pub + 1 priv | 2 pub + 2 priv | 3 pub + 3 priv |
Todos os recursos são tagueados automaticamente para governança:
{
Project = "multicloud-security"
Environment = "dev" | "staging" | "prod"
ManagedBy = "terraform"
Owner = "heavyscan"
}🔑 State Remoto: Configure o
backend.tfantes de usar em produção. O state contém dados sensíveis.
🔐 Credenciais: NUNCA comite
terraform.tfvarsno Git. Ele está no.gitignore.
💰 Azure Firewall: Habilitado automaticamente em
prod. Custo:$1.25/hora ($900/mês).
🔒 SSH: Por padrão restrito a
10.0.0.0/8. Ajusteallowed_ssh_cidrsconforme sua rede.
- Fork o repositório
- Crie uma branch:
git checkout -b feature/nova-regra - Faça suas alterações
- Valide:
terraform fmt && terraform validate - Abra um Pull Request
| Recurso | Link |
|---|---|
| Terraform Multi-Cloud | HashiCorp Tutorials |
| Azure Hub-Spoke | Microsoft Reference Architecture |
| AWS VPC Security | AWS Best Practices |
| GCP Firewall | Cloud Firewall Docs |
| OCI Networking | Oracle Docs |
MIT License — veja LICENSE para detalhes.
Criado por @heavyscan 🛡️
Infraestrutura Multi-Cloud as Code.