TerraformでDynamoDB構築
dynamodbのresource定義も補完される
terraformのmain.tfファイルを作成する
code:main.tf
provider "aws" {
profile = "dynamodb_test"
region = "ap-northeast-1"
access_key = "???"
secret_key = "???"
}
resource "aws_dynamodb_table" "basic-dynamodb-table" {
name = "basic-dynamodb-table"
billing_mode = "PAY_PER_REQUEST"
hash_key = "UserId"
range_key = "GameTitle"
attribute {
name = "UserId"
type = "S"
}
attribute {
name = "GameTitle"
type = "S"
}
}
terraform initで初期化
terraform planで実行計画
問題があったらinit や planで指摘される
terraform applyを実行するとDynamoDBのテーブルが作成された
https://gyazo.com/e09307f438b629a20d5b00fe3db3b292
terraform destroy の実行でテーブルが破棄された
https://gyazo.com/20f417e64e435f3b3e4e4252bf66a6c3