Skip to content

Null computed ListAttribute when data source is read at apply timeย #1102

@marshallford

Description

@marshallford

Hello ๐Ÿ‘‹๐Ÿผ I apologize if this is a bug in my provider and not the plugin framework. This has been a head scratcher, so I thought I would open an issue. Thank you.

Module version

github.com/hashicorp/terraform-plugin-framework v1.13.0

Relevant provider source code

"artifact_queries": schema.MapNestedAttribute{
	Optional:            true,
	NestedObject: schema.NestedAttributeObject{
		Attributes: map[string]schema.Attribute{
			"jq_filter": schema.StringAttribute{
				Required:            true,
				Validators: []validator.String{
					stringIsJQFilter(),
				},
			},
			"results": schema.ListAttribute{
				Computed:            true,
				ElementType:         jsontypes.NormalizedType{},
			},
		},
	},
},

Terraform Configuration Files

See here: marshallford/terraform-provider-ansible#79

Debug Output

https://gist.github.com/marshallford/38c159bd2ab5f7bb11119232bb717d8e

Expected Behavior

The data source attribute artifact_queries.example.results should be considered "unknown" until the deferred read. After the data source has been read the normal graph order of operations should allow the data source attribute to be referenced in resources/outputs/etc.

Actual Behavior

The ListAttribute is not shown in the Terraform plan output (with (known after apply)) and Terraform evaluates the attribute as null before the data source has been read. In contrast, another computed attribute (ansible_options.known_hosts, a ListAttribute within a SingleNestedAttribute) can be referenced when the data source is deferred without issue.

Example

  # data.ansible_navigator_run.test will be read during apply
  # (config refers to values not yet known)
 <= data "ansible_navigator_run" "test" {
      + ansible_navigator_binary = "/home/marshall/Documents/Projects/terraform-provider-ansible/.venv/bin/ansible-navigator"
      + ansible_options          = (known after apply)
      + artifact_queries         = {
          + "example" = {
              + jq_filter = "{foobar: \"test\"}"
              // !! Missing "results = (known after apply)" here !!
            },
        }
      + command                  = (known after apply)
...

Steps to Reproduce

  1. terraform init
  2. terraform plan

References

Sibling issue: marshallford/terraform-provider-ansible#79

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingupstream-terraformIssues that relate to Terraform CLI changes

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions