-
Notifications
You must be signed in to change notification settings - Fork 991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with generate_name in kubernetes_role_binding and kubernetes_cluster_role_binding #588
Comments
This issue has been open 180 days with no activity. If this issue is reproducible with the latest version of the provider and with Terraform 0.12, please comment. Otherwise this issue will be closed in 30 days. |
+1 still a problem with Terraform 0.12 and provider version 1.11.2 |
It is still present with version 1.11.4 and Terraform 0.13 (I have reasons for requiring this version) but that should not matter much as it's the plugin that gives an error. Personally, I don't yet mind as I prefix it anyways and require just 1 name for the governing cluster role but it was unusual to see it unsupported while all other resource types support it, and even the docs claim it is. |
this issue is still exist with terraform version 1.0 and kubernetes provider version
and got
provider details:
|
This is an issue with your module and not the resource. Let me explain why I think this issue should be closed... The documentation describes the SOLUTON:
To comply with the field you must set your module variables to be variable "generate_name" {
description = <<-EOT
Prefix, used by the server, to generate a unique name. This value will also be combined with a unique suffix.
Only one of `name` or `generate_name` can be provide.
EOT
type = string
default = null
nullable = true
}
variable "name" {
description = "Name of the resource, must be unique. Only one of `name` or `generate_name` can be provide."
type = string
default = null
nullable = true
}
...
resource "kubernetes_role_v1" "r" {
metadata {
annotations = var.annotations
generate_name = var.generate_name # pass null be default
labels = var.labels
name = var.name # pass null be default
namespace = var.role_namespace
}
...
} Then you have two distinct ways to call the module: module "name_example" {
source = "../../modules/role"
name = "pod-reader"
...
} This will result in a Role with the name: module "generate_name_example" {
source = "../../modules/role"
generate_name = "pod-reader"
...
} This will result in a Role with the name: You will still get an error if the user calls the module -> resource incorrectly i.e. by providing both module "generate_name_example" {
source = "../../modules/role"
name = "pod-reader"
generate_name = "pod-reader"
...
} will result in this error from the resource
|
interesting. The |
I suppose a workaround could be to use the random data resource to have terraform generate the random suffix. Not ideal, but that would look something like this: variable "generate_name" {
description = <<-EOT
Prefix, used by the server, to generate a unique name. This value will also be combined with a unique suffix.
Only one of `name` or `generate_name` can be provide.
EOT
type = string
default = null
nullable = true
}
variable "name" {
description = "Name of the resource, must be unique. Only one of `name` or `generate_name` can be provide."
type = string
default = null
nullable = true
}
resource "random_string" "generate_name_suffix" {
length = 5
special = false
lower = true
number = false
}
resource "kubernetes_role_v1" "r" {
metadata {
annotations = var.annotations
generate_name = var.generate_name # https://github.com/hashicorp/terraform-provider-kubernetes/issues/588
labels = var.labels
name = var.name != null ? var.name : "${var.generate_name}${random_string.generate_name_suffix.id}"
namespace = var.role_namespace
}
...
} |
can |
I'll provide a fix for these 3 resource: #1899 |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Terraform Version
Terraform v0.12.5
Affected Resource(s)
Please list the resources as a list, for example:
Terraform Configuration Files
Expected Behavior
Actual Behavior
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
References
https://www.terraform.io/docs/providers/kubernetes/r/role_binding.html
https://www.terraform.io/docs/providers/kubernetes/r/cluster_role_binding.html
It seems there is only a typo in arg for schema definition, so this should easy to be fixed.
The text was updated successfully, but these errors were encountered: