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?

AWSSDKからterraformに移行してみた3

0
Last updated at Posted at 2026-08-19
cd infra/terraform
terraform init
terraform plan

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/aws versions matching ">= 5.0.0"...
- Installing hashicorp/aws v6.60.0...
- Installed hashicorp/aws v6.60.0 (signed by HashiCorp)

Terraform has created a lock file .terraform.lock.hcl to record the provider

~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~~~~~ ~~~~ ~~~~ ~~~~ 
Plan: 4 to add, 0 to change, 0 to destroy.

AWSに4つのリソースを新規作成できた。既存リソースの変更なし
リソース削除なしって感じになる。
省略はしたが
main.tfで定義した

DynamoDB
S3バケット
S3のパブリックアクセスブロック設定
S3の暗号化設定

そこからoutputs.tfで定義したvalueの値を出力させるところも完成させられている。ok

次の工程に入る。
では次は、↑をterraform importで指定してあげる。

importとは既存のクラウドリソースを Terraform の state に「紐づける」操作。リソースを作り直さない。

そうするとStateになる。
State(状態): Terraform が「実際に管理しているリソース一覧とそのID」を保持するファイル(ローカルかリモート)。

一回planしたら差分をチェックしていくだけでいい。main.tfのリソースで書き換えがあるなら。

(中略)

import 後に差分確認

yokoyamatowa@yokoyamadaidaiwanoMacBook-Air terraform % terraform plan -out=tfplan
terraform show -no-color tfplan > plan.txt

人間が読みやすい形式にして出力。
okでは現状を整理
図の各要素のステータス

API Gateway(aws_api_gateway_*): 未定義(Terraform側) → 未着手
Lambda(aws_lambda_function): 未定義 → 未着手
DynamoDB(aws_dynamodb_table.session): importでplanまでしている
S3 バケット(slides_raw):  importでplanまでしている
CloudWatch Alarm / SNS / Budgets: 未定義 → 未着手

次に移っていく。

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?