-
Notifications
You must be signed in to change notification settings - Fork 232
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
Default TypeList / TypeSet #142
Comments
Hi, Do someone have some workaround to this problem? Thanks. |
Hi, I'm still confused about resource example_box robin {
bundle = "b-x"
// "size" attribute of Set type is not specified here
} func resourceExampleBox() *schema.Resource {
return &schema.Resource{
Create: resourceExampleBoxCreate,
...
"size": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"width": {
Type: schema.TypeInt,
Optional: true,
Default: 100,
},
"height": {
Type: schema.TypeInt,
Optional: true,
Default: 50,
},
},
},
},
...
func resourceExampleBoxCreate(d *schema.ResourceData, m interface{}) error {
...
size := d.Get("size").(*schema.Set).List() // len: 0 here !!! why??? is it a bug or feature? Here is my discussion with @slapula regarding the subject, but it didn't help me to understand is it a bug or feature. I've also created an example provider to play around and check the unexpected behavior of the defaults. |
I'd also love some clarity on this issue |
From my understanding the way that defaults applied to "blocks" such as lists and sets require the block to be declared for it to work. As you can see in the below example the fields have default env variables and the field is a type list with a max item of one. For the default values to be propagated to the values in the Set/List field it requires you to declare that block. provider databricks {
host =....
basic_auth {}
} Without declaring the empty block terraform does not seem to populate default values. AFAIK you cannot set defaults on the set/list object itself but only the values it contains. What I cannot confirm is if this is the intended behavior of the sdk/terraform. Concrete example below: Provider field definition: |
This also seems to be contrary to what the current documentation for
Currently based on this the documentation is just plain wrong 😕 |
Terraform provides a test example for using a default for TypeList:
https://github.com/hashicorp/terraform/blob/master/helper/schema/schema_test.go#L3624
However if I define one in a provider I get:
foo: Default is not valid for lists or sets
I have also tried using a DefaultFunc:
Which compiles but doesn't provide a default, how would you go about achieving this?
Thanks!
The text was updated successfully, but these errors were encountered: