メモ
- EC2インスタンスを一台作成する
-
参考
記載のURLの通りに実行したメモ
インスタンスの構築
# 作業用ディレクトリ作成
% mkdir terraform-test2
% cd terraform-test2
# configuration codeファイル(日本語訳不明)作成
% touch example.tf
# デプロイするサービスプロバイダの種類(AWS)やリソースの情報を記載する(AMI IDは環境によって有効な値に読み替えること)
% vim example.tf
provider "aws" {
profile = "default"
region = "ap-northeast-1"
}
resource "aws_instance" "example" {
ami = "ami-2757f631"
instance_type = "t2.micro"
}
# 初期化コマンド
# AWSとの連携に必要なファイル類をダウンロードするらしい
% terraform init
# フォーマット & バリデーション
# ファイルのフォーマッティングをしてくれる。インデントとか
% terraform fmt
# バリデーション
% terraform validate
# リソース作成
# `yes` と入力を求められるプロンプトが表示される
% terraform apply
...
# リソース確認
% terraform show
インスタンスのタイプ変更
# t2.micro -> t2.large に変更
% vim example.tf
provider "aws" {
profile = "default"
region = "ap-northeast-1"
}
resource "aws_instance" "example" {
ami = "ami-2757f631"
instance_type = "t2.large"
}
# 変更実行
# 勝手にインスタンス止めて、起動させてくれる。すごい。
% terraform apply
インスタンスの削除
% terraform destroy
参考
Build Infrastructure | Terraform - HashiCorp Learn https://learn.hashicorp.com/terraform/getting-started/build