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?

AWSDKからterraformに移行してみた1

0
Last updated at Posted at 2026-08-17

Terraformを使ってみたい

現在はCDK(Cloud Development Kit)定義をしている。
TypeScriptやPythonなどの一般的プログラミング言語を使って、クラウド上のインフラ構成をコードとして記述・定義する。そして、背後ではCloudFormationが動いていらっしゃる。 JSON/YAML形式
やっていることとしてまとめると下記。

  • TypeScript で AWS リソースを書く

  • CDK がそれを synth(合成)する

  • CloudFormation テンプレートが生成される

  • AWS がそのテンプレートを読み込んでリソースを作る

今はたった1つのファイルでこういう感じになっている。

  • Lambda を作る
  • API Gateway を作る
  • DynamoDB を作る
  • S3 を作る
  • CloudWatch 検知を作る
  • SNS/メール通知を作る
  • Budget を作る

参考(https://qiita.com/Brutus/items/6c8d9bfaab7af53d154a)

せっかく運用業務をしている身なのでより370行ほどのこのファイルをインフラ用に書き換えても悪い気がしないのでそうしたい。

Terraform は

  • plan で差分確認
  • apply で反映
  • state で現在の状態管理

HashiCorp Configuration Language = HCL形式で書かれている、HCLで書いた設定ファイルをTerraformが読み込み、その通りにクラウド上のサーバーやネットワークを自動で作成・変更・削除する。
利点として、最終的にどうしたいのかを定義する(今はコレがガチで足りない)
宣言的構文 を用いられる。
あとは、コードの再利用が可能となるなどの利点。

やること

lambda.Function → aws_lambda_function
apigateway.RestApi → aws_api_gateway_rest_api
dynamodb.Table → aws_dynamodb_table
s3.Bucket → aws_s3_bucket
cloudwatch.Alarm → aws_cloudwatch_metric_alarm
sns.Topic → aws_sns_topic
budgets.CfnBudget → aws_budgets_budget

こういう感じにする!
図は下記
image.png
依存関係ピラミッド
image.png

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?