Skip to content

Commit da065b3

Browse files
committed
Decouple installation name from Kubernetes namespace name
1 parent 24c7fea commit da065b3

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

locals.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
locals {
2-
namespace = data.kubernetes_namespace.this.metadata.0.name
3-
account_id = data.aws_caller_identity.current.account_id
2+
namespace_name = coalesce(var.namespace_name, var.name)
3+
namespace = data.kubernetes_namespace.this.metadata.0.name
4+
account_id = data.aws_caller_identity.current.account_id
45
}

main.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@ resource "kubernetes_namespace" "this" {
22
count = var.namespace_deploy ? 1 : 0
33

44
metadata {
5-
name = var.name
5+
name = local.namespace_name
66

77
labels = {
8-
name = var.name
8+
name = local.namespace_name
99
description = var.description
1010
}
1111
}
1212
}
1313

14+
// Retrieving this data will ensure that the target Kubernetes namespace exists
15+
// before proceeding
1416
data "kubernetes_namespace" "this" {
1517
metadata {
16-
name = var.name
18+
name = local.namespace_name
1719
}
1820

1921
depends_on = [
20-
kubernetes_namespace.this
22+
kubernetes_namespace.this,
2123
]
2224
}
2325

variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ variable "iam_deploy" {
2323

2424
variable "name" {
2525
default = "velero"
26-
description = "Namespace name"
26+
description = "Installation name"
2727
type = string
2828
}
2929

30+
variable "namespace_name" {
31+
description = "Kubernetes namespace name. If left unset, the `name` variable will be used instead."
32+
type = string
33+
optional = true
34+
}
35+
3036
variable "description" {
3137
default = "velero-back-up-and-restore"
3238
description = "Namespace description"

0 commit comments

Comments
 (0)