Initial commit: Terraform configurations for multiple cloud providers

This commit is contained in:
Ben User
2026-02-01 06:36:02 +00:00
commit 70f160b396
58 changed files with 1813 additions and 0 deletions

73
oracle/README.md Normal file
View File

@@ -0,0 +1,73 @@
# Oracle Cloud (OCI) Terraform 配置
## 项目结构
```
oracle/
├── main.tf # 根配置Provider 定义)
├── modules/ # 共享模块
│ ├── vcn/ # 虚拟云网络模块
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── outputs.tf
│ └── compute/ # 计算实例模块
│ ├── main.tf
│ └── variables.tf
└── environments/ # 环境特定配置
├── dev/ # 开发环境
│ ├── main.tf
│ └── variables.tf
└── prod/ # 生产环境
├── main.tf
└── variables.tf
```
## 配置说明
### 1. ~/.oci 配置
您的 OCI 配置已经位于 `~/.oci/` 目录中,包含:
- `config` - OCI 配置文件
- `oci_api_key.pem` - 私钥文件
Terraform OCI Provider 会自动读取这些配置,无需在代码中硬编码凭证。
### 2. 如何使用
**开发环境**
```bash
cd environments/dev
terraform init
terraform plan
terraform apply
```
**生产环境**
```bash
cd environments/prod
terraform init
terraform plan
terraform apply
```
### 3. 模块使用
模块位于 `modules/` 目录,可以在不同环境中重复使用:
```hcl
module "vcn" {
source = "../../modules/vcn"
compartment_id = var.compartment_id
vcn_name = "my-vcn"
cidr_block = "10.0.0.0/16"
}
```
## 优势
1. **环境隔离**dev 和 prod 环境完全分离
2. **代码复用**:模块可在不同环境中共享
3. **配置安全**:敏感信息存储在 `~/.oci`,不在代码中
4. **易于扩展**:可添加 staging、test 等环境
## 注意事项
1. 每个环境有独立的 Terraform 状态文件
2. 建议使用不同的 Compartment 或 Tenancy 隔离环境
3. 生产环境的 CIDR 和规格应与开发环境不同

View File

@@ -0,0 +1,38 @@
terraform {
required_providers {
oci = {
source = "oracle/oci"
version = ">= 4.0.0"
}
}
}
provider "oci" {
# 使用 ~/.oci/config 中的配置
# 如果 ~/.oci/config 已正确配置,以下参数可以省略
# 或者显式指定配置(可选)
# tenancy_ocid = "your-tenancy-ocid"
# user_ocid = "your-user-ocid"
# fingerprint = "your-fingerprint"
# private_key_path = "~/.oci/oci_api_key.pem"
# region = "us-phoenix-1"
}
module "vcn" {
source = "../../modules/vcn"
compartment_id = var.compartment_id
vcn_name = "${var.environment}-vcn"
cidr_block = "10.0.0.0/16"
dns_label = "devvcn"
}
module "compute" {
source = "../../modules/compute"
compartment_id = var.compartment_id
instance_name = "${var.environment}-instance"
shape = "VM.Standard2.1"
subnet_id = "ocid1.subnet.oc1..example" # 这里应该使用实际的子网 OCID
}

View File

@@ -0,0 +1,11 @@
variable "compartment_id" {
description = "开发环境的 Compartment OCID"
type = string
default = "ocid1.compartment.oc1..example"
}
variable "environment" {
description = "环境名称"
type = string
default = "dev"
}

View File

@@ -0,0 +1,38 @@
terraform {
required_providers {
oci = {
source = "oracle/oci"
version = ">= 4.0.0"
}
}
}
provider "oci" {
# 使用 ~/.oci/config 中的配置
# 如果 ~/.oci/config 已正确配置,以下参数可以省略
# 或者显式指定配置(可选)
# tenancy_ocid = "your-tenancy-ocid"
# user_ocid = "your-user-ocid"
# fingerprint = "your-fingerprint"
# private_key_path = "~/.oci/oci_api_key.pem"
# region = "us-phoenix-1"
}
module "vcn" {
source = "../../modules/vcn"
compartment_id = var.compartment_id
vcn_name = "${var.environment}-vcn"
cidr_block = "10.1.0.0/16" # 生产环境使用不同的 CIDR
dns_label = "prodvcn"
}
module "compute" {
source = "../../modules/compute"
compartment_id = var.compartment_id
instance_name = "${var.environment}-instance"
shape = "VM.Standard4.2" # 生产环境使用更高的规格
subnet_id = "ocid1.subnet.oc1..example" # 这里应该使用实际的子网 OCID
}

View File

@@ -0,0 +1,11 @@
variable "compartment_id" {
description = "生产环境的 Compartment OCID"
type = string
default = "ocid1.compartment.oc1..example"
}
variable "environment" {
description = "环境名称"
type = string
default = "prod"
}

26
oracle/kr/README.md Normal file
View File

@@ -0,0 +1,26 @@
# Oracle Cloud 韩国账号配置
## 配置说明
此目录包含韩国 Oracle Cloud 账号的 Terraform 配置。配置使用 `~/.oci/config` 文件中的 `[korea]` profile。
## 账号信息
- **区域**: ap-chuncheon-1韩国春川
- **Profile**: korea
- **密钥文件**: ~/.oci/oci_api_key_kr.pem
## 使用方法
```bash
cd /home/ben/terraform/oracle/kr
terraform init
terraform plan
terraform apply
```
## 区域特性
- **韩国春川区域** (ap-chuncheon-1): 位于韩国江原道,提供低延迟访问韩国本地市场
- 韩国区域的合规要求和服务可用性可能与美国区域不同
## 注意事项
- 确保 `~/.oci/config` 中的 [korea] 配置正确
- 韩国区域的资源命名可能需要遵守本地化规范
- 考虑网络延迟和本地合规要求

