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

Crash when creating ldap object with computed attribute value #6

Open
philsttr opened this issue Dec 23, 2017 · 1 comment
Open

Crash when creating ldap object with computed attribute value #6

philsttr opened this issue Dec 23, 2017 · 1 comment

Comments

@philsttr
Copy link

philsttr commented Dec 23, 2017

The terraform-provider-ldap crashes if an ldap_object attribute's value is derived from a computed value.

For example, I have taken the example given in the README.md, and changed the uid/gid attribute values to be computed values (from a random integer) as follows

resource "random_integer" "id" {
  min = 500
  max = 1000
}

resource "ldap_object" "foo" {
  # DN must be complete (no RDN!)
  dn = "uid=foo,dc=example,dc=com"

  # classes are specified as an array
  object_classes = [
    "inetOrgPerson",
    "posixAccount",
  ]

  # attributes are specified as a set of 1-element maps
  attributes = [
    { sn = "10" },
    { cn = "bar" },
    { uidNumber = "${random_integer.id.result}" },
    { gidNumber = "${random_integer.id.result}" },
    { homeDirectory = "/home/billy" },
    { loginShell = "/bin/bash" },
    # when an attribute has multiple values, it must be specified multiple times
    { mail = "[email protected]" },
    { mail = "[email protected]" },
  ]
}

Running terraform plan will give the following error:

Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

Error: Error running plan: 1 error(s) occurred:

* ldap_object.foo: 1 error(s) occurred:

* ldap_object.foo: unexpected EOF


