본문 바로가기

퍼블릭 클라우드

[Terraform] 테라폼 서브넷 생성

반응형

서브넷 생성

(선행 작업)

- VPC 생성

 

subnets.tf 파일 생성

$ vim subnet.tf
###Subnet 생성
# Public(WEB)
resource "aws_subnet" "sangchul_vpc11-sb3" {
	vpc_id                  = aws_vpc.sangchul_vpc11.id
	cidr_block              = "10.11.3.0/24"
    map_public_ip_on_launch = true
	availability_zone       = "us-east-1a"
    tags = {
        Name                = "sangchul_vpc11-sb3"
        Env                 = "stg"
        CreateUser          = "terraform@email.com"
        Owner               = "iac"
        Role                = "subnet"
        Service             = "network"
    }
}
resource "aws_subnet" "sangchul_vpc11-sb4" {
	vpc_id                  = aws_vpc.sangchul_vpc11.id
	cidr_block              = "10.11.4.0/24"
    map_public_ip_on_launch = true
	availability_zone       = "us-east-1c"
    tags = {
        Name                = "sangchul_vpc11-sb4"
        Env                 = "stg"
        CreateUser          = "terraform@email.com"
        Owner               = "iac"
        Role                = "subnet"
        Service             = "network"
    }
}
# Private(DB)
resource "aws_subnet" "sangchul_vpc11-sb13" {
	vpc_id                  = aws_vpc.sangchul_vpc11.id
	cidr_block              = "10.11.13.0/24"
	availability_zone       = "us-east-1a"
    tags = {
        Name                = "sangchul_vpc11-sb13"
        Env                 = "stg"
        CreateUser          = "terraform@email.com"
        Owner               = "iac"
        Role                = "subnet"
        Service             = "network"
    }
}
resource "aws_subnet" "sangchul_vpc11-sb14" {
	vpc_id                  = aws_vpc.sangchul_vpc11.id
	cidr_block              = "10.11.14.0/24"
	availability_zone       = "us-east-1c"
    tags = {
        Name                = "sangchul_vpc11-sb14"
        Env                 = "stg"
        CreateUser          = "terraform@email.com"
        Owner               = "iac"
        Role                = "subnet"
        Service             = "network"
    }
}

terraform apply 명령 실행

$ terraform apply
aws_vpc.sangchul_vpc11: Refreshing state... [id=vpc]

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

...

Plan: 4 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_subnet.sangchul_vpc11-sb14: Creating...
aws_subnet.sangchul_vpc11-sb13: Creating...
aws_subnet.sangchul_vpc11-sb4: Creating...
aws_subnet.sangchul_vpc11-sb3: Creating...
aws_subnet.sangchul_vpc11-sb14: Creation complete after 3s [id=subnet]
aws_subnet.sangchul_vpc11-sb13: Creation complete after 3s [id=subnet]
aws_subnet.sangchul_vpc11-sb4: Creation complete after 4s [id=subnet]
aws_subnet.sangchul_vpc11-sb3: Creation complete after 4s [id=subnet]

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