Skip to Content
Terraform クックブック
book

Terraform クックブック

by Kerim Satirli, Taylor Dolezal
March 2025
Intermediate to advanced
282 pages
3h 50m
Japanese
O'Reilly Media, Inc.
Content preview from Terraform クックブック

第4章 Terraformのモジュールとプロバイダ Terraformモジュールとプロバイダ

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

モジュール Terraformにおけるモジュールは、グループとして管理されるTerraformコンフィギュレーションの自己完結型パッケージである。コードを再利用可能なコンポーネントにカプセル化し、チームワークとコラボレーションを促進するコードの組織化に使われる。各モジュールには、連携するように設定された複数のリソースを含めることができる。

モジュールは、従来のプログラミング言語における関数と比較することができる。関数のように、モジュールは特定の目的を持ったコードブロックをカプセル化し、異なるコンテキストで再利用することができる。しかし、関数とは異なり、モジュールはコンピューティングを実行するのではなく、リソースのコレクションを管理する。

Terraformモジュールは、ルートレベルのTerraform構成ファイル(.tfファイル)と同じ言語構文で作成される。モジュール設定ブロックを使うことで、他のモジュールやルートモジュールから呼び出すことができる。

モジュールはリソースの整理やコードの再利用に役立つが、Terraformプロバイダは外部APIとやりとりして、それらのリソースを作成、読み取り、更新、削除する。各プロバイダはAPIインタラクションを理解し、リソースを公開する責任がある。

Terraformは、AWS、GCP、Microsoft Azure、その他GitHub、Datadogなど多くのサービスプロバイダと互換性がある。

4.1 パブリックモジュールを使用してEKSクラスタを作成する

問題

AWS内にVPCをセットアップし、今度はKubernetes上でアプリケーションのホスティングを始めたいと考えている。あなたはElastic Kubernetes Service (EKS)クラスタをセットアップし、最初の設定を行いたい。

解決策

Terraform Registryの public AWS EKS moduleを使えば、AWS上でKubernetesクラスタを稼働させるために必要な、コード設定によるインフラのセットアップを効率的に行うことができる。まず、AWSアカウントとEKSクラスタの作成に必要な権限があることを確認する。次に、Terraformレジストリを参照し、"terraform-aws-modules eks "を検索して今回使用するモジュールを見つける。

Terraformレジストリには、モジュールのドキュメント(図4-1を参照)、どのような入力が必要で、どのような出力が提供されるのか、モジュールを使うときに利用できるその他の依存関係やリソースが示されている。

図 4-1. Terraform レジストリ AWS EKS Terraform モジュールリスト

章のVPCモジュールで使用した前回のレシピを基に作成しているので、AWSプロバイダーの再指定やVPCモジュールの再作成は必要ない。

variables.tfファイルは主にセットアップされているが、使用するKubernetesのバージョンや、アプリケーションをEKSクラスタに追加する際にホストするワーカーノードプールをどのように構成するかなど、追加しなければならない変数がまだある。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

入門 Kubernetes

入門 Kubernetes

Kelsey Hightower, Brendan Burns, Joe Beda, 松浦 隼人
AWS クックブック

AWS クックブック

John Culkin, Mike Zazon
Kubernetes クックブック、第 2 版

Kubernetes クックブック、第 2 版

Sameer Naik, Sébastien Goasguen, Jonathan Michaux

Publisher Resources

ISBN: 9798341633247