brunch

5-1. NHN 클라우드- 모듈

by Master Seo
410 module.png


1



# modules/vpc

# main.tf

# var.tf

# Define required providers

terraform {

required_version = ">= 1.0.0"

required_providers {

nhncloud = {

source = "nhn-cloud/nhncloud"

version = "1.0.2"

}

}

}

#VPC 생성 리소스 블록

resource "nhncloud_networking_vpc_v2" "terraform_vpc" {

name = var.vpc_name

cidrv4 = var.vpc_cidr

}

resource "nhncloud_networking_vpcsubnet_v2" "subnets" {

for_each = var.subnets

name = "${each.key}"

vpc_id = nhncloud_networking_vpc_v2.terraform_vpc.id

cidr = each.value

}

# var.tf

variable vpc_name {

type =string

}

variable vpc_cidr {

type =string

}

variable subnets {

type =map(string)

}

# test 폴더

# main.tf

module vpc {

source = "../modules/vpc"

vpc_name = "module_vpc"

vpc_cidr = "192.168.0.0/16"

subnets = {

public = "192.168.1.0/24"

private ="192.168.2.0/24"

}

}

# provider.tf

# Define required providers

terraform {

required_version = ">= 1.0.0"

required_providers {

nhncloud = {

source = "nhn-cloud/nhncloud"

version = "1.0.2"

}

}

}

provider "nhncloud" {

user_name = var.nhncloud_info["user_name"]

tenant_id = var.nhncloud_info["tenant_id"]

password = var.passwd

auth_url = var.nhncloud_info["auth_url"]

region = var.region["kr2"]

}

# var.tf

variable nhncloud_info {

type =map(string)

default = {

user_name = "topasvga@naver.com"

tenant_id = "0cad32d7cf43"

password = "test"

auth_url = "https://api-identity-infrastructure.nhncloudservice.com/v2.0"

}

}

variable passwd {

type = string

default = "test"

sensitive =true

}

variable region {

type = map(string)

default = {

kr1 = "KR1"

kr2 = "KR2"

}

}


keyword
매거진의 이전글4-3. NHN 클라우드 - 데이터 베이스