Skip to content

Commit

Permalink
Merge pull request #10 from IBM-Cloud/Release3.3.0
Browse files Browse the repository at this point in the history
Release3.3.0
  • Loading branch information
go-davidng authored Nov 22, 2022
2 parents baf829b + c5ee17e commit ef2786b
Show file tree
Hide file tree
Showing 58 changed files with 2,543 additions and 776 deletions.
9 changes: 0 additions & 9 deletions 3-tier-autoscale/.gitignore

This file was deleted.

20 changes: 19 additions & 1 deletion 3-tier-autoscale/common_variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
##################################################################################################
##################################################################################################


/**
* Name: api_key
* Type: String
Expand Down Expand Up @@ -94,7 +94,25 @@ variable "prefix" {
}
}

/**
* Name: enable_dbaas
* Type: Bool
* Description: For enabling Database as a Service which is a managed DB service.
**/
variable "enable_dbaas" {
type = bool
description = "For enabling Database as a Service which is a managed DB service."
}

/**
* Name: db_admin_password
* Type: String
* Description: The admin user password for the Database service instance. No special characters; minimum 10 characters, A-Z, a-z, 0-9
*/
variable "db_admin_password" {
type = string
description = "The admin user password for the Database service instance. No special characters; minimum 10 characters, A-Z, a-z, 0-9"
}



Expand Down
92 changes: 92 additions & 0 deletions 3-tier-autoscale/db_variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
###################################################################################################
###################################################################################################
##### This Terraform file defines the variables used in dbaas Module ######
##### db Module ######
###################################################################################################
###################################################################################################

locals {
service = "databases-for-mysql" # The type of Cloud Databases that you want to create. Currently support for only 'databases-for-mysql'.
plan = "standard" # The name of the service plan that you choose for your instance. All databases use 'standard'. The 'enterprise' is supported only for cassandra and mongodb
db_version = "5.7" # The database version for the mysql dbaas service
member_cpu_allocation_count = 3 # Enables and allocates dedicated CPU per-member to your deployment. Member group cpu must be >= 3 and <= 28 in increments of 1.
member_disk_allocation_mb = 20480 # The amount of disk space for the database, allocated per-member. Member group disk must be >= 20480 and <= 4194304 in increments of 1024.
member_memory_allocation_mb = 1024 # The amount of memory in megabytes for the database, allocated per-member. Member group memory must be >= 1024 and <= 114688 in increments of 128.
users = null # Type = set(map(string)), Database Users. It is set of username and passwords example: [{ "name"= "" "password" = ""}, { "name"= "" "password" = ""}]
create_timeout = "1h" # The creation of an instance is considered failed when no response is received for create_timeout minutes.
update_timeout = "1h" # The update of an instance is considered failed when no response is received for update_timeout minutes.
delete_timeout = "15m" # The deletion of an instance is considered failed when no response is received for delete_timeout minutes.
auto_scaling = [{ # Type = set(map(string)), Configure rules to allow your database to automatically increase its resources. Single block of autoscaling is allowed at once.
/**
* Autoscale Disk:
* note -> [Disk cannot be scaled down]
* Perform autoscaling: [When to scale, based on usage over a period of time]
* When either
* -> Average I/O utilisation is above <io_above_percent> over a <io_over_period> period
* or
* -> when less than <free_space_less_than_percent> free space is remaining
* Then
* Scale up by <rate_increase_percent> every <rate_period_seconds> to a limit of <rate_limit_mb_per_member> per member
* [ A hard limit on scaling, the deployment stops scaling at the limit ]
*/
"disk" = {
"capacity_enabled" = true # (Optional, Bool) Auto scaling scalar enables or disables the scalar capacity.
"free_space_less_than_percent" = 15 # (Optional, Integer) Auto scaling scalar capacity free space less than percent.
"io_above_percent" = 85 # (Optional, Integer) Auto scaling scalar I/O utilization above percent.
"io_enabled" = true # (Optional, String) Auto scaling scalar I/O utilization over period.
"io_over_period" = "15m" # (Optional, Bool) Auto scaling scalar I/O utilization enabled.
"rate_increase_percent" = 15 # (Optional, Integer) Auto scaling rate increase percent.
"rate_limit_mb_per_member" = 3670016 # (Optional, Integer) Auto scaling rate limit in megabytes per member. Max limit is 3TB.
"rate_period_seconds" = 900 # (Optional, Integer) Auto scaling rate period in seconds.
"rate_units" = "mb" # (Optional, String) Auto scaling rate in units.
}
/**
* Autoscale Memory/RAM :
* Perform autoscaling:
* When [When to scale, based on usage over a period of time]
* -> Average I/O utilisation is above <io_above_percent> over a <io_over_period> period
* Then
* Scale up by <rate_increase_percent> every <rate_period_seconds> to a limit of <rate_limit_mb_per_member> per member
* [ A hard limit on scaling, the deployment stops scaling at the limit ]
*/
"memory" = {
"io_above_percent" = 90 # (Optional, Integer) Auto scaling scalar I/O utilization above percent.
"io_enabled" = true # (Optional) Auto scaling scalar I/O utilization enabled.
"io_over_period" = "15m" # (Optional, String) Auto scaling scalar I/O utilization over period.
"rate_increase_percent" = 10 # (Optional, Integer) Auto scaling rate in increase percent.
"rate_limit_mb_per_member" = 114688 # (Optional, Integer) Auto scaling rate limit in megabytes per member. Max limit is 114688MB which is 112GB.
"rate_period_seconds" = 900 # (Optional, Integer) Auto scaling rate period in seconds.
"rate_units" = "mb" # (Optional, String) Auto scaling rate in units.
}
}
]
whitelist = null # Type = set(map(string)), Database Whitelist It is set of IP Address and description, example: [{ "address"= "10.248.0.4/32" "description" = ""}, { "address"= "10.248.64.4/32" "description" = ""}]
tags = null # Type = set(string), Tags to the dbaas service, example : ["tag1", "tag2"]
key_protect_instance = null # The instance CRN of a Key Management Services like Key Protect or Hyper Protect Crypto Service (HPCS) that you want to use for disk encryption.
key_protect_key = null # The root key CRN of a Key Management Services like Key Protect or Hyper Protect Crypto Service (HPCS) that you want to use for disk encryption.
backup_id = null # The CRN of a backup resource to restore from. The backup is created by a database deployment with the same service ID.
backup_encryption_key_crn = null # The CRN of a key protect key, that you want to use for encrypting disk that holds deployment backups.
remote_leader_id = null # A CRN of the leader database to make the replica(read-only) deployment. The leader database is created by a database deployment with the same service ID.
}

/**
* Name: db_access_endpoints
* Type: String
* Description: Allowed network of database instance. It could be 'private', 'public' or 'public-and-private'.
*/
variable "db_access_endpoints" {
description = "Allowed network of database instance"
type = string
default = "private"
}

/**
* Name: db_enable_autoscaling
* Type: String
* Description: Enable db autoscaling
*/
variable "db_enable_autoscaling" {
description = "Enable db autoscaling."
type = bool
default = false
}
18 changes: 18 additions & 0 deletions 3-tier-autoscale/example.userinput.auto.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,24 @@
################################### Database Input Variables ##################################
#

#/**
#* For enabling Database as a Service which is a managed DB service.
#* here default value is false
#**/
#enable_dbaas = false

#/**
#* The admin user password for the Database service instance. No special characters; minimum 10 characters, A-Z, a-z, 0-9
#* Here db_admin_password is "Admin12345678"
#**/
#db_admin_password = "Admin12345678"

#/**
#* Enter db_name value. It is the Database name.
#* Here we have db_name = "wpdb"
#**/
#db_name = "wpdb"

#/**
#* Enter the OS flavour you want to use for DB servers
#* You can choose windows or linux here.
Expand Down
10 changes: 10 additions & 0 deletions 3-tier-autoscale/instance_variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,14 @@ variable "db_vsi_count" {
condition = var.db_vsi_count <= 3
error_message = "Database VSI count should be less than or equals to 3."
}
}

/**
* Name: db_name
* Type: string
* Description: Database will be created with the specified name
**/
variable "db_name" {
description = "Database will be created with the specified name"
type = string
}
39 changes: 38 additions & 1 deletion 3-tier-autoscale/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,40 @@ resource "ibm_is_vpc" "vpc" {
resource_group = var.resource_group_id
}

# /**
# * Calling the db module with the following required parameters
# * source: Source Directory of the Module
# * prefix: This will be appended in resources created by this module
# * resource_group_id: The resource group id
# **/
module "db" {
count = var.enable_dbaas ? 1 : 0
source = "./modules/db"
prefix = var.prefix
resource_group_id = var.resource_group_id
region = var.region
db_admin_password = var.db_admin_password
service_endpoints = var.db_access_endpoints
db_version = local.db_version
service = local.service
plan = local.plan
member_cpu_allocation_count = local.member_cpu_allocation_count
member_disk_allocation_mb = local.member_disk_allocation_mb
member_memory_allocation_mb = local.member_memory_allocation_mb
tags = local.tags
users = local.users
create_timeout = local.create_timeout
update_timeout = local.update_timeout
delete_timeout = local.delete_timeout
auto_scaling = var.db_enable_autoscaling == true ? local.auto_scaling : []
key_protect_instance = local.key_protect_instance
key_protect_key = local.key_protect_key
whitelist = local.whitelist
backup_id = local.backup_id
backup_encryption_key_crn = local.backup_encryption_key_crn
remote_leader_id = local.remote_leader_id
}

/**
* Locals
* This resource will be used to create and calculate local variables containing Subnet IP count.
Expand Down Expand Up @@ -258,6 +292,7 @@ module "load_balancer" {
**/

module "instance" {
count = var.enable_dbaas ? 0 : 1
source = "./modules/instance"
prefix = var.prefix
vpc_id = ibm_is_vpc.vpc.id
Expand All @@ -268,10 +303,12 @@ module "instance" {
data_vol_size = var.data_vol_size
db_image = var.db_image
db_profile = var.db_profile
db_vsi_count = var.db_vsi_count
tiered_profiles = var.tiered_profiles
subnets = module.subnet.sub_objects["db"].*.id
db_sg = module.security_group.sg_objects["db"].id
db_vsi_count = var.db_vsi_count
db_password = var.db_admin_password
db_name = var.db_name
depends_on = [module.subnet.ibm_is_subnet, module.security_group, module.bastion]
}

Expand Down
45 changes: 45 additions & 0 deletions 3-tier-autoscale/modules/db/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Requirements

No requirements.

## Providers

| Name | Version |
|------|---------|
| <a name="provider_ibm"></a> [ibm](#provider\_ibm) | 1.33.1 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [ibm_is_instance.db](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_instance) | resource |
| [ibm_is_volume.data_volume](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_volume) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_bandwidth"></a> [bandwidth](#input\_bandwidth) | Bandwidth per second in GB. The possible values are 3, 5 and 10 | `number` | n/a | yes |
| <a name="input_data_vol_size"></a> [data\_vol\_size](#input\_data\_vol\_size) | Storage size in GB. The value should be between 10 and 2000 | `number` | n/a | yes |
| <a name="input_db_image"></a> [db\_image](#input\_db\_image) | Image for DB VSI | `string` | n/a | yes |
| <a name="input_db_profile"></a> [db\_profile](#input\_db\_profile) | DB Profile | `string` | n/a | yes |
| <a name="input_db_sg"></a> [db\_sg](#input\_db\_sg) | DB Security Group | `string` | n/a | yes |
| <a name="input_db_vsi_count"></a> [db\_vsi\_count](#input\_db\_vsi\_count) | Please enter the total number of instances you want to create in each zones. | `any` | n/a | yes |
| <a name="input_prefix"></a> [prefix](#input\_prefix) | Prefix for all the resources. | `string` | n/a | yes |
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | Resource Group ID | `string` | n/a | yes |
| <a name="input_ssh_key"></a> [ssh\_key](#input\_ssh\_key) | ssh keys for the vsi | `list(any)` | n/a | yes |
| <a name="input_subnets"></a> [subnets](#input\_subnets) | DB subnets Ids. This is required parameter | `list(any)` | n/a | yes |
| <a name="input_tiered_profiles"></a> [tiered\_profiles](#input\_tiered\_profiles) | Tiered profiles for Input/Output per seconds in GBs | `map(any)` | n/a | yes |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | Required parameter vpc\_id | `string` | n/a | yes |
| <a name="input_zones"></a> [zones](#input\_zones) | List of Availability Zones where compute resource will be created | `list(any)` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_db_target"></a> [db\_target](#output\_db\_target) | Target primary network interface address |
| <a name="output_db_vsi"></a> [db\_vsi](#output\_db\_vsi) | Target primary network interface address |
83 changes: 83 additions & 0 deletions 3-tier-autoscale/modules/db/db.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# /**
# #################################################################################################################
# * Resources Section for the db Module.
# #################################################################################################################
# */

/**
* IBM Cloud Database
* Element : ibm_database
* This resource will be used to create a database as per the users input.
**/
resource "ibm_database" "db" {
name = "${var.prefix}db"
resource_group_id = var.resource_group_id
location = var.region
version = var.db_version
adminpassword = var.db_admin_password
service = var.service
service_endpoints = var.service_endpoints
plan = var.plan
group {
group_id = "member"
memory {
allocation_mb = var.member_memory_allocation_mb
}
disk {
allocation_mb = var.member_disk_allocation_mb
}
cpu {
allocation_count = var.member_cpu_allocation_count
}
}
key_protect_instance = var.key_protect_instance
key_protect_key = var.key_protect_key
tags = var.tags
backup_id = var.backup_id
backup_encryption_key_crn = var.backup_encryption_key_crn
remote_leader_id = var.remote_leader_id
dynamic "auto_scaling" {
for_each = (var.auto_scaling != null ? var.auto_scaling : [])
content {
disk {
capacity_enabled = auto_scaling.value.disk.capacity_enabled
free_space_less_than_percent = auto_scaling.value.disk.free_space_less_than_percent
io_above_percent = auto_scaling.value.disk.io_above_percent
io_enabled = auto_scaling.value.disk.io_enabled
io_over_period = auto_scaling.value.disk.io_over_period
rate_increase_percent = auto_scaling.value.disk.rate_increase_percent
rate_limit_mb_per_member = auto_scaling.value.disk.rate_limit_mb_per_member
rate_period_seconds = auto_scaling.value.disk.rate_period_seconds
rate_units = auto_scaling.value.disk.rate_units
}
memory {
io_above_percent = auto_scaling.value.memory.io_above_percent
io_enabled = auto_scaling.value.memory.io_enabled
io_over_period = auto_scaling.value.memory.io_over_period
rate_increase_percent = auto_scaling.value.memory.rate_increase_percent
rate_limit_mb_per_member = auto_scaling.value.memory.rate_limit_mb_per_member
rate_period_seconds = auto_scaling.value.memory.rate_period_seconds
rate_units = auto_scaling.value.memory.rate_units
}
}
}
dynamic "users" {
for_each = (var.users != null ? var.users : [])
content {
name = (users.value.name != "" ? users.value.name : null)
password = (users.value.password != "" ? users.value.password : null)
}
}
dynamic "whitelist" {
for_each = (var.whitelist != null ? var.whitelist : [])
content {
address = (whitelist.value.address != "" ? whitelist.value.address : null)
description = (whitelist.value.description != "" ? whitelist.value.description : null)
}
}
timeouts {
create = var.create_timeout
update = var.update_timeout
delete = var.delete_timeout
}
}
22 changes: 22 additions & 0 deletions 3-tier-autoscale/modules/db/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# /**
# #################################################################################################################
# * Output Variable Section for the db Module.
# #################################################################################################################
# **/


output "db_connection_command" {
value = "MYSQL_PWD=<Admin-PASSWORD> mysql --host=${ibm_database.db.connectionstrings[0].hosts[0].hostname} --port=${ibm_database.db.connectionstrings[0].hosts[0].port} --user=admin ibmclouddb"
}

output "db_hostname" {
value = ibm_database.db.connectionstrings[0].hosts[0].hostname
}

output "db_port" {
value = ibm_database.db.connectionstrings[0].hosts[0].port
}

output "db_certificate" {
value = "${ibm_database.db.connectionstrings[0].certbase64}}"
}
Loading

0 comments on commit ef2786b

Please sign in to comment.