Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions k8s/k8s-namespace/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# k8s-namespace

Create a namespace in kubernetes

## Behavior

This module includes lifecycle rules that ignore changes to metadata labels and annotations. This means that external tools (like Rancher) can modify labels and annotations without Terraform attempting to revert those changes.

If you need to update labels or annotations through Terraform after the namespace is created, you have two options:
1. Use `terraform apply -replace="kubernetes_namespace.ns"` to force recreation
2. Temporarily comment out the lifecycle block, apply changes, then uncomment it

<!-- BEGIN_TF_DOCS -->
## Requirements

Expand Down
12 changes: 10 additions & 2 deletions k8s/k8s-namespace/namespace.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
resource "kubernetes_namespace" "ns" {
metadata {
name = var.name
labels = merge(local.interpolated_tags, var.labels)
name = var.name
labels = merge(local.interpolated_tags, var.labels)
annotations = var.annotations
}

lifecycle {
ignore_changes = [
metadata[0].labels,
metadata[0].annotations,
]
}
}
8 changes: 7 additions & 1 deletion k8s/k8s-namespace/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ variable "tags" {

# module specific variables
variable "labels" {
description = "Labels to add to the secret"
description = "Labels to add to the namespace"
type = map(any)
default = {}
}

variable "annotations" {
description = "Annotations to add to the namespace"
type = map(any)
default = {}
}
Expand Down
Loading