トップ 差分 一覧 ソース 検索 ヘルプ RSS ログイン

Terraform

[Linux]

Terraform

  検討

    • dev: 開発環境
    • stg: ステージング環境
    • prd: 本番環境

  インストール

  • Download Terraform
    • Windowsだとバイナリ1つで構成される、msys2の/usr/bin/以下に入れた

  ことはじめ

Build Infrastructure を読む

  • AWSの秘密情報
    • アクセスキーをGitにコミットしたくないので、~/.aws/credentialsに以下を作成
[default]
aws_access_key_id = XXXXXXXXXXXXXXXXX
aws_secret_access_key = YYYYYYYYYYYYYYYYYYYYYYYYY
  • example.tf
    • 以下をexample.tfとして保存(コメントアウトしているが、ここにアクセスキーを書くこともできる)
    • 設定ファイルをS3に入れる設定にする(Backend Type: s3 - Terraform by HashiCorp
provider "aws" {
  # access_key = "ACCESS_KEY_HERE"
  # secret_key = "SECRET_KEY_HERE"
  region     = "ap-northeast-1"
}

terraform {
  backend "s3" {
    bucket  = "my-tfstate-store-name-at-s3" # bucket名
    key     = "hogehoge/terraform.tfstate"  # tfstateファイルの保存先
    region  = "ap-northeast-1"
    profile = "my-profile-name"             # プロファイル(アクセスキーが1つなら不要)
  }
}
  • init実行
    • いい感じのログが出る
$ terraform init

Initializing the backend...

Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.

Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "aws" (1.26.0)...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.aws: version = "~> 1.26"

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
お名前: コメント: