mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
4439a7dcf4
Don't lose default values set within a nested block.
71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package test
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
)
|
|
|
|
func testResourceDefaults() *schema.Resource {
|
|
return &schema.Resource{
|
|
Create: testResourceDefaultsCreate,
|
|
Read: testResourceDefaultsRead,
|
|
Delete: testResourceDefaultsDelete,
|
|
Update: testResourceDefaultsUpdate,
|
|
|
|
Importer: &schema.ResourceImporter{
|
|
State: schema.ImportStatePassthrough,
|
|
},
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
"default_string": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
Default: "default string",
|
|
},
|
|
"default_bool": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
Default: true,
|
|
},
|
|
"nested": {
|
|
Type: schema.TypeSet,
|
|
Optional: true,
|
|
ForceNew: true,
|
|
Elem: &schema.Resource{
|
|
Schema: map[string]*schema.Schema{
|
|
"string": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
Default: "default nested",
|
|
},
|
|
"optional": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func testResourceDefaultsCreate(d *schema.ResourceData, meta interface{}) error {
|
|
d.SetId(fmt.Sprintf("%x", rand.Int63()))
|
|
return testResourceDefaultsRead(d, meta)
|
|
}
|
|
|
|
func testResourceDefaultsUpdate(d *schema.ResourceData, meta interface{}) error {
|
|
return testResourceDefaultsRead(d, meta)
|
|
}
|
|
|
|
func testResourceDefaultsRead(d *schema.ResourceData, meta interface{}) error {
|
|
return nil
|
|
}
|
|
|
|
func testResourceDefaultsDelete(d *schema.ResourceData, meta interface{}) error {
|
|
d.SetId("")
|
|
return nil
|
|
}
|