Skip to content

Commit

Permalink
Merge pull request #100 from yunkon-kim/241104-19
Browse files Browse the repository at this point in the history
Add NCP MongoDB and Object Storage examples
  • Loading branch information
yunkon-kim authored Nov 8, 2024
2 parents 48ab382 + c65b903 commit c433330
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 54 deletions.
79 changes: 79 additions & 0 deletions examples/ncp/monogodb-instance/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
terraform {

# Required Tofu version
required_version = "~>1.8.3"

required_providers {
ncloud = {
source = "NaverCloudPlatform/ncloud"
version = "3.2.1"
}
}
}

provider "ncloud" {
access_key = var.ncloud_access_key
secret_key = var.ncloud_secret_key
region = "KR" # Set the desired region (e.g., "KR", "JP", etc.)
support_vpc = true # Enable VPC support
}

# Declare variables
variable "ncloud_access_key" {
description = "Naver Cloud Platform Access Key"
type = string
default = "" # Leave the default value empty
}

variable "ncloud_secret_key" {
description = "Naver Cloud Platform Secret Key"
type = string
default = "" # Leave the default value empty
}

# Declare MongoDB admin user
variable "mongodb_user_name" {
description = "MongoDB admin username"
type = string
default = "dbadmin" # 기본 관리자 사용자명
}

# Declare MongoDB admin password
variable "mongodb_user_password" {
description = "MongoDB admin password"
type = string
sensitive = true # 민감 정보로 표시
default = "P@ssw0rd!" # 기본 관리자 비밀번호
}

# Create VPC
resource "ncloud_vpc" "example" {
name = "tofu-vpc-mongodb"
ipv4_cidr_block = "10.0.0.0/16" # CIDR block for the VPC
}

# Create Network ACL
resource "ncloud_network_acl" "nacl" {
vpc_no = ncloud_vpc.example.id
}

# Create Subnet
resource "ncloud_subnet" "example" {
name = "tofu-subnet-mongodb"
vpc_no = ncloud_vpc.example.vpc_no
subnet = cidrsubnet(ncloud_vpc.example.ipv4_cidr_block, 8, 0) # "10.0.0.0/24" CIDR block for the subnet
zone = "KR-1" # Availability zone
network_acl_no = ncloud_vpc.example.default_network_acl_no # Network ACL number
subnet_type = "PUBLIC" # Subnet type
}

# Create MongoDB instance
resource "ncloud_mongodb" "mongodb" {
vpc_no = ncloud_vpc.example.id
subnet_no = ncloud_subnet.example.id
service_name = "tofu-mongodb"
server_name_prefix = "tf-svr"
user_name = var.mongodb_user_name # Admin username (variable used)
user_password = var.mongodb_user_password # Admin password (variable used)
cluster_type_code = "STAND_ALONE"
}
9 changes: 9 additions & 0 deletions examples/ncp/monogodb-instance/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

