feat: 重构基础设施配置与安全凭证管理
Some checks failed
Infrastructure CI/CD / Validate Infrastructure (push) Failing after 9s
Infrastructure CI/CD / Plan Infrastructure (push) Has been skipped
Infrastructure CI/CD / Apply Infrastructure (push) Has been skipped
Simple Test / test (push) Successful in 1s

- 新增多个云服务商配置文件(OCI、阿里云)
- 重构Vault、Consul、Nomad等服务的部署配置
- 新增备份与恢复完美状态的脚本
- 更新安全凭证管理文档
- 优化Traefik动态配置
- 删除过时的脚本和配置文件

重构后的配置支持多区域部署,优化了服务发现和负载均衡机制,并完善了安全凭证的备份与恢复流程。
This commit is contained in:
2025-10-13 03:08:22 +00:00
parent 41bff0cd02
commit 4381428b5d
48 changed files with 3628 additions and 498 deletions

View File

@@ -0,0 +1,79 @@
# 阿里云北京区域 Terraform 配置
## 概述
这个目录包含阿里云北京区域的 Terraform 配置文件,主要用于 Supabase 部署。
## 文件结构
```
terraform-alicloud-beijing/
├── README.md # 本文档
├── variables.tf # 变量定义
├── terraform.tfvars # 变量值配置
├── alicloud-config.json # 阿里云配置文件
├── create_beijing_switch.tf # 创建北京可用区I交换机
└── check_supabase_status.tf # 检查 Supabase 状态
```
## 配置信息
### 区域信息
- **区域**: cn-beijing (北京)
- **VPC ID**: vpc-2ze1d10frat58rkmugz2d (bj_ipam)
- **现有交换机**: vsw-2zert539m12zh3ipi5dlg (bj_k, cn-beijing-k)
### 网络配置
- **VPC CIDR**: 10.0.0.0/16
- **现有交换机**: 10.0.0.0/24 (cn-beijing-k)
- **新交换机**: 10.0.1.0/24 (cn-beijing-i)
## 使用方法
### 1. 创建北京可用区I交换机
```bash
cd /root/mgmt/cloud_provider/terraform-alicloud-beijing
terraform init
terraform plan -target=alicloud_vswitch.bj_i
terraform apply -target=alicloud_vswitch.bj_i
```
### 2. 检查 Supabase 状态
```bash
terraform plan -target=data.alicloud_db_instances.all
terraform apply
terraform output db_instances_status
terraform output creating_instances
```
### 3. 检查网络使用情况
```bash
terraform output network_usage
```
## 安全注意事项
- 凭据信息已配置在 variables.tf 中
- 建议在生产环境中使用环境变量或密钥管理系统
- 定期轮换 AccessKey
## 故障排除
### 创建速度慢的可能原因
1. **服务可用性**: Supabase 在北京区域可能服务有限
2. **资源配额**: 检查 VPC 内资源配额
3. **网络策略**: 可能需要特定安全组配置
4. **权限问题**: 检查 AccessKey 权限
### 检查命令
```bash
# 检查当前实例状态
terraform output creating_instances
# 检查网络配置
terraform output network_usage
# 查看详细状态
terraform show
```
## 相关文档
- [阿里云凭据配置](../../security/alicloud-credentials.md)
- [网络分析报告](../../security/alicloud-network-analysis.md)

View File

@@ -0,0 +1,12 @@
{
"current": "default",
"profiles": [
{
"name": "default",
"mode": "AK",
"access_key_id": "LTAI5tBRm7PbNFdaGZpUaLUJ",
"access_key_secret": "cYRaxAoE9I3MILlHRgUbowfxQzhj1D",
"region_id": "cn-hangzhou"
}
]
}

View File

