~>非推奨のお知らせ Equinix Metalは、2026年6月30日 をもってサービスを終了します。すべてのMetalデータソースは、このプロバイダのバージョン5.0.0で削除されます。廃止までの継続利用には、このプロバイダのバージョン4.xをご利用ください。詳細は https://docs.equinix.com/metal/ をご覧ください。
エクイニクス_メタルプラン
Equinix Metal plansデータソースを提供します。フィルター条件を満たすプランを検索するために使用できます。
使用例
# Following example will select device plans which are under 2.5$ per hour, are available in metro 'da' (Dallas)
# OR 'sv' (Sillicon Valley) and sort it by the hourly price ascending.
data "equinix_metal_plans" "example" {
sort {
attribute = "pricing_hour"
direction = "asc"
}
filter {
attribute = "pricing_hour"
values = [2.5]
match_by = "less_than"
}
filter {
attribute = "available_in_metros"
values = ["da", "sv"]
}
}
output "plans" {
value = data.equinix_metal_plans.example.plans
}
# Following example will select device plans with class containing string 'large', are available in metro 'da' (Dallas)
# AND 'sv' (Sillicon Valley), are elegible for spot_market deployments.
data "equinix_metal_plans" "example" {
filter {
attribute = "class"
values = ["large"]
match_by = "substring"
}
filter {
attribute = "deployment_types"
values = ["spot_market"]
}
filter {
attribute = "available_in_metros"
values = ["da", "sv"]
all = true
}
}
output "plans" {
value = data.equinix_metal_plans.example.plans
}
プラン変更の無視/メトロ
新しい実行プランを作成する際に、デプロイ済みのデバイスプラン、施設、メトロを保持します。
data-resource-behaviorで説明したように、terraformはterraform planコマンドとterraform applyコマンドの両方で計画フェーズ中にデータリソースを読み込みます。データソースからの出力が以前の状態と異なる場合、その属性への参照があるリソースに対して変更を提案します。
equinix_metal_plansの場合、デバイスプランがメトロで在庫がないため利用できなくなったり、レガシーサーバプランを利用していたため、検索条件に一致するプランのリストが前回plan/applyと異なることがあります。したがって、equinix_metal_deviceのようなリソースがこのデータソースの出力を使ってデバイスプランやメトロを選択すると、Terraformプランはequinix_metal_deviceを再作成する必要があると報告します。
これを防ぐには、以下の例のように Terraform lifecycle ignore_changes 機能を利用します。
# Following example will use equinix_metal_plans to select the cheapest plan available in metro 'sv' (Sillicon Valley)
data "equinix_metal_plans" "example" {
sort {
attribute = "pricing_hour"
direction = "asc"
}
filter {
attribute = "name"
values = ["c3.small.x86", "c3.medium.x86", "m3.large.x86"]
}
filter {
attribute = "available_in_metros"
values = ["sv"]
}
}
# This equinix_metal_device will use the first returned plan and the first metro in which that plan is available
# It will ignore future changes on plan and metro
resource "equinix_metal_device" "example" {
hostname = "example"
plan = data.equinix_metal_plans.example.plans[0].name
metro = data.equinix_metal_plans.example.plans[0].available_in_metros[0]
operating_system = "ubuntu_24_04"
billing_cycle = "hourly"
project_id = var.project_id
lifecycle {
ignore_changes = [
plan,
metro,
]
}
}
ユースケースでデバイスプランやメトロの動的な変更が必要な場合、条件でライフサイクルを定義できます。
# Following example uses a boolean variable that may eventually be set to you false when you update your equinix_metal_plans filter criteria because you need a device plan with a new feature.
variable "ignore_plans_metros_changes" {
type = bool
description = "If set to true, it will ignore plans or metros changes"
default = false
}
data "equinix_metal_plans" "example" {
// new search criteria
}
resource "equinix_metal_device" "example" {
// required device arguments
lifecycle {
ignore_changes = var.ignore_plans_metros_changes ? [
plan,
metro,
] : []
}
}
引数リファレンス
以下の引数をサポートしています:
sort- (オプ シ ョ ナル) 結果を ソ ー ト する属性 / 方向のペアを 1 つ以上指定 し ます。複数のソートが指定された場合、以下の順序で適用されます。attribute- (必須)結果の並べ替えに使用する属性。ソート属性は大文字と小文字を区別しますdirection- (オプション)結果を昇順または降順に並べ替えます。文字列はアルファベット順に並べ替えられます。asc, desc のいずれか
filter- (オプション)フィルタリングする 1 つ以上の属性と値のペアattribute- (必須)フィルタリングに使用する属性。フィルタ属性は大文字と小文字を区別します。values- (必須)フィルタ値。フィルター値は大文字と小文字を区別します。フィルターに複数の値を指定した場合、デフォルトでは値は OR で結合され、リクエストは指定された値のいずれかに一致するすべての結果を返します。match_by- (オプション)適用する比較のタイプ。のいずれかです:in,re,substring,less_than,less_than_or_equal,greater_than,greater_than_or_equal.デフォルトはinです。all- (オプション) true に設定すると、値は AND で結合され、要求 は指定されたすべての値に一致する結果のみを返します。デフォルトはfalseです。
以下に定義する plans ブロックのすべてのフィールドは、sort と filter ブロックの両方の属性として使用できます。
属性リファレンス
上記のすべての引数に加えて、以下の属性がエクスポートされます:
plansid- プランの IDname- プラン名slug- プランスラグdescription- 計画の説明line- プランライン、例:ベアメタルlegacy- レガシープランかどうかを示すフラグclass- プランクラスpricing_hour-プラン時間単価pricing_month-プラン月額料金deployment_types- デプロイメントタイプのリスト(例:オンデマンド、スポットマーケットavailable_in- (非推奨) プランが利用可能な施設のリストavailable_in_metros- プランが利用可能なメトロのリスト