diff --git a/README.md b/README.md index c827201..e3412cc 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A collection of GCP resources ready to be used with [Humanitec](https://humanite The following resources are included: -* None +* [redis/basic](./humanitec-resource-defs/redis/basic): GCP Memorystore Redis resource. The `humanitec-resource-defs` directory includes the respective resource definitions. diff --git a/examples/redis/basic/README.md b/examples/redis/basic/README.md new file mode 100644 index 0000000..a8a0675 --- /dev/null +++ b/examples/redis/basic/README.md @@ -0,0 +1,46 @@ + +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 1.3.0 | +| humanitec | ~> 0 | + +## Providers + +| Name | Version | +|------|---------| +| humanitec | ~> 0 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| redis | ../../../humanitec-resource-defs/redis/basic | n/a | + +## Resources + +| Name | Type | +|------|------| +| [humanitec_application.example](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/application) | resource | +| [humanitec_resource_definition_criteria.redis](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| alternative\_location\_id | n/a | `string` | n/a | yes | +| auth\_enabled | n/a | `bool` | n/a | yes | +| authorized\_network | n/a | `string` | n/a | yes | +| credentials | n/a | `any` | n/a | yes | +| humanitec\_org\_id | Humanitec organization where resource definitions will be applied | `string` | n/a | yes | +| humanitec\_token | Humanitec API token | `string` | n/a | yes | +| location\_id | n/a | `string` | n/a | yes | +| memory\_size\_gb | n/a | `number` | n/a | yes | +| name | n/a | `string` | n/a | yes | +| project | n/a | `string` | n/a | yes | +| region | n/a | `string` | n/a | yes | +| humanitec\_host | Humanitec API host url | `string` | `"https://api.humanitec.io"` | no | +| resource\_packs\_gcp\_rev | n/a | `string` | `"ref/heads/main"` | no | +| resource\_packs\_gcp\_url | n/a | `string` | `"https://github.com/humanitec-architecture/resource-packs-gcp.git"` | no | + \ No newline at end of file diff --git a/examples/redis/basic/main.tf b/examples/redis/basic/main.tf new file mode 100644 index 0000000..9614119 --- /dev/null +++ b/examples/redis/basic/main.tf @@ -0,0 +1,30 @@ +locals { + res_def_prefix = "${var.name}-" +} + +resource "humanitec_application" "example" { + id = var.name + name = var.name +} + +module "redis" { + source = "../../../humanitec-resource-defs/redis/basic" + + prefix = local.res_def_prefix + display_name = var.name + resource_packs_gcp_rev = var.resource_packs_gcp_rev + resource_packs_gcp_url = var.resource_packs_gcp_url + project = var.project + region = var.region + credentials = var.credentials + memory_size_gb = var.memory_size_gb + location_id = var.location_id + alternative_location_id = var.alternative_location_id + authorized_network = var.authorized_network + auth_enabled = var.auth_enabled +} + +resource "humanitec_resource_definition_criteria" "redis" { + resource_definition_id = module.redis.id + app_id = humanitec_application.example.id +} diff --git a/examples/redis/basic/providers.tf b/examples/redis/basic/providers.tf new file mode 100644 index 0000000..724dbd4 --- /dev/null +++ b/examples/redis/basic/providers.tf @@ -0,0 +1,16 @@ +terraform { + required_providers { + humanitec = { + source = "humanitec/humanitec" + version = "~> 0" + } + } + + required_version = ">= 1.3.0" +} + +provider "humanitec" { + host = var.humanitec_host + org_id = var.humanitec_org_id + token = var.humanitec_token +} diff --git a/examples/redis/basic/terraform.tfvars.example b/examples/redis/basic/terraform.tfvars.example new file mode 100644 index 0000000..d4ce462 --- /dev/null +++ b/examples/redis/basic/terraform.tfvars.example @@ -0,0 +1,21 @@ +alternative_location_id = "" +auth_enabled = "" +authorized_network = "" +credentials = "" + +# Humanitec API host url +humanitec_host = "https://api.humanitec.io" + +# Humanitec organization where resource definitions will be applied +humanitec_org_id = "" + +# Humanitec API token +humanitec_token = "" + +location_id = "" +memory_size_gb = "" +name = "" +project = "" +region = "" +resource_packs_gcp_rev = "ref/heads/main" +resource_packs_gcp_url = "https://github.com/humanitec-architecture/resource-packs-gcp.git" \ No newline at end of file diff --git a/examples/redis/basic/variables.tf b/examples/redis/basic/variables.tf new file mode 100644 index 0000000..e7fee2b --- /dev/null +++ b/examples/redis/basic/variables.tf @@ -0,0 +1,61 @@ +variable "humanitec_org_id" { + type = string + description = "Humanitec organization where resource definitions will be applied" +} + +variable "humanitec_token" { + type = string + description = "Humanitec API token" +} + +variable "humanitec_host" { + type = string + default = "https://api.humanitec.io" + description = "Humanitec API host url" +} + +variable "name" { + type = string +} + +variable "resource_packs_gcp_rev" { + type = string + default = "ref/heads/main" +} + +variable "resource_packs_gcp_url" { + type = string + default = "https://github.com/humanitec-architecture/resource-packs-gcp.git" +} + +variable "project" { + type = string +} + +variable "region" { + type = string +} + +variable "credentials" { + type = any +} + +variable "memory_size_gb" { + type = number +} + +variable "location_id" { + type = string +} + +variable "alternative_location_id" { + type = string +} + +variable "authorized_network" { + type = string +} + +variable "auth_enabled" { + type = bool +} diff --git a/humanitec-resource-defs/.gitkeep b/humanitec-resource-defs/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/humanitec-resource-defs/redis/basic/README.md b/humanitec-resource-defs/redis/basic/README.md new file mode 100644 index 0000000..796da53 --- /dev/null +++ b/humanitec-resource-defs/redis/basic/README.md @@ -0,0 +1,46 @@ + +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 1.3.0 | +| humanitec | ~> 0 | + +## Providers + +| Name | Version | +|------|---------| +| humanitec | ~> 0 | + +## 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 | +|------|-------------|------|---------|:--------:| +| alternative\_location\_id | n/a | `string` | n/a | yes | +| authorized\_network | n/a | `string` | n/a | yes | +| credentials | n/a | `any` | n/a | yes | +| display\_name | n/a | `string` | n/a | yes | +| location\_id | n/a | `string` | n/a | yes | +| memory\_size\_gb | n/a | `number` | n/a | yes | +| prefix | n/a | `string` | n/a | yes | +| project | n/a | `string` | n/a | yes | +| region | n/a | `string` | n/a | yes | +| auth\_enabled | n/a | `bool` | `false` | no | +| redis\_version | n/a | `string` | `"REDIS_4_0"` | no | +| reserved\_ip\_range | n/a | `string` | `null` | no | +| resource\_packs\_gcp\_rev | n/a | `string` | `"ref/heads/main"` | no | +| resource\_packs\_gcp\_url | n/a | `string` | `"https://github.com/humanitec-architecture/resource-packs-gcp.git"` | no | +| weekly\_maintenance\_windows | n/a | `any` | `{}` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| id | n/a | + \ No newline at end of file diff --git a/humanitec-resource-defs/redis/basic/main.tf b/humanitec-resource-defs/redis/basic/main.tf new file mode 100644 index 0000000..07db4bb --- /dev/null +++ b/humanitec-resource-defs/redis/basic/main.tf @@ -0,0 +1,41 @@ +resource "humanitec_resource_definition" "main" { + driver_type = "humanitec/terraform" + id = "${var.prefix}memorystore-redis" + name = "${var.prefix}memorystore-redis" + type = "redis" + + driver_inputs = { + secrets_string = jsonencode({ + variables = { + credentials = var.credentials + } + + }) + + values_string = jsonencode({ + source = { + path = "modules/redis/basic" + rev = var.resource_packs_gcp_rev + url = var.resource_packs_gcp_url + } + + variables = { + name = "${var.prefix}redis" + project = var.project + region = var.region + app_id = "$${context.app.id}" + env_id = "$${context.env.id}" + res_id = "$${context.res.id}" + memory_size_gb = var.memory_size_gb + location_id = var.location_id + alternative_location_id = var.alternative_location_id + authorized_network = var.authorized_network + redis_version = var.redis_version + display_name = var.display_name + reserved_ip_range = var.reserved_ip_range + weekly_maintenance_windows = var.weekly_maintenance_windows + auth_enabled = var.auth_enabled + } + }) + } +} diff --git a/humanitec-resource-defs/redis/basic/outputs.tf b/humanitec-resource-defs/redis/basic/outputs.tf new file mode 100644 index 0000000..28542ec --- /dev/null +++ b/humanitec-resource-defs/redis/basic/outputs.tf @@ -0,0 +1,3 @@ +output "id" { + value = humanitec_resource_definition.main.id +} diff --git a/humanitec-resource-defs/redis/basic/providers.tf b/humanitec-resource-defs/redis/basic/providers.tf new file mode 100644 index 0000000..86c4fc3 --- /dev/null +++ b/humanitec-resource-defs/redis/basic/providers.tf @@ -0,0 +1,10 @@ +terraform { + required_providers { + humanitec = { + source = "humanitec/humanitec" + version = "~> 0" + } + } + + required_version = ">= 1.3.0" +} diff --git a/humanitec-resource-defs/redis/basic/terraform.tfvars.example b/humanitec-resource-defs/redis/basic/terraform.tfvars.example new file mode 100644 index 0000000..be95700 --- /dev/null +++ b/humanitec-resource-defs/redis/basic/terraform.tfvars.example @@ -0,0 +1,15 @@ +alternative_location_id = "" +auth_enabled = false +authorized_network = "" +credentials = "" +display_name = "" +location_id = "" +memory_size_gb = "" +prefix = "" +project = "" +redis_version = "REDIS_4_0" +region = "" +reserved_ip_range = "" +resource_packs_gcp_rev = "ref/heads/main" +resource_packs_gcp_url = "https://github.com/humanitec-architecture/resource-packs-gcp.git" +weekly_maintenance_windows = {} \ No newline at end of file diff --git a/humanitec-resource-defs/redis/basic/variables.tf b/humanitec-resource-defs/redis/basic/variables.tf new file mode 100644 index 0000000..717f114 --- /dev/null +++ b/humanitec-resource-defs/redis/basic/variables.tf @@ -0,0 +1,65 @@ +variable "prefix" { + type = string +} + +variable "resource_packs_gcp_rev" { + type = string + default = "ref/heads/main" +} + +variable "resource_packs_gcp_url" { + type = string + default = "https://github.com/humanitec-architecture/resource-packs-gcp.git" +} + +variable "project" { + type = string +} + +variable "region" { + type = string +} + +variable "credentials" { + type = any +} + +variable "memory_size_gb" { + type = number +} + +variable "location_id" { + type = string +} + +variable "alternative_location_id" { + type = string +} + +variable "authorized_network" { + type = string +} + +variable "display_name" { + type = string +} + +variable "redis_version" { + type = string + default = "REDIS_4_0" +} + +variable "reserved_ip_range" { + type = string + default = null +} + +variable "weekly_maintenance_windows" { + type = any + default = {} +} + +variable "auth_enabled" { + type = bool + default = false +} diff --git a/modules/.gitkeep b/modules/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/modules/redis/basic/README.md b/modules/redis/basic/README.md new file mode 100644 index 0000000..abfd9dc --- /dev/null +++ b/modules/redis/basic/README.md @@ -0,0 +1,50 @@ + +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 1.3.0 | +| google | 5.10.0 | + +## Providers + +| Name | Version | +|------|---------| +| google | 5.10.0 | + +## Resources + +| Name | Type | +|------|------| +| [google_redis_instance.cache](https://registry.terraform.io/providers/hashicorp/google/5.10.0/docs/resources/redis_instance) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| alternative\_location\_id | n/a | `string` | n/a | yes | +| app\_id | n/a | `string` | n/a | yes | +| authorized\_network | n/a | `string` | n/a | yes | +| credentials | n/a | `any` | n/a | yes | +| display\_name | n/a | `string` | n/a | yes | +| env\_id | n/a | `string` | n/a | yes | +| location\_id | n/a | `string` | n/a | yes | +| memory\_size\_gb | n/a | `number` | n/a | yes | +| name | n/a | `string` | n/a | yes | +| project | n/a | `string` | n/a | yes | +| region | n/a | `string` | n/a | yes | +| res\_id | n/a | `string` | n/a | yes | +| auth\_enabled | n/a | `bool` | `false` | no | +| redis\_version | n/a | `string` | `"REDIS_4_0"` | no | +| reserved\_ip\_range | n/a | `string` | `null` | no | +| weekly\_maintenance\_windows | n/a | `any` | `{}` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| host | The IP address of the instance. | +| password | n/a | +| port | The IP address of the instance. | +| username | n/a | + \ No newline at end of file diff --git a/modules/redis/basic/main.tf b/modules/redis/basic/main.tf new file mode 100644 index 0000000..0b92694 --- /dev/null +++ b/modules/redis/basic/main.tf @@ -0,0 +1,29 @@ +resource "google_redis_instance" "cache" { + name = var.name + display_name = var.display_name + + tier = "STANDARD_HA" + location_id = var.location_id + alternative_location_id = var.alternative_location_id + + memory_size_gb = var.memory_size_gb + redis_version = var.redis_version + authorized_network = var.authorized_network + reserved_ip_range = var.reserved_ip_range + auth_enabled = var.auth_enabled + + dynamic "maintenance_policy" { + for_each = var.weekly_maintenance_windows + content { + weekly_maintenance_window { + day = maintenance_policy.value["day"] + start_time { + hours = maintenance_policy.value["start_hours"] + minutes = maintenance_policy.value["start_minutes"] + seconds = maintenance_policy.value["start_seconds"] + nanos = maintenance_policy.value["start_nanos"] + } + } + } + } +} diff --git a/modules/redis/basic/outputs.tf b/modules/redis/basic/outputs.tf new file mode 100644 index 0000000..a79ab35 --- /dev/null +++ b/modules/redis/basic/outputs.tf @@ -0,0 +1,19 @@ +output "host" { + description = "The IP address of the instance." + value = google_redis_instance.cache.host +} + +output "port" { + description = "The IP address of the instance." + value = google_redis_instance.cache.port +} + +output "username" { + # redis doesn't use usernames yet + value = "" +} + +output "password" { + value = google_redis_instance.cache.auth_string + sensitive = true +} diff --git a/modules/redis/basic/providers.tf b/modules/redis/basic/providers.tf new file mode 100644 index 0000000..906ca87 --- /dev/null +++ b/modules/redis/basic/providers.tf @@ -0,0 +1,22 @@ +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "5.10.0" + } + } + + required_version = ">= 1.3.0" +} + +provider "google" { + project = var.project + region = var.region + credentials = jsonencode(var.credentials) + default_labels = { + "managed-by" = "humanitec" + "hum-app-id" = var.app_id + "hum-env-id" = var.env_id + "hum-res-id" = replace(var.res_id, ".", "-") + } +} diff --git a/modules/redis/basic/terraform.tfvars.example b/modules/redis/basic/terraform.tfvars.example new file mode 100644 index 0000000..59a8316 --- /dev/null +++ b/modules/redis/basic/terraform.tfvars.example @@ -0,0 +1,16 @@ +alternative_location_id = "" +app_id = "" +auth_enabled = false +authorized_network = "" +credentials = "" +display_name = "" +env_id = "" +location_id = "" +memory_size_gb = "" +name = "" +project = "" +redis_version = "REDIS_4_0" +region = "" +res_id = "" +reserved_ip_range = "" +weekly_maintenance_windows = {} \ No newline at end of file diff --git a/modules/redis/basic/variables.tf b/modules/redis/basic/variables.tf new file mode 100644 index 0000000..02832df --- /dev/null +++ b/modules/redis/basic/variables.tf @@ -0,0 +1,67 @@ +variable "project" { + type = string +} + +variable "region" { + type = string +} + +variable "credentials" { + type = any +} + +variable "app_id" { + type = string +} + +variable "env_id" { + type = string +} + +variable "res_id" { + type = string +} + +variable "name" { + type = string +} + +variable "memory_size_gb" { + type = number +} + +variable "location_id" { + type = string +} + +variable "alternative_location_id" { + type = string +} + +variable "authorized_network" { + type = string +} + +variable "redis_version" { + type = string + default = "REDIS_4_0" +} + +variable "display_name" { + type = string +} + +variable "reserved_ip_range" { + type = string + default = null +} + +variable "weekly_maintenance_windows" { + type = any + default = {} +} + +variable "auth_enabled" { + type = bool + default = false +}