hashicorp / hashicorp/terraform-plugin-sdk

`ResourceDiff.Get()` doesn't return all the data

Open
#1,035 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
485
Forks
244
Avg merge
19h 57m
Merged PRs (30d)
4

Description

SDK version
v2.21.0
Relevant provider source code
&schema.Resource{ // Root resource
	Schema: map[string]*schema.Schema{
		"analysis_definition": {
			Type:     schema.TypeList,
			MaxItems: 1,
			Required: true,
			Elem: &schema.Resource{
				Schema: analysisDefinitionSchema,
			},
		},
	},
	CustomizeDiff: func(ctx context.Context, rd *schema.ResourceDiff, i any) error {
		helper.Logger.Printf("Data: %#v", rd.Get("string"))
		helper.Logger.Printf("Raw: %#v", rd.GetRawConfig())
		return nil
	},
}
Terraform Configuration Files

Some text was replaced but structure is unchanged
Note fields field is a TypeSet, and items is a TypeList

resource "analysis_definitions" "test" {
  analysis_definition {
    name        = "name"
    description = "description"
    model_id    = "d9f4e470-f4ad-456c-8b8e-47577a8212cd"
    node_id     = var.node_id
    inputs {
      type = "STRUCTURE"
      fields {
        name = "example1"
        type = "STRUCTURE"
        fields {
          name = "example2"
          type = "ARRAY"
          items {
            type = "STRUCTURE"
            fields {
              name   = "id"
              type   = "TEXT"
              source = "STATIC"
              value  = "This value doesnt appear!"
            }
          }
        }
      }
    }
  }
}

Debug Output

This is from my Logger.Printf() code. Some text was replaced but structure is unchanged.
https://gist.github.com/N1ark/805c152bc2cea3155189a6dfdf7c411f

Expected Behavior

Although the outputs of Data and Raw are different (one is a map[string]interface{} and the other is a cty.Value, they contain the same data.

Actual Behavior

The Data output seems to be cut - after a certain depth the data output by "Data" isn't present and is instead nil .
Simply search "items":[]interface {}{interface {}(nil)} in the gist to find it.
This data is present in Raw (search for "This value doesnt appear!").

Steps to Reproduce
  1. Setup a schema that goes deep enough (mine is done through a recursive function)
  2. Write the configuration that goes deep enough
  3. Add the given CustomizeDiff snippet
  4. terraform init && terraform plan --refresh=false
(Edit: clearer example)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ResourceDiff.Get and GetRawConfig entry points shown in the CustomizeDiff snippet, then reproduce the nested schema behavior using the provided Terraform configuration. Run terraform init && terraform plan --refresh=false and compare the Data and Raw outputs, including the nested items value; done means ResourceDiff.Get returns the same data present in Raw.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, terraform
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.