Cloud Infra Architecture (AWS)/AWS Terraform

Terraform VPC, subnet 생성

seongduck 2024. 2. 4. 19:28

1) Provicder.tf 생성

vim provider

"
provider "aws" {
	region = "ap-northeast-1"
}
"

 

2) VPC 생성

vim vpc.tf

"
resource "aws_vpc" "main" {
	cidr_block = "ip대역"
    
    tage = {
    Name = "vpc-dev-ircp"
    }
}

 

3) terraform init - plan - apply

terraform init

terraform plan

terraform apply

 

 

2) Subnet 생성

vim vpc.tf //vpc를 만든 곳에 subnet 코드 작성

"
resource "aws_subent" "sbn-dev-ircp-public-resource-az2a" {
	vpc_id = aws_vpc.main.id
    cidr_block = "ip대역"
    
    availability_zone = "ap-northeast-1a"
    
    tags = {
    	Name = "sbn-dev-ircp-public-resource-az2a"
    }
}

resource "aws_subent" "sbn-dev-ircp-public-resource-az2c" {
	vpc_id = aws_vpc.main.id
    cidr_block = "ip대역"
    
    availability_zone = "ap-northeast-1a"
    
    tags = {
    	Name = "sbn-dev-ircp-public-resource-az2c"
    }
}
"

 

terraform plan

terraform apply

 

terraform state list