# 开发环境主配置文件

# 引入共享版本配置
terraform {
  required_version = ">= 1.6"
  
  required_providers {
    # Oracle Cloud Infrastructure
    oci = {
      source  = "oracle/oci"
      version = "~> 5.0"
    }
    
    # 华为云
    huaweicloud = {
      source  = "huaweicloud/huaweicloud"
      version = "~> 1.60"
    }
    
    # 其他常用提供商
    random = {
      source  = "hashicorp/random"
      version = "~> 3.1"
    }
    
    tls = {
      source  = "hashicorp/tls"
      version = "~> 4.0"
    }
    
    local = {
      source  = "hashicorp/local"
      version = "~> 2.1"
    }
  }
  
  # 后端配置
  backend "local" {
    path = "terraform.tfstate"
  }
}

# Oracle Cloud 提供商配置
provider "oci" {
  tenancy_ocid     = var.oci_config.tenancy_ocid
  user_ocid        = var.oci_config.user_ocid
  fingerprint      = var.oci_config.fingerprint
  private_key_path = var.oci_config.private_key_path
  region           = var.oci_config.region
}

# 华为云提供商配置 (仅在需要时配置)
provider "huaweicloud" {
  access_key = var.huawei_config.access_key
  secret_key = var.huawei_config.secret_key
  region     = var.huawei_config.region
  alias      = "huawei"
}

# Oracle Cloud 基础设施
module "oracle_cloud" {
  source = "../../providers/oracle-cloud"
  
  # 传递变量
  environment    = var.environment
  project_name   = var.project_name
  owner          = var.owner
  vpc_cidr       = var.vpc_cidr
  availability_zones = var.availability_zones
  common_tags    = var.common_tags
  oci_config     = var.oci_config
  
  # 开发环境特定配置
  instance_count = 1
  instance_size  = "VM.Standard.E2.1.Micro"  # 免费层
  
  providers = {
    oci = oci
  }
}

# 华为云基础设施 (可选)
module "huawei_cloud" {
  source = "../../providers/huawei-cloud"
  count  = contains(var.cloud_providers, "huawei") ? 1 : 0
  
  environment    = var.environment
  project_name   = var.project_name
  owner          = var.owner
  vpc_cidr       = "10.1.0.0/16"  # 不同的 CIDR 避免冲突
  availability_zones = var.availability_zones
  common_tags    = var.common_tags
  huawei_config  = var.huawei_config
  
  providers = {
    huaweicloud = huaweicloud.huawei
  }
}

# 输出
output "oracle_cloud_outputs" {
  description = "Oracle Cloud 基础设施输出"
  value       = module.oracle_cloud
}

output "huawei_cloud_outputs" {
  description = "华为云基础设施输出"
  value       = length(module.huawei_cloud) > 0 ? module.huawei_cloud[0] : null
}