Resource Packs

Cloud

Example

Flavor

Feature

Mysql

Example: mysql resource using a Kubernetes StatefulSet

This example configures a mysql Resource Definition using Kubernetes StatefulSet.

Requirements

Name Version
terraform >= 1.3.0
humanitec ~> 1.0

Providers

Name Version
humanitec ~> 1.0

Modules

Name Source Version
mysql_basic ../../humanitec-resource-defs/mysql/basic n/a

Resources

Name Type
humanitec_resource_definition_criteria.mysql_basic resource

Inputs

Name Description Type Default Required
prefix Prefix of the created resources string "hum-rp-mysql-ex-" no

Deploy and use this example

To deploy this resource definition, run these commands below:

git clone https://github.com/humanitec-architecture/resource-packs-in-cluster

cd examples/mysql/

humctl login
humctl config set org YOUR-ORG

terraform init
terraform plan
terraform apply

The created Resource Definition can be used in your Score file like illustrated below:

apiVersion: score.dev/v1b1
metadata:
  name: my-workload
containers:
  my-container:
    image: nginx:latest # this container image is just used as an example, it's not talking to mysql.
    variables:
      MYSQL_CONNECTION_STRING: "Server=${resources.my-mysql.host};Port=${resources.my-mysql.port};Database=${resources.my-mysql.name};Uid=${resources.my-mysql.username};Pwd=${resources.my-mysql.password};"
resources:
  my-mysql:
    type: mysql

This Score file when deployed to Humanitec will provision the mysql database and inject the outputs in the associated environment variable.

Here is how to deploy this Score file, for example to the mysql-example Application and development Environment:

humctl create app mysql-example

humctl score deploy \
    -f score.yaml \
    --app mysql-example \
    --env development

main.tf ( view on GitHub ) :

module "mysql_basic" {
  source = "github.com/humanitec-architecture/resource-packs-in-cluster?ref=v2024-11-05//humanitec-resource-defs/mysql/basic"

  prefix = var.prefix
}

resource "humanitec_resource_definition_criteria" "mysql_basic" {
  resource_definition_id = module.mysql_basic.id
  class                  = "default"
  force_delete           = true
}


providers.tf ( view on GitHub ) :

terraform {
  required_providers {
    humanitec = {
      source  = "humanitec/humanitec"
      version = "~> 1.0"
    }
  }
  required_version = ">= 1.3.0"
}


provider "humanitec" {}


terraform.tfvars.example ( view on GitHub ) :


# Prefix of the created resources
prefix = "hum-rp-mysql-ex-"

variables.tf ( view on GitHub ) :

variable "prefix" {
  description = "Prefix of the created resources"
  type        = string
  default     = "hum-rp-mysql-ex-"
}

Top