Skip to content

Avoid nested objects with a single optional field #3928

@danawillow

Description

@danawillow

For example, GKE addons_config has a bunch of nested objects with a single boolean field inside them:

			"addons_config": {
				Type:     schema.TypeList,
				Optional: true,
				Computed: true,
				MaxItems: 1,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"http_load_balancing": {
							Type:     schema.TypeList,
							Optional: true,
							Computed: true,
							MaxItems: 1,
							Elem: &schema.Resource{
								Schema: map[string]*schema.Schema{
									"disabled": {
										Type:     schema.TypeBool,
										Optional: true,
									},
								},
							},
						},
						"horizontal_pod_autoscaling": {
							Type:     schema.TypeList,
							Optional: true,
							Computed: true,
							MaxItems: 1,
							Elem: &schema.Resource{
								Schema: map[string]*schema.Schema{
									"disabled": {
										Type:     schema.TypeBool,
										Optional: true,
									},
								},
							},
						},
...etc

This means that hypothetically, a user could put the following in their schema:

addons_config {
  http_load_balancing {
  }
}

From the user's point of view, this behavior would probably just take the API-level default. However, what it actually does is set disabled = false, since we ForceSend the field. If we decide to keep these fields nested in this way, we should make the booleans Required in order to make their behavior more clear.

Marking as 3.0 since this would be a breaking change.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions