Skip to content

Commit

Permalink
Merge pull request #106 from yunkon-kim/241111-2030
Browse files Browse the repository at this point in the history
Support creating SQL database in NCP
  • Loading branch information
yunkon-kim authored Nov 11, 2024
2 parents dab1d94 + 97e0db5 commit de88286
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 0 deletions.
12 changes: 12 additions & 0 deletions templates/sql-db/ncp/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
output "sql_db_info" {
description = "Information needed to connect to the MySQL RDS instance."
value = {
service_name = ncloud_mysql.mysql.service_name
server_name_prefix = ncloud_mysql.mysql.server_name_prefix
user_name = ncloud_mysql.mysql.user_name
host_ip = ncloud_mysql.mysql.host_ip
database_name = ncloud_mysql.mysql.database_name
# user_password = ncloud_mysql.mysql.user_password
}
# sensitive = true // Mark as sensitive to hide sensitive details like passwords
}
33 changes: 33 additions & 0 deletions templates/sql-db/ncp/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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 = var.csp_region # 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
}

11 changes: 11 additions & 0 deletions templates/sql-db/ncp/sql-db.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# Create MySQL RDS Instance
resource "ncloud_mysql" "mysql" {
subnet_no = var.csp_subnet1_id
service_name = "${var.terrarium_id}-db-instance" # Service name: Only English alphabets, numbers, dash ( - ) and Korean letters can be entered. Min: 3, Max: 30
server_name_prefix = "svr-name-prefix" # Server name prefix: In order to prevent overlapping host names, random text is added. Min: 3, Max: 20
user_name = var.db_admin_username # Master username
user_password = var.db_admin_password # Master password
host_ip = "%" # Host IP: "%" For overall access (use cautiously), specific IPs permitted: 1.1.1.1, IP band connection permitted: 1.1.1.%
database_name = "${var.terrarium_id}-db" # Initial database name
}
101 changes: 101 additions & 0 deletions templates/sql-db/ncp/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
variable "terrarium_id" {
type = string
description = "Unique ID to distinguish and manage infrastructure."

validation {
condition = var.terrarium_id != ""
error_message = "The terrarium ID must be set"
}
}


#######################################################################
# Naver Cloud Platform (NCP)

variable "csp_region" {
type = string
description = "A region in NCP."
default = "KR"

}

# variable "csp_resource_group" {
# type = string
# default = "tr-rg-01"
# description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
# }

# variable "azure-virtual-network-name" {
# type = string
# description = "A virtual network name in MS Azure."
# default = "tr-azure-vnet"
# }

# # Required network information
# variable "csp_vnet_id" {
# type = string
# description = "The VPC ID in AWS."
# }

variable "csp_subnet1_id" {
type = string
description = "The subnet ID in NCP."
}

# variable "csp_subnet2_id" {
# type = string
# description = "The subnet ID in AWS."
# }

# # Required security group information
# variable "db_engine_port" {
# type = number
# description = "The port number for the database engine."
# default = 3306
# }

# variable "ingress_cidr_block" {
# type = string
# description = "The CIDR block for ingress traffic."
# default = "0.0.0.0/0"
# }

# variable "egress_cidr_block" {
# type = string
# description = "The CIDR block for egress traffic."
# default = "0.0.0.0/0"
# }

# # Required database engine information
# variable "db_instance_identifier" {
# type = string
# description = "The identifier for the database."
# default = "mydbinstance"
# }

# variable "db_engine_version" {
# type = string
# description = "The version of the database engine."
# default = "MYSQL_8_0"
# }

# variable "db_instance_spec" {
# type = string
# description = "The instance class for the database."
# default = "db-f1-micro"
# }

variable "db_admin_username" {
type = string
description = "The admin username for the database."
default = "mydbadmin"
}

# NOTE - "administrator_password" must contain characters from three of the categories
# – uppercase letters, lowercase letters, numbers and non-alphanumeric characters, got mysdbpass
variable "db_admin_password" {
type = string
description = "The admin password for the database."
default = "P@ssword1234!"
}

0 comments on commit de88286

Please sign in to comment.