VCN 모듈 생성

VCN (가상 클라우드 네트워크) 및 게이트웨이를 Terraform 구성의 리소스로 정의하고 모듈에서 사용되는 변수를 선언합니다.

vcn 하위 디렉토리에서 다음 단계를 수행합니다.
  1. variables.tf 라는 텍스트 파일을 생성하고 다음 코드를 파일에 붙여넣습니다.
    이 코드는 이 모듈에서 사용되는 변수를 선언합니다.
    variable "tenancy_ocid" {}
    variable "compartment_ocid" {}
    variable "app_tag" {}
    variable "environment" {}
    variable "vcn_cidr" {}
  2. vcn.tf 라는 텍스트 파일을 생성하고 다음 코드를 파일에 붙여넣습니다.
    이 코드는 VCN, 인터넷 게이트웨이 및 NAT 게이트웨이의 매개변수를 지정합니다.
    resource "oci_core_virtual_network" "base_vcn" {
      cidr_block     = "${var.vcn_cidr}"
      compartment_id = "${var.compartment_ocid}"
      display_name   = "${var.app_tag}_${var.environment}_vcn"
      dns_label      = "${lower(format("%s", var.app_tag))}"
    }
    
    resource "oci_core_internet_gateway" "base_ig" {
      compartment_id = "${var.compartment_ocid}"
      display_name   = "${var.app_tag}_${var.environment}_internetgateway"
      vcn_id         = "${oci_core_virtual_network.base_vcn.id}"
    }
    
    resource "oci_core_nat_gateway" "nat_gateway" {
      compartment_id = "${var.compartment_ocid}"
      vcn_id         = "${oci_core_virtual_network.base_vcn.id}"
      display_name   = "${var.app_tag}_${var.environment}_nat_gateway"
    }

    이 Terraform 구성 예제에서는 서브넷, 보안 목록 및 기타 네트워킹 리소스를 지정하지 않습니다. 필요에 따라 이 구성을 사용자 정의할 수 있습니다.

  3. vcn_output.tf 라는 텍스트 파일을 생성하고 다음 코드를 파일에 붙여넣습니다.
    이 코드는 리소스 Id가 생성된 후 리소스 id를 표시합니다.
    output "vcnid" {
      value = "${oci_core_virtual_network.base_vcn.id}"
    }
    
    output "default_dhcp_id" {
      value = "${oci_core_virtual_network.base_vcn.default_dhcp_options_id}"
    }
    
    output "internet_gateway_id" {
      value = "${oci_core_internet_gateway.base_ig.id}"
    }
    
    output "nat_gateway_id" {
      value = "${oci_core_nat_gateway.nat_gateway.id}"
    }