apiVersion: core.oam.dev/v1alpha2
kind: ComponentDefinition
metadata:
  name: alibaba-rds
  namespace: vela-system
  annotations:
    definition.oam.dev/description: Terraform configuration for Alibaba Cloud RDS object
  labels:
    type: terraform
spec:
  workload:
    definition:
      apiVersion: terraform.core.oam.dev/v1beta1
      kind: Configuration
  schematic:
    terraform:
      configuration: |
        module "rds" {
          source = "github.com/kubevela-contrib/terraform-alicloud-rds"
          engine = "MySQL"
          engine_version = "8.0"
          instance_type = "rds.mysql.c1.large"
          instance_storage = "20"
          instance_name = var.instance_name
          account_name = var.account_name
          password = var.password
          allocate_public_connection = var.allocate_public_connection
          security_ips = ["0.0.0.0/0",]
        }

        output "DB_NAME" {
          value = module.rds.this_db_instance_name
        }
        output "DB_USER" {
          value = module.rds.this_db_database_account
        }
        output "DB_PORT" {
          value = module.rds.this_db_instance_port
        }
        output "DB_HOST" {
          value = module.rds.this_db_instance_connection_string
        }
        output "DB_PASSWORD" {
          value = var.password
        }
        output "DB_PUBLIC_HOST" {
          value = module.rds.db_public_connection_string
        }

        variable "instance_name" {
          description = "RDS instance name"
          type = string
          default = "poc"
        }

        variable "account_name" {
          description = "RDS instance user account name"
          type = string
          default = "oam"
        }

        variable "password" {
          description = "RDS instance account password"
          type = string
          default = "Xyfff83jfewGGfaked"
        }

        variable "allocate_public_connection" {
          description = "Whether to allocate public connection for a RDS instance."
          type        = bool
          default     = true
        }
