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
I'd like to be able to define a variable like this in cdktf, where a is optional but b is not.
variable "complex" {
type = object({
a = optional(number, 1)
b = string
})
default = {}
}
Background context: I'm looking into cdktf adoption to try and simplify a large existing Terraform codebase.
The first area I'm looking at is removing duplicated complex variable type signatures. These can be up to ~30 lines that we manually keep in sync to work around this issue.
I'm planning on doing this by synthesising a bit of the module (such as specific variable definitions) by using a shared library but keeping the rest of the existing Terraform in place.
Happy to try and implement this
References
No response
Help Wanted
I'm interested in contributing a fix myself
Community Note
Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
If you are interested in working on this issue or have submitted a pull request, please leave a comment
The text was updated successfully, but these errors were encountered:
I am extremely interested in this feature as well. I am hoping by providing the example Hashi provides for HCL here, the complexity is less than you think.
The optional modifier takes one or two arguments.
Type: (Required) The first argument specifies the type of the attribute.
Default: (Optional) The second argument defines the default value that Terraform should use if the attribute is not present. This must be compatible with the attribute type. If not specified, Terraform uses a null value of the appropriate type as the default.
I don't think it would be too difficult to add a simple version of this. If you look at https://github.com/hashicorp/terraform-cdk/blob/main/packages/cdktf/lib/terraform-variable.ts there are some static functions meant for building complex types. A new method for optional could be created as a quick version. Building better default support would take some more thought.
Actually using complex variables effectively within cdktf is another issue, but having basic support may help make things easier.
Description
I'd like to be able to define a variable like this in cdktf, where
a
is optional butb
is not.Background context: I'm looking into cdktf adoption to try and simplify a large existing Terraform codebase.
The first area I'm looking at is removing duplicated complex variable type signatures. These can be up to ~30 lines that we manually keep in sync to work around this issue.
I'm planning on doing this by synthesising a bit of the module (such as specific variable definitions) by using a shared library but keeping the rest of the existing Terraform in place.
Happy to try and implement this
References
No response
Help Wanted
Community Note
The text was updated successfully, but these errors were encountered: