Skip to content
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

panic: interface conversion: interface {} is nil, not map[string]interface {} #35083

Closed
TheNilesh opened this issue Apr 25, 2024 · 4 comments · Fixed by #35090
Closed

panic: interface conversion: interface {} is nil, not map[string]interface {} #35083

TheNilesh opened this issue Apr 25, 2024 · 4 comments · Fixed by #35090
Assignees

Comments

@TheNilesh
Copy link

TheNilesh commented Apr 25, 2024

Terraform Version

Terraform v1.8.1
on linux_amd64
+ provider registry.terraform.io/hashicorp/external v2.3.3

Your version of Terraform is out of date! The latest version
is 1.8.2. You can update by downloading from https://www.terraform.io/downloads.html

Terraform Configuration Files

resource "pf9_cluster" "cluster" {
  name = var.cluster_name
  addons = {
    "kubernetes-dashboard" = null
  }
}

Debug Output

https://gist.github.com/TheNilesh/641b223a094ecc78252c4cd6a675b5f4

Expected Behavior

No crash

Actual Behavior

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Steps to Reproduce

  1. Find a terraform provider that has been developed using terraform plugin framework
  2. The provider should have an attribute of type map_nested. map-nested
  3. The practitioner should set the value of the key from the map to null and run terraform apply

Example terraform configuration to reproduce this error

resource "examplecloud_thing" "example" {
  example_attribute = {
    "key1" = {
        attr = "one"
    },
    # The following attribute value will cause panic. 
    # I believe terraform is trying to load the value of the attribute "key2" in map[string]interface{} 
    # before checking if it is nil.
    "key2" = null
  }
}

Additional Context

  • I am the author of the terraform provider. Here's the schema
  • The provider is developed using a plugin framework. During debugging this crash happens after calling ModifyPlan()
  • The issue is associated with the setting value of the map_nested element to null in the config. In this case addons is of type map_nested and kubernetes-dashboard(key inside the map) was set to null by the practitioner.

References

No response

@TheNilesh TheNilesh added bug new new issue not yet triaged labels Apr 25, 2024
@jbardin jbardin added the core label Apr 25, 2024
@jbardin
Copy link
Member

jbardin commented Apr 25, 2024

Hi @TheNilesh,

Thanks for filing the issue. Can you supply the schema you are using for the addons attribute, along with any actions taken by the provider when creating the plan? While the crash is definitely not intended here, we first need to determine if the value being returned by the provider is valid and what it looks like.

Thanks!

@jbardin jbardin added the waiting for reproduction unable to reproduce issue without further information label Apr 25, 2024
@TheNilesh
Copy link
Author

Here's schema:

"addons": schema.MapNestedAttribute{
	NestedObject: schema.NestedAttributeObject{
		Attributes: map[string]schema.Attribute{
			"params": schema.MapAttribute{
				ElementType: types.StringType,
				Optional:    true,
				Computed:    true,
				PlanModifiers: []planmodifier.Map{
					mapplanmodifier.UseStateForUnknown(),
				},
			},
			"phase": schema.StringAttribute{
				Computed: true,
			},
			"version": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
				},
			},
		},
		CustomType: AddonsType{
			ObjectType: types.ObjectType{
				AttrTypes: AddonsValue{}.AttributeTypes(ctx),
			},
		},
	},
	Optional: true,
	Computed: true,
	PlanModifiers: []planmodifier.Map{
		mapplanmodifier.UseStateForUnknown(),
	},
},

@TheNilesh
Copy link
Author

@jbardin Have you been able to reproduce the issue? I have also added Steps to Reproduce in the issue description, hope it helps.

@jbardin jbardin removed new new issue not yet triaged waiting for reproduction unable to reproduce issue without further information labels Apr 26, 2024
@jbardin
Copy link
Member

jbardin commented Apr 26, 2024

Thank you for the extra info @TheNilesh, we will look into this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants