Skip to content

Commit

Permalink
feat(redis): redis in-cluster resource
Browse files Browse the repository at this point in the history
  • Loading branch information
dharsanb committed Jan 5, 2024
1 parent 5cb85c7 commit db556fd
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The following resources are included:

* [mysql/basic](./humanitec-resource-defs/mysql/basic): A basic MySQL.
* [postgres/basic](./humanitec-resource-defs/postgres/basic): A basic Postgres.
* [redis/basic](./humanitec-resource-defs/redis/basic): A basic Redis.

The `humanitec-resource-defs` directory includes the respective resource definitions.

Expand Down
21 changes: 21 additions & 0 deletions examples/redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- BEGIN_TF_DOCS -->


## Providers

| Name | Version |
|------|---------|
| humanitec | n/a |

## Modules

| Name | Source | Version |
|------|--------|---------|
| redis\_basic | ../../humanitec-resource-defs/redis/basic | n/a |

## Resources

| Name | Type |
|------|------|
| [humanitec_resource_definition_criteria.redis_basic](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
<!-- END_TF_DOCS -->
16 changes: 16 additions & 0 deletions examples/redis/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Redis

locals {
res_def_prefix = "dev-in-cluster-"
redis_class = "dev-in-cluster-redis"
}

module "redis_basic" {
source = "../../humanitec-resource-defs/redis/basic"
prefix = local.res_def_prefix
}

resource "humanitec_resource_definition_criteria" "redis_basic" {
resource_definition_id = module.redis_basic.id
class = local.redis_class
}
10 changes: 10 additions & 0 deletions examples/redis/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
humanitec = {
source = "humanitec/humanitec"
}
}
}


provider "humanitec" {}
Empty file.
27 changes: 27 additions & 0 deletions humanitec-resource-defs/redis/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- BEGIN_TF_DOCS -->


## Providers

| Name | Version |
|------|---------|
| humanitec | n/a |

## Resources

| Name | Type |
|------|------|
| [humanitec_resource_definition.main](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| prefix | n/a | `string` | `""` | no |

## Outputs

| Name | Description |
|------|-------------|
| id | n/a |
<!-- END_TF_DOCS -->
90 changes: 90 additions & 0 deletions humanitec-resource-defs/redis/basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
resource "humanitec_resource_definition" "main" {
id = "${var.prefix}redis"
name = "${var.prefix}redis"
type = "redis"
driver_type = "humanitec/template"

driver_inputs = {
values_string = jsonencode({
templates = {
cookie = <<EOL
port: {{ .init.port }}
EOL
init = <<EOL
{{- if .cookie}}
port: {{ .cookie.port }}
{{- else }}
port: 6379
{{- end }}
name: redis-{{ .id }}
EOL
manifests = <<EOL
deployment.yaml:
location: namespace
data:
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .init.name }}
spec:
serviceName: redis
replicas: 1
selector:
matchLabels:
app: {{ .init.name }}
template:
metadata:
labels:
app: {{ .init.name }}
spec:
securityContext:
fsGroup: 1000
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 1000
seccompProfile:
type: RuntimeDefault
containers:
- name: {{ .init.name }}
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
readOnlyRootFilesystem: true
image: redis:7-alpine
ports:
- name: tcp-redis
port: {{ .init.port }}
targetPort: 6379
volumeMounts:
- mountPath: /data
name: redis-data
volumes:
- name: redis-data
emptyDir: {}
service.yaml:
location: namespace
data:
apiVersion: v1
kind: Service
metadata:
name: {{ .init.name }}
spec:
type: ClusterIP
selector:
app: {{ .init.name }}
ports:
- name: tcp-redis
port: {{ .init.port }}
targetPort: {{ .init.port }}
EOL
outputs = <<EOL
host: {{ .init.name }}
port: {{ .init.port }}
EOL
}
})
}
}
3 changes: 3 additions & 0 deletions humanitec-resource-defs/redis/basic/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "id" {
value = humanitec_resource_definition.main.id
}
7 changes: 7 additions & 0 deletions humanitec-resource-defs/redis/basic/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_providers {
humanitec = {
source = "humanitec/humanitec"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prefix = ""
3 changes: 3 additions & 0 deletions humanitec-resource-defs/redis/basic/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "prefix" {
default = ""
}

0 comments on commit db556fd

Please sign in to comment.