Skip to content

Commit

Permalink
Merge pull request #108 from yunkon-kim/241114-14
Browse files Browse the repository at this point in the history
Align the `sql_db_info` output of AWS, Azure, GCP, and NCP
  • Loading branch information
yunkon-kim authored Nov 14, 2024
2 parents ae81599 + 0146793 commit d075c1c
Show file tree
Hide file tree
Showing 21 changed files with 593 additions and 144 deletions.
2 changes: 1 addition & 1 deletion api/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2546,7 +2546,7 @@ const docTemplate = `{
},
"db_admin_password": {
"type": "string",
"example": "P@ssword1234!"
"example": "Password1234!"
},
"db_admin_username": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,7 @@
},
"db_admin_password": {
"type": "string",
"example": "P@ssword1234!"
"example": "Password1234!"
},
"db_admin_username": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ definitions:
example: vpc-12345678
type: string
db_admin_password:
example: P@ssword1234!
example: Password1234!
type: string
db_admin_username:
example: mydbadmin
Expand Down
4 changes: 2 additions & 2 deletions examples/aws/mysql-db-instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ resource "aws_route_table_association" "public_2" {

# Create a DB subnet group
resource "aws_db_subnet_group" "rds" {
name = "main"
name = "tofu-main"
subnet_ids = [aws_subnet.public_1.id, aws_subnet.public_2.id]

tags = {
Expand All @@ -96,7 +96,7 @@ resource "aws_db_subnet_group" "rds" {

# Create a security group for RDS Database Instance
resource "aws_security_group" "rds_sg" {
name = "rds_sg"
name = "tofu-rds-sg"
vpc_id = aws_vpc.main.id

ingress {
Expand Down
59 changes: 53 additions & 6 deletions examples/aws/mysql-db-instance/output.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,54 @@
#outputs.tf
output "security_group_id" {
value = aws_security_group.rds_sg.id
}
output "db_instance_endpoint" {
value = aws_db_instance.myinstance.endpoint
# Outputs wrapped in sql_db_info object
output "sql_db_info" {
description = "Information for connecting to the MySQL RDS instance with dynamic variables."
value = {
sql_db_detail = {
# Basic Information
instance_name = aws_db_instance.myinstance.identifier # "myrdsinstance"
instance_resource_id = aws_db_instance.myinstance.id # "db-YMJCVDFDANINUTBJJU63AZTY5Q"
instance_spec = aws_db_instance.myinstance.instance_class # "db.t3.micro"
location = aws_db_instance.myinstance.availability_zone # "ap-northeast-2c"
tags = aws_db_instance.myinstance.tags # { "Name" = "myrdsinstance" }

# Storage Configuration
storage_type = aws_db_instance.myinstance.storage_type # "gp2"
storage_size = aws_db_instance.myinstance.allocated_storage # 20

# Database Engine Information
engine_name = aws_db_instance.myinstance.engine # "mysql"
engine_version = aws_db_instance.myinstance.engine_version # "8.0.39"

# Database Connection Details
connection_endpoint = aws_db_instance.myinstance.endpoint # "myrdsinstance.chrkjg2ktom1.ap-northeast-2.rds.amazonaws.com:3306"
connection_host = aws_db_instance.myinstance.address # "myrdsinstance.chrkjg2ktom1.ap-northeast-2.rds.amazonaws.com"
connection_port = aws_db_instance.myinstance.port # 3306
public_access_enabled = aws_db_instance.myinstance.publicly_accessible # true

# Authentication
admin_username = aws_db_instance.myinstance.username # "myrdsuser"
# amdin_password = aws_db_instance.myinstance.password # "myrdsuser"

provider_specific_detail = {
provider = "aws"
resource_identifier = aws_db_instance.myinstance.arn # "arn:aws:rds:ap-northeast-2:635484366616:db:myrdsinstance"
is_multi_az = aws_db_instance.myinstance.multi_az # false

status = aws_db_instance.myinstance.status # "available"
dns_zone_id = aws_db_instance.myinstance.hosted_zone_id # "ZLA2NUCOLGUUR"
security_group_ids = aws_db_instance.myinstance.vpc_security_group_ids # ["sg-0af75bda5c889cea6"]
subnet_group_name = aws_db_instance.myinstance.db_subnet_group_name # "tofu-main"
storage_encrypted = aws_db_instance.myinstance.storage_encrypted # false
storage_throughput = aws_db_instance.myinstance.storage_throughput # 0
storage_iops = aws_db_instance.myinstance.iops # 0
replicas = aws_db_instance.myinstance.replicas # []
}
}
}
}

#
# output "db_instance_all" {
# description = "All information"
# value = aws_db_instance.myinstance
# sensitive = true
# }
70 changes: 61 additions & 9 deletions examples/azure/mysql-db/output.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,64 @@
output "MySqlDbInfo" {
description = "Information needed to connect and manage the Azure Database for MySQL instance."
# Outputs wrapped in sql_db_info object
output "sql_db_info" {
description = "Information for connecting to the MySQL Flexible Server instance in Azure."
value = {
server_name = azurerm_mysql_flexible_server.example.name
fully_qualified_domain_name = azurerm_mysql_flexible_server.example.fqdn
administrator_login = azurerm_mysql_flexible_server.example.administrator_login
administrator_password = "YOUR_PASSWORD_HERE" # Note: Avoid exposing this directly; consider using a secret management tool
database_name = azurerm_mysql_flexible_database.example.name
port = 3306
# ssl_enforcement = azurerm_mysql_flexible_server.example.ssl_enforcement_enabled
sql_db_detail = {
# Basic Information
instance_name = azurerm_mysql_flexible_server.example.name # "tofu-example-mysql-server"
instance_resource_id = azurerm_mysql_flexible_server.example.id # "/subscriptions/a20fed83-96bd-4480-92a9-140b8e3b7c3a/resourceGroups/tofu-example-rg/providers/Microsoft.DBforMySQL/flexibleServers/tofu-example-mysql-server"
instance_spec = azurerm_mysql_flexible_server.example.sku_name # "B_Standard_B1ms"
location = azurerm_mysql_flexible_server.example.location # "koreacentral"
tags = azurerm_mysql_flexible_server.example.tags # (if available)

# Storage Configuration
storage_type = "Premium_LRS" # Azure MySQL Flexible Server uses Premium storage
storage_size = azurerm_mysql_flexible_server.example.storage[0].size_gb # 20

# Database Engine Information
engine_name = "mysql" # Always "mysql"
engine_version = azurerm_mysql_flexible_server.example.version # "5.7"

# Database Connection Details
connection_endpoint = "${azurerm_mysql_flexible_server.example.fqdn}:3306" # "tofu-example-mysql-server.mysql.database.azure.com:3306"
connection_host = azurerm_mysql_flexible_server.example.fqdn # "tofu-example-mysql-server.mysql.database.azure.com"
connection_port = 3306 # Default MySQL port
public_access_enabled = azurerm_mysql_flexible_server.example.public_network_access_enabled # true

# Authentication
admin_username = azurerm_mysql_flexible_server.example.administrator_login # "adminuser"
# admin_password = azurerm_mysql_flexible_server.example.administrator_login_password # "adminuser"

provider_specific_detail = {
provider = "azure"
resource_identifier = azurerm_mysql_flexible_server.example.id

resource_group_name = azurerm_mysql_flexible_server.example.resource_group_name # "tofu-example-rg"
zone = azurerm_mysql_flexible_server.example.zone # "2"
database_name = azurerm_mysql_flexible_database.example.name # "tofu-example-db"
charset = azurerm_mysql_flexible_database.example.charset # "utf8"
collation = azurerm_mysql_flexible_database.example.collation # "utf8_general_ci"

storage_autogrow_enabled = azurerm_mysql_flexible_server.example.storage[0].auto_grow_enabled # true
io_scaling_enabled = azurerm_mysql_flexible_server.example.storage[0].io_scaling_enabled # false

backup_retention_days = azurerm_mysql_flexible_server.example.backup_retention_days # 7
geo_redundant_backup_enabled = azurerm_mysql_flexible_server.example.geo_redundant_backup_enabled # false

replica_capacity = azurerm_mysql_flexible_server.example.replica_capacity # 10
replication_role = azurerm_mysql_flexible_server.example.replication_role # "None"
}
}
}
}

# output "azurerm_mysql_flexible_server_all" {
# description = "All attributes of the Azure Database for MySQL instance."
# value = azurerm_mysql_flexible_server.example
# sensitive = true
# }

# output "azurerm_mysql_flexible_database_all" {
# description = "All attributes of the Azure Database for MySQL database."
# value = azurerm_mysql_flexible_database.example
# sensitive = true
# }
2 changes: 1 addition & 1 deletion examples/azure/mysql-db/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ resource "azurerm_mysql_flexible_server" "example" {
resource_group_name = azurerm_resource_group.example.name

administrator_login = "adminuser"
administrator_password = "P@ssword1234!"
administrator_password = "Password1234!"

sku_name = "B_Standard_B1ms" # e.g., General Purpose, Standard_D2s_v3
# storage_mb = 5120 # 5 GB
Expand Down
2 changes: 1 addition & 1 deletion examples/gcp/sql-db-instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ resource "google_sql_database_instance" "my_sql_instance" {
tier = "db-f1-micro" # Set the instance type
}

# deletion_protection = false # Disable deletion protection
deletion_protection = false # Disable deletion protection
}

# Create database
Expand Down
64 changes: 56 additions & 8 deletions examples/gcp/sql-db-instance/output.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,59 @@
# Outputs wrapped in SqlDbInstanceInfo object, including public IP
output "SqlDbInstanceInfo" {
# Outputs wrapped in sql_db_info object
output "sql_db_info" {
description = "Information of the MySQL Cloud SQL instance in GCP."
value = {
instance_name = google_sql_database_instance.my_sql_instance.name
database_name = google_sql_database.my_database.name
database_user = google_sql_user.my_user.name
connection_name = google_sql_database_instance.my_sql_instance.connection_name
public_ip = google_sql_database_instance.my_sql_instance.public_ip_address
sql_db_detail = {
# Basic Information
instance_name = google_sql_database_instance.my_sql_instance.name # "my-sql-instance"
instance_resource_id = google_sql_database_instance.my_sql_instance.id # "my-sql-instance"
instance_spec = google_sql_database_instance.my_sql_instance.settings[0].tier # "db-f1-micro"
location = google_sql_database_instance.my_sql_instance.settings[0].location_preference[0].zone # "asia-northeast3-a"
tags = google_sql_database_instance.my_sql_instance.settings[0].user_labels # {}

# Storage Configuration
storage_type = google_sql_database_instance.my_sql_instance.settings[0].disk_type # "PD_SSD"
storage_size = google_sql_database_instance.my_sql_instance.settings[0].disk_size # 10

# Database Engine Information
engine_name = "mysql" # Not exposed by GCP
engine_version = google_sql_database_instance.my_sql_instance.database_version # "MYSQL_8_0"

# Database Connection Details
connection_endpoint = "${google_sql_database_instance.my_sql_instance.first_ip_address}:3306"
connection_host = google_sql_database_instance.my_sql_instance.first_ip_address
connection_port = 3306 # Default MySQL port
public_access_enabled = google_sql_database_instance.my_sql_instance.settings[0].ip_configuration[0].ipv4_enabled

# Authentication
admin_username = google_sql_user.my_user.name # "myuser"
# admin_password = google_sql_user.my_user.password # "mypassword"

provider_specific_detail = {
provider = "gcp"
resource_identifier = google_sql_database_instance.my_sql_instance.self_link
availability_type = google_sql_database_instance.my_sql_instance.settings[0].availability_type

project = google_sql_database_instance.my_sql_instance.project
region = google_sql_database_instance.my_sql_instance.region
}
}
}
description = "Information for SQL Database instance, including instance name, database name, user, connection name, and public IP address"
}

# output "my_sql_instance_all" {
# description = "All information"
# value = google_sql_database_instance.my_sql_instance
# sensitive = true
# }

# output "my_database_all" {
# description = "All information"
# value = google_sql_database.my_database
# sensitive = true
# }

# output "my_user_all" {
# description = "All information"
# value = google_sql_user.my_user
# sensitive = true
# }
73 changes: 64 additions & 9 deletions examples/ncp/mysql/output.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,67 @@
output "mysql_db_info" {
description = "Information needed to connect to the MySQL RDS instance."
# Outputs wrapped in sql_db_info object
output "sql_db_info" {
description = "Information for connecting to the MySQL instance in NCP."
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
sql_db_detail = {
# Basic Information
instance_name = ncloud_mysql.mysql.service_name # "tofu-example-mysql"
instance_resource_id = ncloud_mysql.mysql.id # "100457839"
instance_spec = ncloud_mysql.mysql.image_product_code # "SW.VMYSL.OS.LNX64.ROCKY.0810.MYSQL.B050"
location = ncloud_mysql.mysql.region_code # "KR"
tags = {} # (if available)

# Storage Configuration
storage_type = ncloud_mysql.mysql.data_storage_type # "SSD"
storage_size = ncloud_mysql.mysql.mysql_server_list[0].data_storage_size / 1073741824 # 10 (Unit: GB)

# Database Engine Information
engine_name = "mysql" # Always "mysql"
engine_version = ncloud_mysql.mysql.engine_version_code # "MYSQL8.0.36"

# Database Connection Details
connection_endpoint = "${ncloud_mysql.mysql.mysql_server_list[0].private_domain}:${ncloud_mysql.mysql.port}" # "db-2vpnbg.vpc-cdb.ntruss.com:3306"
connection_host = ncloud_mysql.mysql.mysql_server_list[0].private_domain # "db-2vpnbg.vpc-cdb.ntruss.com"
connection_port = ncloud_mysql.mysql.port # 3306
public_access_enabled = ncloud_mysql.mysql.mysql_server_list[0].is_public_subnet # true

# Authentication
admin_username = ncloud_mysql.mysql.user_name # "username"
# admin_password = ncloud_mysql.mysql.user_password # "password"

provider_specific_detail = {
provider = "ncp"
resource_identifier = ncloud_mysql.mysql.id # "100457839"
is_ha = ncloud_mysql.mysql.is_ha # true

host_ip = ncloud_mysql.mysql.host_ip # "%"
server_name_prefix = ncloud_mysql.mysql.server_name_prefix # "tofu-example-prefix"
server_instances = [for server in ncloud_mysql.mysql.mysql_server_list : {
name = server.server_name # "tofu-example-prefix-001-61we"
role = server.server_role # "M" or "H"
cpu_count = server.cpu_count # 2
memory_size = server.memory_size # 4294967296
create_date = server.create_date # "2024-11-14T19:29:51+0900"
uptime = server.uptime # "2024-11-14T19:34:37+0900"
server_instance_no = server.server_instance_no # "100457840"
}]

vpc_no = ncloud_mysql.mysql.vpc_no # "82836"
subnet_no = ncloud_mysql.mysql.subnet_no # "185880"
access_control_group_no_list = ncloud_mysql.mysql.access_control_group_no_list # ["218311"]

backup_enabled = ncloud_mysql.mysql.is_backup # true
backup_time = ncloud_mysql.mysql.backup_time # "07:45"
backup_file_retention_period = ncloud_mysql.mysql.backup_file_retention_period # 1

is_multi_zone = ncloud_mysql.mysql.is_multi_zone # false
is_storage_encryption = ncloud_mysql.mysql.is_storage_encryption # false
}
}
}
# sensitive = true // Mark as sensitive to hide sensitive details like passwords
}

# output "ncloud_mysql_all" {
# description = "All information about the MySQL RDS instance."
# value = ncloud_mysql.mysql
# sensitive = true // Mark as sensitive to hide sensitive details like passwords
# }
10 changes: 5 additions & 5 deletions pkg/api/rest/handler/sql-db.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func InitEnvForSqlDb(c echo.Context) error {
return c.JSON(http.StatusCreated, res)
}

// ClearEnvForSqlDb godoc
// ClearEnvOfSqlDb godoc
// @Summary Clear the entire directory and configuration files
// @Description Clear the entire directory and configuration files
// @Tags [SQL Database] Operations
Expand All @@ -188,7 +188,7 @@ func InitEnvForSqlDb(c echo.Context) error {
// @Failure 500 {object} model.Response "Internal Server Error"
// @Failure 503 {object} model.Response "Service Unavailable"
// @Router /tr/{trId}/sql-db/env [delete]
func ClearSqlDb(c echo.Context) error {
func ClearEnvOfSqlDb(c echo.Context) error {

trId := c.Param("trId")
if trId == "" {
Expand Down Expand Up @@ -490,7 +490,7 @@ func CreateSqlDb(c echo.Context) error {
return c.JSON(http.StatusCreated, res)
}

// GetResourceInfoOfGcpAwsVpn godoc
// GetResourceInfoOfSqlDb godoc
// @Summary Get resource info of SQL database
// @Description Get resource info of SQL database
// @Tags [SQL Database] Operations
Expand Down Expand Up @@ -663,7 +663,7 @@ func GetResourceInfoOfSqlDb(c echo.Context) error {
}
}

// DestroyGcpAwsVpn godoc
// DestroySqlDb godoc
// @Summary Destroy SQL database
// @Description Destroy SQL database
// @Tags [SQL Database] Operations
Expand Down Expand Up @@ -739,7 +739,7 @@ func DestroySqlDb(c echo.Context) error {
return c.JSON(http.StatusCreated, res)
}

// GetRequestStatusOfGcpAwsVpn godoc
// GetRequestStatusOfSqlDb godoc
// @Summary Check the status of a specific request by its ID
// @Description Check the status of a specific request by its ID
// @Tags [SQL Database] Operations
Expand Down
Loading

0 comments on commit d075c1c

Please sign in to comment.