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

Last updated at Posted at 2025-07-08

Terraformをはじめよう

input variable(入力変数)

  • description 用途などかく

  • default デフォルト値がない場合、対話的に入力を求められる。

  • type string,number,bool,list,map etc.. 型定義

  • validation 最大値や最小値など、定義をカスタマイズできる。

  • sensitive ログ出力などの値を秘匿化する

  • 記述例

variable "security_group_name" {
  description = "The name of the security group"
  type        = string
  default     = "terraform-example-instance"
}
  • 参照例 コマンドラインから
terrafrom plan -var "server_port=8080"
  • 参照例 環境変数から
export TF_VAR_server_port=8080
  • 参照例 コードから
var.server_port=8080

output variable(出力変数)

  • description 用途などかく

  • sensitive ログ出力などの値を秘匿化する

  • depends_on ??

  • 記述例

output "public_ip" {
  value       = aws_instance.example.public_ip
  description = "The public IP of the Instance"
}

ステートを管理する

terraform.tfstate(apply実行するとできる。)

ワークスペースによる分離

ファイルレイアウトによる分離

  • トツプレベルフォルダの例
- stage
- prod
- mgmt(DevOpsツール環境、踏み台、CIサーバなど)
- global(全環境をまたぐリソースS3,IAM)
  • セカンド、サードレベル
- vpc(ネットワーク)
- services(アプリケーション群)
-- frontend-app
-- backend-app
- data-storage(データストア用)
  • 各個別フォルダ
- variables.tf(入力変数)
- output.tf(出力変数)
- main.tf(リソースとデータソース)

モジュールで再利用可能なインフラを作る

ヒントとコツ

シークレットを管理する

複数のプロバイダを使う

本番レベルのTerraformコード

Terraformのコードをテストする

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?