20
oracle/kr/main.tf Normal file
View File

@@ -0,0 +1,20 @@
terraform {
required_providers {
oci = {
source = "oracle/oci"
version = ">= 4.0.0"
}
}
}
provider "oci" {
# 韩国账号配置 - 使用 ~/.oci/config 中的 [korea] profile
config_file_profile = "korea"
# 或者,如果需要覆盖某些配置,可以显式指定:
# tenancy_ocid = "ocid1.tenancy.oc1..aaaaaaaawfv2wd54ly75ppfjgdgap7rtd3vhtziz25dwx23xo4rbkxnxlapq"
# user_ocid = "ocid1.user.oc1..aaaaaaaaqoa2my3fwh3jbayachyylqyneiveydrjliu2qz65ijlc57ehplha"
# fingerprint = "13:bd:ef:e3:bd:b8:5a:35:1a:b4:2d:82:4b:93:ff:19"
# private_key_path = "~/.oci/oci_api_key_kr.pem"
# region = "ap-chuncheon-1"
}

20
oracle/main.tf Normal file
View File

@@ -0,0 +1,20 @@
terraform {
required_providers {
oci = {
source = "oracle/oci"
version = ">= 4.0.0"
}
}
}
provider "oci" {
# 使用 ~/.oci/config 中的配置
# 如果 ~/.oci/config 已正确配置,以下参数可以省略
# 或者显式指定配置(可选)
# tenancy_ocid = "your-tenancy-ocid"
# user_ocid = "your-user-ocid"
# fingerprint = "your-fingerprint"
# private_key_path = "~/.oci/oci_api_key.pem"
# region = "us-phoenix-1"
}

View File

@@ -0,0 +1,14 @@
# Oracle 计算实例模块示例
# 这是一个示例,实际使用时需要替换为真实的 OCI 资源
resource "null_resource" "compute_example" {
triggers = {
compartment_id = var.compartment_id
instance_name = var.instance_name
shape = var.shape
}
provisioner "local-exec" {
command = "echo '创建计算实例: ${var.instance_name},规格: ${var.shape},在 Compartment: ${var.compartment_id}'"
}
}

View File

@@ -0,0 +1,21 @@
variable "compartment_id" {
description = "Compartment OCID"
type = string
}
variable "instance_name" {
description = "计算实例名称"
type = string
default = "my-instance"
}
variable "shape" {
description = "实例规格"
type = string
default = "VM.Standard2.1"
}
variable "subnet_id" {
description = "子网 OCID"
type = string
}

View File

@@ -0,0 +1,13 @@
# Oracle VCN 模块示例
# 这是一个示例,实际使用时需要替换为真实的 OCI 资源
resource "null_resource" "vcn_example" {
triggers = {
compartment_id = var.compartment_id
vcn_name = var.vcn_name
}
provisioner "local-exec" {
command = "echo '创建 VCN: ${var.vcn_name}CIDR: ${var.cidr_block},在 Compartment: ${var.compartment_id}'"
}
}

View File

@@ -0,0 +1,9 @@
output "vcn_name" {
description = "VCN 名称"
value = var.vcn_name
}
output "cidr_block" {
description = "CIDR 地址块"
value = var.cidr_block
}

View File

@@ -0,0 +1,22 @@
variable "compartment_id" {
description = "Compartment OCID where the VCN will be created"
type = string
}
variable "vcn_name" {
description = "Name of the VCN"
type = string
default = "my-vcn"
}
variable "cidr_block" {
description = "CIDR block for the VCN"
type = string
default = "10.0.0.0/16"
}
variable "dns_label" {
description = "DNS label for the VCN"
type = string
default = "vcn"
}

26
oracle/us/README.md Normal file
View File

@@ -0,0 +1,26 @@
# Oracle Cloud 美国账号配置
## 配置说明
此目录包含美国 Oracle Cloud 账号的 Terraform 配置。配置使用 `~/.oci/config` 文件中的 `[DEFAULT]` profile。
## 账号信息
- **区域**: us-ashburn-1弗吉尼亚
- **Profile**: DEFAULT
- **密钥文件**: ~/.oci/oci_api_key.pem
## 使用方法
```bash
cd /home/ben/terraform/oracle/us
terraform init
terraform plan
terraform apply
```
## 环境配置
如果需要多环境dev/prod可以考虑
1. 在此目录下创建 `environments/` 子目录
2. 或者使用根目录的共享 `environments/``modules/` 目录
## 注意事项
- 确保 `~/.oci/config` 中的 [DEFAULT] 配置正确
- 美国区域的资源命名和合规要求可能与其他区域不同

20
oracle/us/main.tf Normal file
View File

@@ -0,0 +1,20 @@
terraform {
required_providers {
oci = {
source = "oracle/oci"
version = ">= 4.0.0"
}
}
}
provider "oci" {
# 美国账号配置 - 使用 ~/.oci/config 中的 [DEFAULT] profile
# config_file_profile = "DEFAULT" # 可选DEFAULT 是默认值
# 或者,如果需要覆盖某些配置,可以显式指定:
# tenancy_ocid = "ocid1.tenancy.oc1..aaaaaaaayyhuf6swf2ho4s5acdpee6zssst6j7nkiri4kyfdusxzn3e7p32q"
# user_ocid = "ocid1.user.oc1..aaaaaaaappc7zxue4dlrsjljg4fwl6wcc5smetreuvpqn72heiyvjeeqanqq"
# fingerprint = "36:2f:3e:19:fa:9e:bb:81:30:26:f2:d7:52:d4:1d:88"
# private_key_path = "~/.oci/oci_api_key.pem"
# region = "us-ashburn-1"
}