1
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の基本概念、用語の意味

1
Posted at

概要

Terraformを扱う上での概念のうち、基本となる次の4つの概念について自分なりに分かりやすくまとめました。

  • リソース(Resource)
  • リソースモジュール(Resource Module)
  • インフラモジュール(Infrastructure Module)
  • コンポジション(Composition)

リソース(Resource)

最小単位となるパーツ。

例) AWSでいうVPCやsecurity groupなど

resource "aws_lb" "this" {
 ...
}

リソースモジュール(Resource Module)

1つの目的を達成するために関連するリソースを寄せ集めて作ります。

例 AWS ALB
AWS ALBを作る場合、

  • ALB本体
  • Lister(リクエストを受け付けるルールを設定するもの、80ポートのリクエストをこのターゲットグループに送りますみたいな)
  • Target Group: ALB経由でリクエストを受け付ける(ターゲット)の集まり

の3つのリソース は必要になります。多くの場合、これで1つのリソースモジュールを作ります。

// modules/alb/main.tf
resource "aws_lb" "this" {
 ...
}

resource "aws_lb_target_group" "this" {
  ...
}

resource "aws_lb_listener" "https" {
  ...
}

resource "aws_lb_listener" "http" {
  ...
}

インフラモジュール(Infrastructure Module)

本番環境を作るや、会社のプロジェクトなど、何かの目的を達成するためのリソースモジュールの集まり。


会社でよくある構成として、productionとstaging環境など環境ごとに分けているケースはよくあると思います。
その場合は environments/productionなどが1つのインフラモジュールになります。

terraform/
├── modules/           # リソースモジュール
│   ├── acm/           # SSL証明書
│   ├── alb/           # Application Load Balancer
│   ├── aurora/        # Aurora PostgreSQL
│   ├── ecr/           # Container Registry
│   ├── ecs/           # ECS Fargate
│   ├── route53/       # DNS (Public/Private)
│   ├── security_groups/ # Security Groups
│   └── vpc/           # VPC, Subnets, NAT Gateway
├── environments/      # インフラモジュール
│   ├── prod/          # Production環境
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   ├── outputs.tf
│   │   ├── versions.tf
│   │   └── terraform.tfvars
│   └── stag/          # Staging環境
│       ├── main.tf
│       ├── variables.tf
│       ├── outputs.tf
│       ├── versions.tf
│       └── terraform.tfvars

コンポジション(Composition)

インフラモジュールの集まり。リージョンやaws accountなど分け方はさまざま。
先ほどのインフラモジュールの例で言うと、production + stagingで1つのcompositionと見ることができる。この場合、repositoryそのものが1つのcompositionとみてもよさそう。

まとめ

ここら辺の概念がいまいち掴めず、結果記事の内容がよくわからないと言うことはあったので、自分の中で整理する意味において、記事を書いてとてもよかったです。また、terraformは英語の資料が多いので、日本語で書いた記事として誰かの助けになるといいなと思いました。

参考文献

1
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
1
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?