diff --git a/templates/sql-db/ncp/output.tf b/templates/sql-db/ncp/output.tf new file mode 100644 index 0000000..fd99a4b --- /dev/null +++ b/templates/sql-db/ncp/output.tf @@ -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 +} diff --git a/templates/sql-db/ncp/providers.tf b/templates/sql-db/ncp/providers.tf new file mode 100644 index 0000000..23fd7c9 --- /dev/null +++ b/templates/sql-db/ncp/providers.tf @@ -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 +} + diff --git a/templates/sql-db/ncp/sql-db.tf b/templates/sql-db/ncp/sql-db.tf new file mode 100644 index 0000000..6336003 --- /dev/null +++ b/templates/sql-db/ncp/sql-db.tf @@ -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 +} diff --git a/templates/sql-db/ncp/variables.tf b/templates/sql-db/ncp/variables.tf new file mode 100644 index 0000000..3e93b3c --- /dev/null +++ b/templates/sql-db/ncp/variables.tf @@ -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!" +} +