109 lines
3.0 KiB
HCL
109 lines
3.0 KiB
HCL
# 检查 ash2e 实例状态
|
|
terraform {
|
|
required_providers {
|
|
oci = {
|
|
source = "oracle/oci"
|
|
version = "~> 7.0"
|
|
}
|
|
consul = {
|
|
source = "hashicorp/consul"
|
|
version = "~> 2.22"
|
|
}
|
|
}
|
|
}
|
|
|
|
# 从 Consul 获取美国区域配置
|
|
data "consul_keys" "oracle_config_us_check" {
|
|
key {
|
|
name = "tenancy_ocid"
|
|
path = "config/dev/oracle/us/tenancy_ocid"
|
|
}
|
|
key {
|
|
name = "user_ocid"
|
|
path = "config/dev/oracle/us/user_ocid"
|
|
}
|
|
key {
|
|
name = "fingerprint"
|
|
path = "config/dev/oracle/us/fingerprint"
|
|
}
|
|
key {
|
|
name = "private_key_path"
|
|
path = "config/dev/oracle/us/private_key_path"
|
|
}
|
|
key {
|
|
name = "region"
|
|
path = "config/dev/oracle/us/region"
|
|
}
|
|
}
|
|
|
|
# 配置美国区域 Provider
|
|
provider "oci" {
|
|
alias = "us_check"
|
|
tenancy_ocid = data.consul_keys.oracle_config_us_check.var.tenancy_ocid
|
|
user_ocid = data.consul_keys.oracle_config_us_check.var.user_ocid
|
|
fingerprint = data.consul_keys.oracle_config_us_check.var.fingerprint
|
|
private_key_path = data.consul_keys.oracle_config_us_check.var.private_key_path
|
|
region = data.consul_keys.oracle_config_us_check.var.region
|
|
}
|
|
|
|
# 获取美国区域的所有实例
|
|
data "oci_core_instances" "us_instances" {
|
|
provider = oci.us_check
|
|
compartment_id = data.consul_keys.oracle_config_us_check.var.tenancy_ocid
|
|
}
|
|
|
|
# 获取美国区域的所有磁盘卷
|
|
data "oci_core_volumes" "us_volumes" {
|
|
provider = oci.us_check
|
|
compartment_id = data.consul_keys.oracle_config_us_check.var.tenancy_ocid
|
|
}
|
|
|
|
# 获取美国区域的所有启动卷
|
|
data "oci_core_boot_volumes" "us_boot_volumes" {
|
|
provider = oci.us_check
|
|
availability_domain = "TZXJ:US-ASHBURN-AD-1"
|
|
compartment_id = data.consul_keys.oracle_config_us_check.var.tenancy_ocid
|
|
}
|
|
|
|
# 输出所有实例信息
|
|
output "us_instances_status" {
|
|
value = {
|
|
for instance in data.oci_core_instances.us_instances.instances :
|
|
instance.display_name => {
|
|
id = instance.id
|
|
state = instance.state
|
|
shape = instance.shape
|
|
availability_domain = instance.availability_domain
|
|
time_created = instance.time_created
|
|
}
|
|
}
|
|
description = "美国区域所有实例状态"
|
|
}
|
|
|
|
# 输出磁盘状态 - 关键信息!
|
|
output "us_volumes_status" {
|
|
value = {
|
|
for volume in data.oci_core_volumes.us_volumes.volumes :
|
|
volume.display_name => {
|
|
id = volume.id
|
|
state = volume.state
|
|
size_in_gbs = volume.size_in_gbs
|
|
time_created = volume.time_created
|
|
}
|
|
}
|
|
description = "美国区域所有数据磁盘状态"
|
|
}
|
|
|
|
# 输出启动磁盘状态 - 更关键!
|
|
output "us_boot_volumes_status" {
|
|
value = {
|
|
for boot_volume in data.oci_core_boot_volumes.us_boot_volumes.boot_volumes :
|
|
boot_volume.display_name => {
|
|
id = boot_volume.id
|
|
state = boot_volume.state
|
|
size_in_gbs = boot_volume.size_in_gbs
|
|
time_created = boot_volume.time_created
|
|
}
|
|
}
|
|
description = "美国区域所有启动磁盘状态 - ash2e 的配置可能还在这里!"
|
|
} |