panic: interface conversion: interface {} is nil, not map[string]interface {}
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: goroutine 44 [running]:
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: main.attributeHash(0x0, 0x0, 0x0)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/Pryz/terraform-provider-ldap/resource_ldap_object.go:365 +0x31b
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/helper/schema.(*Set).hash(0xc4203953c0, 0x0, 0x0, 0xc420018080, 0xc)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/helper/schema/set.go:205 +0x3d
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/helper/schema.(*Set).add(0xc4203953c0, 0x0, 0x0, 0xc420368f00, 0x0, 0xc4200176a0)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/helper/schema/set.go:192 +0x72
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/helper/schema.(*ConfigFieldReader).readSet(0xc4203ba4b0, 0xc4203c0260, 0x1, 0x1, 0xc420368f00, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/helper/schema/field_reader_config.go:289 +0x413
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/helper/schema.(*ConfigFieldReader).readField(0xc4203ba4b0, 0xc4203c0260, 0x1, 0x1, 0xc42000ec00, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/helper/schema/field_reader_config.go:115 +0xc56
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/helper/schema.(*ConfigFieldReader).ReadField(0xc4203ba4b0, 0xc4203c0260, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7fcba0b33000, ...)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/helper/schema/field_reader_config.go:27 +0x110
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/helper/schema.(*MultiLevelFieldReader).ReadFieldExact(0xc420394ec0, 0xc4203c0260, 0x1, 0x1, 0xdd5c1e, 0x6, 0x0, 0x0, 0x0, 0x0, ...)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/helper/schema/field_reader_multi.go:31 +0x12e
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/helper/schema.(*ResourceData).get(0xc4203a6a80, 0xc4203c0260, 0x1, 0x1, 0xc4203c0212, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/helper/schema/resource_data.go:497 +0x16e
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/helper/schema.(*ResourceData).getChange(0xc4203a6a80, 0xdd9c43, 0xa, 0xc420371201, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/helper/schema/resource_data.go:473 +0x135
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/helper/schema.(*ResourceData).diffChange(0xc4203a6a80, 0xdd9c43, 0xa, 0xc420397d10, 0xc420373610, 0x12ef640, 0xc4203a6a80, 0x1)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/helper/schema/resource_data.go:450 +0xa5
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/helper/schema.schemaMap.diffSet(0xc42036e780, 0xdd9c43, 0xa, 0xc420368f00, 0xc420373610, 0x12ef640, 0xc4203a6a80, 0x42af00, 0x0, 0x0)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/helper/schema/schema.go:1030 +0x66
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/helper/schema.schemaMap.diff(0xc42036e780, 0xdd9c43, 0xa, 0xc420368f00, 0xc420394dc0, 0x12ef640, 0xc4203a6a80, 0x756ea123cb9d00, 0x0, 0x0)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/helper/schema/schema.go:780 +0x521
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/helper/schema.schemaMap.Diff(0xc42036e780, 0xc4202f2d70, 0xc42036fec0, 0x0, 0xdb5000, 0xc4203a2100, 0x0, 0x0, 0x0)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/helper/schema/schema.go:424 +0x24a
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/helper/schema.(*Resource).Diff(0xc42034ae70, 0xc4202f2d70, 0xc42036fec0, 0xdb5000, 0xc4203a2100, 0x1, 0xc4203ba270, 0xc4203ba270)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/helper/schema/resource.go:252 +0x187
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/helper/schema.(*Provider).Diff(0xc42034aee0, 0xc4202f2d20, 0xc4202f2d70, 0xc42036fec0, 0x7fcba0b33000, 0x0, 0x18)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/helper/schema/provider.go:296 +0xa4
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: github.com/hashicorp/terraform/plugin.(*ResourceProviderServer).Diff(0xc42000dc20, 0xc420394740, 0xc42038fcb0, 0x0, 0x0)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /root/go/src/github.com/hashicorp/terraform/plugin/resource_provider.go:538 +0x57
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: reflect.Value.call(0xc4202eec60, 0xc42000e6f8, 0x13, 0xdd3fdf, 0x4, 0xc420326f20, 0x3, 0x3, 0xc42036b680, 0xc42001cae0, ...)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /usr/lib/golang/src/reflect/value.go:434 +0x905
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: reflect.Value.Call(0xc4202eec60, 0xc42000e6f8, 0x13, 0xc42002c720, 0x3, 0x3, 0x12ec9e0, 0xc42036b4a0, 0xc4203563c0)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /usr/lib/golang/src/reflect/value.go:302 +0xa4
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: net/rpc.(*service).call(0xc42038c580, 0xc4202f2780, 0xc4200169c0, 0xc4202f7880, 0xc42000dd00, 0xc4e060, 0xc420394740, 0x16, 0xc4e0a0, 0xc42038fcb0, ...)
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /usr/lib/golang/src/net/rpc/server.go:381 +0x142
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap: created by net/rpc.(*Server).ServeCodec
2017-12-23T00:05:44.580Z [DEBUG] plugin.terraform-provider-ldap:        /usr/lib/golang/src/net/rpc/server.go:475 +0x36b
2017/12/23 00:05:44 [ERROR] root: eval: *terraform.EvalDiff, err: unexpected EOF
2017/12/23 00:05:44 [ERROR] root: eval: *terraform.EvalSequence, err: unexpected EOF
2017/12/23 00:05:44 [TRACE] [walkPlan] Exiting eval tree: ldap_object.foo
2017/12/23 00:05:44 [TRACE] dag/walk: upstream errored, not walking "provider.ldap (close)"
2017/12/23 00:05:44 [TRACE] dag/walk: upstream errored, not walking "meta.count-boundary (count boundary fixup)"
2017/12/23 00:05:44 [TRACE] dag/walk: upstream errored, not walking "root"
2017/12/23 00:05:44 [DEBUG] plugin: waiting for all plugin processes to complete...
2017-12-23T00:05:44.582Z [WARN ] plugin: error closing client during Kill: err="connection is shut down"
2017-12-23T00:05:44.582Z [DEBUG] plugin: plugin process exited: path=/opt/terraform/terraform-provider-ldap
2017-12-23T00:05:44.584Z [WARN ] plugin: error closing client during Kill: err="unexpected EOF"
2017-12-23T00:05:44.584Z [DEBUG] plugin: plugin process exited: path=/opt/terraform/terraform-provider-random_v1.1.0_x4



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

Terraform crashed! This is always indicative of a bug within Terraform.
A crash log has been placed at "crash.log" relative to your current
working directory. It would be immensely helpful if you could please
report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version. That
information is available on the first line of crash.log. You can also
get it by running 'terraform --version' on the command line.

[1]: https://github.com/hashicorp/terraform/issues

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

crash.log

This works fine if I change the uid/gid back to static values. I only see the crash when they are computed values.

terraform v0.10.8
centos 7.4

philsttr pushed a commit to philsttr/terraform that referenced this issue Jan 5, 2018
…computed.

This fixes a problem for fields of type `schema.TypeSet`, whose elements are of type `schema.TypeMap`, whose elements are computed.

For example, consider the following schema...

```
	"maps": &schema.Schema{
		Type:        schema.TypeSet,
		Set:         mapHash,
		MinItems:    0,

		Elem: &schema.Schema{
			Type:        schema.TypeMap,
			MinItems:    1,
			MaxItems:    1,
			Elem: &schema.Schema{
				Type:        schema.TypeString,
			},
		},
		Optional: true,
	},
```

Note that the `mapHash` function determines the unique ID of an item (a map) so that a proper set can be built.

Without this change, the `mapHash` function will be passed `nil` for computed maps (since field_reader.ReadField returns null for maps with computed entries).
A proper hash for `nil` cannot be accurately determined.  You could theoretically always return the same value, but that breaks downstream logic that assumes each element will have a unique hash.

With this change, since the list is marked as computed, `mapHash` is not invoked for each element.

This is causing Pryz/terraform-provider-ldap#6
@philsttr
Copy link
Author

philsttr commented Jan 5, 2018

Tracked this down to a potential problem in terraform. I've submitted a PR (hashicorp/terraform#17049) to hopefully fix.

philsttr pushed a commit to philsttr/terraform that referenced this issue Jan 8, 2018
…computed.

This fixes a problem for fields of type `schema.TypeSet`, whose elements are of type `schema.TypeMap`, whose elements are computed.

For example, consider the following schema...

```
	"maps": &schema.Schema{
		Type:        schema.TypeSet,
		Set:         mapHash,
		MinItems:    0,

		Elem: &schema.Schema{
			Type:        schema.TypeMap,
			MinItems:    1,
			MaxItems:    1,
			Elem: &schema.Schema{
				Type:        schema.TypeString,
			},
		},
		Optional: true,
	},
```

Note that the `mapHash` function determines the unique ID of an item (a map) so that a proper set can be built.

Without this change, the `mapHash` function will be passed `nil` for computed maps (since field_reader.ReadField returns null for maps with computed entries).
A proper hash for `nil` cannot be accurately determined.  You could theoretically always return the same value, but that breaks downstream logic that assumes each element will have a unique hash.

With this change, since the list is marked as computed, `mapHash` is not invoked for each element.

This is causing Pryz/terraform-provider-ldap#6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant