본문 바로가기

퍼블릭 클라우드

[Terraform] 테라폼 라우팅 테이블 생성

반응형

라우팅 테이블 생성

(선행 작업)

- VPC 생성

 

rtb.tf 파일 생성

$ vim rtb.tf
###라우팅 테이블 생성
#Public default route table
resource "aws_default_route_table" "sangchul_vpc11-rt" {
    default_route_table_id  = aws_vpc.sangchul_vpc11.default_route_table_id
    route {
        cidr_block          = "0.0.0.0/0"
        gateway_id          = aws_internet_gateway.sangchul_vpc11-igw.id
    }
    tags = {
        Name                = "sangchul_vpc11-rt"
        Env                 = "stg"
        CreateUser          = "terraform@email.com"
        Owner               = "iac"
        Role                = "route"
        Service             = "network"
    }
}
#Private route table
resource "aws_route_table" "sangchul_vpc11-rt-pri01" {
    vpc_id                  = aws_vpc.sangchul_vpc11.id
    tags = {
        Name                = "sangchul_vpc11-rt-pri01"
        Env                 = "stg"
        CreateUser          = "terraform@email.com"
        Owner               = "iac"
        Role                = "route"
        Service             = "network"
    }
}

###서브넷 연결
#route table association(WEB)
resource "aws_route_table_association" "sangchul_vpc11-sb3" {
	subnet_id               = aws_subnet.sangchul_vpc11-sb3.id
	route_table_id          = aws_vpc.sangchul_vpc11.default_route_table_id
}
resource "aws_route_table_association" "sangchul_vpc11-sb4" {
	subnet_id               = aws_subnet.sangchul_vpc11-sb4.id
	route_table_id          = aws_vpc.sangchul_vpc11.default_route_table_id
}
#route table association(DB)
resource "aws_route_table_association" "sangchul_vpc11-sb13" {
	subnet_id               = aws_subnet.sangchul_vpc11-sb13.id
	route_table_id          = aws_route_table.sangchul_vpc11-rt-pri01.id
}
resource "aws_route_table_association" "sangchul_vpc11-sb14" {
	subnet_id               = aws_subnet.sangchul_vpc11-sb14.id
	route_table_id          = aws_route_table.sangchul_vpc11-rt-pri01.id
}

terraform apply 명령 실행

$ terraform apply
aws_vpc.sangchul_vpc11: Refreshing state... [id=vpc]
aws_route_table.sangchul_vpc11-rt-pri01: Refreshing state... [id=rtb]
aws_subnet.sangchul_vpc11-sb13: Refreshing state... [id=subnet]
aws_subnet.sangchul_vpc11-sb4: Refreshing state... [id=subnet]
aws_internet_gateway.sangchul_vpc11-igw: Refreshing state... [id=igw]
aws_subnet.sangchul_vpc11-sb14: Refreshing state... [id=subnet]
aws_subnet.sangchul_vpc11-sb3: Refreshing state... [id=subnet]
aws_default_route_table.sangchul_vpc11-rt: Refreshing state... [id=rtb]
aws_route_table_association.sangchul_vpc11-sb13: Refreshing state... [id=rtbassoc]
aws_route_table_association.sangchul_vpc11-sb14: Refreshing state... [id=rtbassoc]
aws_route_table_association.sangchul_vpc11-sb3: Refreshing state... [id=rtbassoc]
aws_route_table_association.sangchul_vpc11-sb4: Refreshing state... [id=rtbassoc]

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

...

Plan: 3 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_route_table.sangchul_vpc11-rt-pri01: Creating...
aws_route_table.sangchul_vpc11-rt-pri01: Creation complete after 3s [id=rtb]
aws_route_table_association.sangchul_vpc11-sb13: Creating...
aws_route_table_association.sangchul_vpc11-sb14: Creating...
aws_route_table_association.sangchul_vpc11-sb13: Creation complete after 1s [id=rtbassoc]
aws_route_table_association.sangchul_vpc11-sb14: Creation complete after 1s [id=rtbassoc]

Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
728x90
반응형