Terraformとは?
Terraform
Terraformとは?
Google Cloudリソースは、コードインフラストラクチャ(IaC)メソッドで宣言プロファイル(仮想マシン、コンテナ、ストレージ、ネットワークなどのリソース)に構成できるオープンソースツールです.
Google Cloud ## public IP
- 54.x.x.x
- 2.xx
- 34.xx
## private IP
- 10.0.x.x
- 192.168.x.x
- 172.16~32.x.x
セッションにキーを追加するコマンド
## public IP
- 54.x.x.x
- 2.xx
- 34.xx
## private IP
- 10.0.x.x
- 192.168.x.x
- 172.16~32.x.x
ssh-add <key_name>
zshのインストールと適用
# server password
sudo -i
sudo passwd ec2-user
sudo yum install util-linux-user.x86_64 # 아마존 리눅스만
# zsh 설치
sudo yum install zsh
chsh -s /bin/zsh * # 기본쉘은 zsh 로 변경 몇몇 os는 util-linux-user.x86_64 를 설치필요*
AWS CLIのインストール
# Linux x86 (64-bit)
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
# Linux ARM
curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Terraformインストール
curl -sO https://releases.hashicorp.com/terraform/0.12.24/terraform_0.12.24_darwin_amd64.zip
unzip terraform_0.12.24_darwin_amd64.zip
mv terraform /usr/local/bin
aws configureの設定aws configure
aws sts get-caller-identity
Terraformコマンド
terraform init
terraform plan
terraform apply
terraform import
VPC
Amazonが提供する専用ネットワーク.以下は仮想PCの重要なコンポーネントです.
10.0.0.0/8
172.168.0.0/12
192.168.0.0/16
プライベートサブネットとパブリックサブネット
プライベートサブネット
nat gateway
の場合nat gateway
パブリックサブネットに存在パブリックサブネット
internet gateway
の場合Terraformを使用したVPCの作成
provider.tf
# provider
provider "aws" {
region = "ap-northeast-2"
}
vpc.tf
# VPC
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "terraform-101"
}
}
# Subnets
resource "aws_subnet" "public_subnet" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
availability_zone = "ap-northeast-2a"
tags = {
Name = "terraform-101-public-subnet"
}
}
resource "aws_subnet" "private_subnet" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.2.0/24"
availability_zone = "ap-northeast-2b"
tags = {
Name = "terraform-101-private-subnet"
}
}
# IGW
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.main.id
tags = {
Name = "terraform-101-igw"
}
}
# elastic ip for NAT
resource "aws_eip" "nat" {
vpc = true
lifecycle {
create_before_destroy = true
}
}
# NAT Gateway
resource "aws_nat_gateway" "nat_gateway" {
allocation_id = aws_eip.nat_1.id
# Private subnet이 아니라 public subnet을 연결해야한다.
subnet_id = aws_subnet.public.id
tags = {
Name = "terraform-101-NAT-GW-1"
}
}
# Route Table
resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id
# inner rule (IGW와 RT 연결)
route = {
cidr_block = "0.0.0.0/0"
gateway_id = "aws_internet_gateway.igw.id"
}
tags = {
Name = "terraform-101-rt-public"
}
}
resource "aws_route_table" "private" {
vpc_id = aws_vpc.main.id
tags = {
Name = "terraform-101-rt-private"
}
}
# Subnet - Route Table 연결
resource "aws_route_table_association" "route_table_association_public" {
subnet_id = aws_subnet.public_subnet.id
route_table_id = aws_route_table.puvlic.id
}
resource "aws_route_table_association" "route_table_association_private" {
subnet_id = aws_subnet.private_subnet.id
route_table_id = aws_route_table.private.id
}
# NAT와 RT 연결
resource "aws_route" "private_nat" {
route_table_id = aws_route_table.private.id
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat_gateway.id
}
++他のVPCエンドポイントへの接続IAMアカウントの作成
provider "aws" {
region = "ap-northeast-2"
}
resource "aws_iam_user" "gildong_hong" {
name = "gildong.hong"
}
Reference
ウィザードのショートカット
Reference
この問題について(Terraformとは?), 我々は、より多くの情報をここで見つけました https://velog.io/@1yangsh/Terraform-이란テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol