Skip to content

Commit

Permalink
refs #000: add default label to namespace resources (#35)
Browse files Browse the repository at this point in the history
* refs #000: add default label to namespace resources

* refs #000: update changelog

* Update CHANGELOG.md
  • Loading branch information
andypanix authored Nov 6, 2024
1 parent 6d33ff1 commit c9f04d2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ crash.log

# IDE files
.idea
.fleet

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

---

## [0.14.0] - 2024-11-06

[Compare with previous version](https://github.com/sparkfabrik/terraform-google-gcp-cloud-native-drupal-resources/compare/0.13.0...0.14.0)

### Added

- Add support to customize the default labels of Kubernetes resources created by this module.

## [0.13.0] - 2024-11-05

[Compare with previous version](https://github.com/sparkfabrik/terraform-google-gcp-cloud-native-drupal-resources/compare/0.12.1...0.13.0)
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ the random suffix `bucket_append_random_suffix` for the bucket name.

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | >= 4.47.0 |
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | >= 2.19 |
| <a name="provider_google"></a> [google](#provider\_google) | 5.40.0 |
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 2.31.0 |
| <a name="provider_random"></a> [random](#provider\_random) | 3.6.2 |
## Requirements

Expand All @@ -129,6 +129,7 @@ the random suffix `bucket_append_random_suffix` for the bucket name.
| <a name="input_create_buckets"></a> [create\_buckets](#input\_create\_buckets) | If true, the module will create a bucket for each project. | `bool` | `true` | no |
| <a name="input_create_clousql_dumps_bucket"></a> [create\_clousql\_dumps\_bucket](#input\_create\_clousql\_dumps\_bucket) | If true, the module will create a Google Storage bucket that can be used as a destination for CloudSQL dumps. The bucket will also be tagged with the global tags. | `bool` | `false` | no |
| <a name="input_create_databases_and_users"></a> [create\_databases\_and\_users](#input\_create\_databases\_and\_users) | If true, the module will create a user and a database for each project. | `bool` | `true` | no |
| <a name="input_default_k8s_labels"></a> [default\_k8s\_labels](#input\_default\_k8s\_labels) | A map of labels to be applied to all the kubernetes resources created by this module. If a resource specify a map of labels, the default labels will merged with those specified in the resource. | `map(string)` | <pre>{<br> "managed-by": "terraform"<br>}</pre> | no |
| <a name="input_drupal_projects_list"></a> [drupal\_projects\_list](#input\_drupal\_projects\_list) | The list of Drupal projects, add a project name and this will create all infrastructure resources needed to run your project (bucket, database, user with relative credentials). Database resources are created in the CloudSQL instance you specified. Please not that you can assign only a database to a single user, the same user cannot be assigned to multiple databases. The default values are thought for a production environment, they will need to be adjusted accordingly for a stage environment. | <pre>list(object({<br> project_name = string<br> gitlab_project_id = number<br> release_branch_name = optional(string, "main")<br> kubernetes_namespace = optional(string, null)<br> kubernetes_namespace_labels = optional(map(string), {})<br> helm_release_name = optional(string, null)<br> database_name = optional(string, null)<br> database_user_name = optional(string, null)<br> database_host = optional(string, null)<br> database_port = optional(number, 3306)<br> bucket_name = optional(string, null)<br> bucket_host = optional(string, "storage.googleapis.com")<br> bucket_append_random_suffix = optional(bool, true)<br> bucket_location = optional(string, null)<br> bucket_storage_class = optional(string, "STANDARD")<br> bucket_enable_versioning = optional(bool, true)<br> bucket_enable_disaster_recovery = optional(bool, true)<br> bucket_force_destroy = optional(bool, false)<br> bucket_legacy_public_files_path = optional(string, "/public")<br> bucket_set_all_users_as_viewer = optional(bool, false)<br> bucket_labels = optional(map(string), {})<br> bucket_tag_list = optional(list(string), [])<br> bucket_obj_adm = optional(list(string), [])<br> bucket_obj_vwr = optional(list(string), [])<br> bucket_soft_delete_retention_seconds = optional(number, 604800)<br> }))</pre> | n/a | yes |
| <a name="input_global_tags"></a> [global\_tags](#input\_global\_tags) | A list of tags to be applied to all the drupal buckets, in the form <TAG\_KEY\_SHORTNAME>/<TAG\_VALUE\_SHORTNAME>. If a resource specify a list of tags, the global tags will be overridden and replaced by those specified in the resource. Please note that actually only the buckets are tagged by this module. | `list(string)` | `[]` | no |
| <a name="input_logging_bucket_name"></a> [logging\_bucket\_name](#input\_logging\_bucket\_name) | The name of the logging bucket. If empty, no logging bucket will be added and bucket logs will be disabled. | `string` | `""` | no |
Expand Down
5 changes: 4 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ locals {
namespace_list = [
for p in var.drupal_projects_list : {
namespace = p.kubernetes_namespace == null ? "${p.project_name}-${p.gitlab_project_id}-${p.release_branch_name}" : p.kubernetes_namespace
labels = p.kubernetes_namespace_labels
labels = merge(
p.kubernetes_namespace_labels,
var.default_k8s_labels
)
}
]
}
Expand Down
8 changes: 2 additions & 6 deletions secrets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ resource "kubernetes_secret" "bucket_secret_name" {
name = each.value.helm_release_name == null ? "drupal-${each.value.release_branch_name}-${each.value.project_id}-bucket" : "${each.value.helm_release_name}-bucket"
namespace = var.use_existing_kubernetes_namespaces ? each.value.namespace : kubernetes_namespace.namespace[each.value.namespace].metadata[0].name
annotations = {}
labels = {
"app.kubernetes.io/managed-by" = "terraform"
}
labels = var.default_k8s_labels
}
data = {
"endpoint" = each.value.host
Expand All @@ -48,9 +46,7 @@ resource "kubernetes_secret" "database_secret_name" {
name = each.value.helm_release_name == null ? "drupal-${each.value.release_branch_name}-${each.value.project_id}-db-user" : "${each.value.helm_release_name}-db-user"
namespace = var.use_existing_kubernetes_namespaces ? each.value.namespace : kubernetes_namespace.namespace[each.value.namespace].metadata[0].name
annotations = {}
labels = {
"app.kubernetes.io/managed-by" = "terraform"
}
labels = var.default_k8s_labels
}
data = {
"endpoint" = each.value.host != null ? each.value.host : ""
Expand Down
8 changes: 8 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ variable "global_tags" {
default = []
}

variable "default_k8s_labels" {
description = "A map of labels to be applied to all the kubernetes resources created by this module. If a resource specify a map of labels, the default labels will merged with those specified in the resource."
type = map(string)
default = {
"managed-by" = "terraform"
}
}

variable "drupal_projects_list" {
description = "The list of Drupal projects, add a project name and this will create all infrastructure resources needed to run your project (bucket, database, user with relative credentials). Database resources are created in the CloudSQL instance you specified. Please not that you can assign only a database to a single user, the same user cannot be assigned to multiple databases. The default values are thought for a production environment, they will need to be adjusted accordingly for a stage environment."
type = list(object({
Expand Down

0 comments on commit c9f04d2

Please sign in to comment.