output "mongodbInfo" {
description = "Information MongoDB instance"
value = {
service_name = ncloud_mongodb.mongodb.service_name
instance_id = ncloud_mongodb.mongodb.id
cluster_type = ncloud_mongodb.mongodb.cluster_type_code
}
}
108 changes: 54 additions & 54 deletions examples/ncp/db-instance/main.tf → examples/ncp/mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,64 +41,64 @@ variable "ncloud_secret_key" {
# default = "SVR.VSV2.C004.M002.NET.SSD.B050.G002" # Example: 2 vCPU, 4GB RAM
# }

#Server Image Type & Product Type
data "ncloud_server_image" "server_image" {
filter {
name = "product_name"
values = ["ubuntu-20.04"]
}
# image list
# + "SW.VSVR.OS.LNX64.CNTOS.0703.B050" = "centos-7.3-64"
# + "SW.VSVR.OS.LNX64.CNTOS.0708.B050" = "CentOS 7.8 (64-bit)"
# + "SW.VSVR.OS.LNX64.UBNTU.SVR1604.B050" = "ubuntu-16.04-64-server"
# + "SW.VSVR.OS.LNX64.UBNTU.SVR1804.B050" = "ubuntu-18.04"
# + "SW.VSVR.OS.LNX64.UBNTU.SVR2004.B050" = "ubuntu-20.04"
# + "SW.VSVR.OS.WND64.WND.SVR2016EN.B100" = "Windows Server 2016 (64-bit) English Edition"
# + "SW.VSVR.OS.WND64.WND.SVR2019EN.B100" = "Windows Server 2019 (64-bit) English Edition"

# Attributes Reference
# data.ncloud_server_image.server_image.id
}
data "ncloud_server_product" "product" {
server_image_product_code = data.ncloud_server_image.server_image.id

filter {
name = "product_code"
values = ["SSD"]
regex = true
}
filter {
name = "cpu_count"
values = ["2"]
}
filter {
name = "memory_size"
values = ["4GB"]
}
filter {
name = "product_type"
values = ["HICPU"]
# Server Spec Type
# STAND
# HICPU
# HIMEM
}
# Attributes Reference
# data.ncloud_server_product.product.id
}
# #Server Image Type & Product Type
# data "ncloud_server_image" "server_image" {
# filter {
# name = "product_name"
# values = ["ubuntu-20.04"]
# }
# # image list
# # + "SW.VSVR.OS.LNX64.CNTOS.0703.B050" = "centos-7.3-64"
# # + "SW.VSVR.OS.LNX64.CNTOS.0708.B050" = "CentOS 7.8 (64-bit)"
# # + "SW.VSVR.OS.LNX64.UBNTU.SVR1604.B050" = "ubuntu-16.04-64-server"
# # + "SW.VSVR.OS.LNX64.UBNTU.SVR1804.B050" = "ubuntu-18.04"
# # + "SW.VSVR.OS.LNX64.UBNTU.SVR2004.B050" = "ubuntu-20.04"
# # + "SW.VSVR.OS.WND64.WND.SVR2016EN.B100" = "Windows Server 2016 (64-bit) English Edition"
# # + "SW.VSVR.OS.WND64.WND.SVR2019EN.B100" = "Windows Server 2019 (64-bit) English Edition"

# # Attributes Reference
# # data.ncloud_server_image.server_image.id
# }
# data "ncloud_server_product" "product" {
# server_image_product_code = data.ncloud_server_image.server_image.id

# filter {
# name = "product_code"
# values = ["SSD"]
# regex = true
# }
# filter {
# name = "cpu_count"
# values = ["2"]
# }
# filter {
# name = "memory_size"
# values = ["4GB"]
# }
# filter {
# name = "product_type"
# values = ["HICPU"]
# # Server Spec Type
# # STAND
# # HICPU
# # HIMEM
# }
# # Attributes Reference
# # data.ncloud_server_product.product.id
# }


variable "login_key_name" {
default = "tofu-example-key"
}
# variable "login_key_name" {
# default = "tofu-example-key"
# }

resource "random_id" "id" {
byte_length = 4
}
# resource "random_id" "id" {
# byte_length = 4
# }

resource "ncloud_login_key" "key" {
key_name = "${var.login_key_name}${random_id.id.hex}"
}
# resource "ncloud_login_key" "key" {
# key_name = "${var.login_key_name}${random_id.id.hex}"
# }

# Create VPC
resource "ncloud_vpc" "example" {
Expand Down
File renamed without changes.
37 changes: 37 additions & 0 deletions examples/ncp/objectstorage-bucket/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
terraform {

# Required Tofu version
required_version = "~>1.8.3"

required_providers {
ncloud = {
source = "NaverCloudPlatform/ncloud"
version = "3.2.1"
}
}
}

provider "ncloud" {
access_key = var.ncloud_access_key
secret_key = var.ncloud_secret_key
region = "KR" # Set the desired region (e.g., "KR", "JP", etc.)
support_vpc = true # Enable VPC support
}

# Declare variables
variable "ncloud_access_key" {
description = "Naver Cloud Platform Access Key"
type = string
default = "" # Leave the default value empty
}

variable "ncloud_secret_key" {
description = "Naver Cloud Platform Secret Key"
type = string
default = "" # Leave the default value empty
}

# Create object storage bucket
resource "ncloud_objectstorage_bucket" "tofu_bucket" {
bucket_name = "tofu-bucket"
}
8 changes: 8 additions & 0 deletions examples/ncp/objectstorage-bucket/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
output "ObjectStorageInfo" {
description = "Naver Cloud Platform Object Storage Bucket Information"
value = {
bucket_name = ncloud_objectstorage_bucket.tofu_bucket.bucket_name
creation_date = ncloud_objectstorage_bucket.tofu_bucket.creation_date
bucket_id = ncloud_objectstorage_bucket.tofu_bucket.id
}
}

0 comments on commit c433330

Please sign in to comment.