0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【簡単Terraform】【初心者向け】Terraform `output` で値を出力する方法

Posted at

🏗️ はじめに

Terraform を使ってインフラを構築していると、 「作成した VPC の ID
を確認したい」「Subnet ID を他のモジュールで使いたい」
といった場面によく遭遇します。

そんなときに活躍するのが output です。

本記事では、Terraform の output の基本的な使い方 から、
モジュール間で値を受け渡す実践的な用例
までを分かりやすく解説します。

📤 Terraform output とは?

output は、Terraform で作成したリソースの情報を
実行結果として表示したり、他のモジュールへ渡したりするための仕組み
です。

🧩 基本的な output の書き方

resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
}

output "vpc_id" {
  value = aws_vpc.main.id
}

🔗 用例:VPC ID を他のモジュールへ渡す

module "vpc" {
  source = "./modules/vpc"
}

resource "aws_subnet" "main" {
  vpc_id = module.vpc.vpc_id
}

🧠 まとめ

  • output は Terraform の戻り値として利用できる
  • module 間の値の受け渡しに非常に便利
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?