You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While using the s3-bucket component and trying to add logging to it, I want to use a logging_bucket_name_rendering_template format to work when null-label's tenant and environment are null. When I tried using the suggested format for when only tenant is null, I ran into an error with terraform not being able to format a null value with %s -- this is consistent with tf format syntax section docs (see last paragraph in that section).
See the example below.
I believe the required feature change is to remove any null values in the bucket_name line,
│ Error: Error infunctioncall
│
│ on ../../modules/example/main.tf line 30, in locals:
│ 30: final_bucket_name = format("%s-%s-%s-%%s", var.test_namespace, var.test_tenant, var.test_environment, var.test_stage, var.test_logging_bucket_name)
│ ├────────────────
│ │ while calling format(format, args...)
│ │ var.test_environment is "myEnviornment"
│ │ var.test_logging_bucket_name is "myLoggingBucketName"
│ │ var.test_namespace is "myNameSpace"
│ │ var.test_stage is "myStage"
│ │ var.test_tenant is null
│
│ Call to function"format" failed: unsupported value for"%s" at 3: null value cannot be formatted.
╵
Releasing state lock. This may take a few moments...
Expected Behavior
When null values are present in the null-label settings (eg, when environment is null), the format function should still generate a logging bucket name.
Use Case
NA
Describe Ideal Solution
Adjust this line to remove nulls before calling the format function.
If I can get feedback on a viable solution, I'm happy to submit a PR.
Alternatives Considered
Manually set the logging bucket as needed.
Additional Context
variable "test_namespace" {
type = string
description = "The namespace to use for the test"
default = "myNameSpace"
}
variable "test_tenant" {
type = string
description = "The tenant to use for the test"
default = null
}
variable "test_environment" {
type = string
description = "The environment to use for the test"
default = "myEnvironment"
}
variable "test_stage" {
type = string
description = "The stage to use for the test"
default = "myStage"
}
variable "test_logging_bucket_name" {
type = string
description = "The logging bucket name to use for the test"
}
locals {
non_null_values = compact([var.test_namespace, var.test_tenant, var.test_environment, var.test_stage, var.test_logging_bucket_name])
final_bucket_name = format("%s-%s-%s-%%s", local.non_null_values)
}
output "final_bucket_name" {
value = local.final_bucket_name
}
The text was updated successfully, but these errors were encountered:
westonplatter
changed the title
Question
S3-Bucket - make templated logging bucket name more flexible
Apr 3, 2023
westonplatter
added a commit
to westonplatter/terraform-aws-components
that referenced
this issue
Apr 7, 2023
The format recommended in the variable description for when not using tenant is wrong. What is needed is a correction to the documentation, not the code. The correct format is
Have a question? Please checkout our Slack Community or visit our Slack Archive.
Describe the Feature
While using the s3-bucket component and trying to add logging to it, I want to use a
logging_bucket_name_rendering_template
format to work when null-label'stenant
andenvironment
are null. When I tried using the suggested format for when onlytenant
is null, I ran into an error with terraform not being able to format a null value with%s
-- this is consistent with tf format syntax section docs (see last paragraph in that section).See the example below.
I believe the required feature change is to remove any null values in the bucket_name line,
Expected Behavior
When null values are present in the null-label settings (eg, when
environment
is null), the format function should still generate a logging bucket name.Use Case
NA
Describe Ideal Solution
Adjust this line to remove nulls before calling the format function.
Something like this,
If I can get feedback on a viable solution, I'm happy to submit a PR.
Alternatives Considered
Manually set the logging bucket as needed.
Additional Context
The text was updated successfully, but these errors were encountered: