![見出し画像](https://assets.st-note.com/production/uploads/images/111854548/rectangle_large_type_2_6d7071faadd8a8222f40754f617cb21f.png?width=1200)
Terraform Cloud事始めメモ#2|AWS
Build Infrastructure
With Terraform installed, you are ready to create your first infrastructure.
In this tutorial, you will provision an EC2 instance on Amazon Web Services (AWS). EC2 instances are virtual machines running on AWS, and a common component of many infrastructure projects.
必須条件(状態)
The Terraform CLI (1.2.0+) installed.
The AWS CLI installed.
AWS account and associated credentials that allow you to create resources.
あ〜やっぱしAccessキーとシークレットキー必要なのか…
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
Write configuration
ワーキングディレクトリをローカルに作って〜のところ
mkdir learn-terraform-aws-instance
cd learn-terraform-aws-instance
touch main.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.16"
}
}
required_version = ">= 1.2.0"
}
provider "aws" {
region = "ap-northeast-1"
}
resource "aws_instance" "app_server" {
ami = "ami-830c94e3"
instance_type = "t2.micro"
tags = {
Name = "ExampleAppServerInstance"
}
}
Initialize the directory
terraform init
Format and validate the configuration
フォーマットしてくれる。フォーマットする箇所がなければ何もアウトプットしない。
terraform fmt
terraform validate
Create infrastructure
terraform apply
When you applied your configuration, Terraform wrote data into a file called terraform.tfstate. Terraform stores the IDs and properties of the resources it manages in this file, so that it can update or destroy those resources going forward.
The Terraform state file is the only way Terraform can track which resources it manages, and often contains sensitive information, so you must store your state file securely and restrict access to only trusted team members who need to manage your infrastructure. In production, we recommend storing your state remotely with Terraform Cloud or Terraform Enterprise. Terraform also supports several other remote backends you can use to store and manage your state.
構成を適用すると、Terraform は terraform.tfstate というファイルにデータを書き込みます。 Terraform は、管理するリソースの ID とプロパティをこのファイルに保存するため、今後これらのリソースを更新または破棄できるようになります。 Terraform 状態ファイルは、Terraform が管理するリソースを追跡できる唯一の方法であり、機密情報が含まれることが多いため、状態ファイルを安全に保存し、インフラストラクチャを管理する必要がある信頼できるチーム メンバーのみにアクセスを制限する必要があります。運用環境では、Terraform Cloud または Terraform Enterprise を使用して状態をリモートに保存することをお勧めします。 Terraform は、状態の保存と管理に使用できる他のいくつかのリモート バックエンドもサポートしています。
terraform show
Manually Managing State
terraform state list
tfファイルで作成したリソースのリストが出る
この記事が気に入ったらサポートをしてみませんか?