-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from yunkon-kim/241111-2030
Support creating SQL database in NCP
- Loading branch information
Showing
4 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" | ||
} | ||
|