diff --git a/.gitignore b/.gitignore index 059ac21..1d704d3 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1adf35b..6eff5c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index c2fe21c..17642ad 100644 --- a/README.md +++ b/README.md @@ -107,8 +107,8 @@ the random suffix `bucket_append_random_suffix` for the bucket name. | Name | Version | |------|---------| -| [google](#provider\_google) | >= 4.47.0 | -| [kubernetes](#provider\_kubernetes) | >= 2.19 | +| [google](#provider\_google) | 5.40.0 | +| [kubernetes](#provider\_kubernetes) | 2.31.0 | | [random](#provider\_random) | 3.6.2 | ## Requirements @@ -129,6 +129,7 @@ the random suffix `bucket_append_random_suffix` for the bucket name. | [create\_buckets](#input\_create\_buckets) | If true, the module will create a bucket for each project. | `bool` | `true` | no | | [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 | | [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 | +| [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)` |
{
"managed-by": "terraform"
}
| no | | [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. |
list(object({
project_name = string
gitlab_project_id = number
release_branch_name = optional(string, "main")
kubernetes_namespace = optional(string, null)
kubernetes_namespace_labels = optional(map(string), {})
helm_release_name = optional(string, null)
database_name = optional(string, null)
database_user_name = optional(string, null)
database_host = optional(string, null)
database_port = optional(number, 3306)
bucket_name = optional(string, null)
bucket_host = optional(string, "storage.googleapis.com")
bucket_append_random_suffix = optional(bool, true)
bucket_location = optional(string, null)
bucket_storage_class = optional(string, "STANDARD")
bucket_enable_versioning = optional(bool, true)
bucket_enable_disaster_recovery = optional(bool, true)
bucket_force_destroy = optional(bool, false)
bucket_legacy_public_files_path = optional(string, "/public")
bucket_set_all_users_as_viewer = optional(bool, false)
bucket_labels = optional(map(string), {})
bucket_tag_list = optional(list(string), [])
bucket_obj_adm = optional(list(string), [])
bucket_obj_vwr = optional(list(string), [])
bucket_soft_delete_retention_seconds = optional(number, 604800)
}))
| n/a | yes | | [global\_tags](#input\_global\_tags) | A list of tags to be applied to all the drupal buckets, in the form /. 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 | | [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 | diff --git a/main.tf b/main.tf index 78dfda9..824504b 100644 --- a/main.tf +++ b/main.tf @@ -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 + ) } ] } diff --git a/secrets.tf b/secrets.tf index 9e1c046..e6bcda5 100644 --- a/secrets.tf +++ b/secrets.tf @@ -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 @@ -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 : "" diff --git a/variables.tf b/variables.tf index 7a7ffd0..aa12894 100644 --- a/variables.tf +++ b/variables.tf @@ -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({