@@ -0,0 +1,119 @@
# 阿里云北京区域主配置文件
terraform {
required_providers {
alicloud = {
source = "aliyun/alicloud"
version = "1.260.1"
}
}
}
provider "alicloud" {
access_key = var.access_key
secret_key = var.secret_key
region = var.region
}
# 创建北京可用区I的交换机
resource "alicloud_vswitch" "bj_i" {
vpc_id = var.vpc_id
cidr_block = "10.0.1.0/24" # 使用不同的网段
zone_id = "cn-beijing-i" # 北京可用区I
vswitch_name = "${var.project_name}-${var.environment}-bj-i-supabase"
tags = merge(var.common_tags, {
Name = "${var.project_name}-${var.environment}-bj-i-supabase"
Purpose = "Supabase deployment"
})
}
# 获取所有 RDS 实例(包括所有状态)
data "alicloud_db_instances" "all" {
# 不限制状态,获取所有实例
}
# 注意alicloud_db_instance 是资源类型,不是数据源
# 我们只使用 alicloud_db_instances 数据源来获取实例列表
# 检查 VPC 和交换机使用情况
data "alicloud_vpcs" "all" {}
data "alicloud_vswitches" "all" {}
# 输出新创建的交换机信息
output "new_vswitch_id" {
value = alicloud_vswitch.bj_i.id
description = "新创建的北京可用区I交换机ID"
}
output "new_vswitch_name" {
value = alicloud_vswitch.bj_i.vswitch_name
description = "新创建的北京可用区I交换机名称"
}
# 输出所有数据库实例状态
output "db_instances_status" {
value = {
for instance in data.alicloud_db_instances.all.instances : instance.id => {
name = instance.db_instance_description
status = instance.db_instance_status
engine = instance.engine
engine_version = instance.engine_version
create_time = instance.create_time
expire_time = instance.expire_time
vpc_id = instance.vpc_id
vswitch_id = instance.vswitch_id
}
}
description = "所有数据库实例状态"
}
# 检查是否有正在创建的实例
output "creating_instances" {
value = [
for instance in data.alicloud_db_instances.all.instances : {
id = instance.id
name = instance.db_instance_description
status = instance.db_instance_status
create_time = instance.create_time
} if contains(["Creating", "DBInstanceClassChanging", "Transing", "Pending"], instance.db_instance_status)
]
description = "正在创建的数据库实例"
}
# 输出所有实例状态(用于调试)
output "all_instances_debug" {
value = [
for instance in data.alicloud_db_instances.all.instances : {
id = instance.id
name = instance.db_instance_description
status = instance.db_instance_status
create_time = instance.create_time
engine = instance.engine
}
]
description = "所有数据库实例状态(调试用)"
}
# 输出网络使用情况
output "network_usage" {
value = {
vpcs = {
for vpc in data.alicloud_vpcs.all.vpcs : vpc.id => {
name = vpc.vpc_name
cidr = vpc.cidr_block
status = vpc.status
}
}
vswitches = {
for vswitch in data.alicloud_vswitches.all.vswitches : vswitch.id => {
name = vswitch.vswitch_name
vpc_id = vswitch.vpc_id
zone_id = vswitch.zone_id
status = vswitch.status
}
}
}
description = "网络资源使用情况"
}

View File

@@ -0,0 +1,50 @@
# 阿里云北京区域变量定义
variable "access_key" {
description = "阿里云 AccessKey ID"
type = string
default = "LTAI5tBRm7PbNFdaGZpUaLUJ"
sensitive = true
}
variable "secret_key" {
description = "阿里云 AccessKey Secret"
type = string
default = "cYRaxAoE9I3MILlHRgUbowfxQzhj1D"
sensitive = true
}
variable "region" {
description = "阿里云区域"
type = string
default = "cn-beijing"
}
variable "vpc_id" {
description = "VPC ID"
type = string
default = "vpc-2ze1d10frat58rkmugz2d"
}
variable "project_name" {
description = "项目名称"
type = string
default = "mgmt"
}
variable "environment" {
description = "环境名称"
type = string
default = "dev"
}
variable "common_tags" {
description = "通用标签"
type = map(string)
default = {
Project = "mgmt"
Environment = "dev"
Owner = "ben"
ManagedBy = "terraform"
}
}