schema.Resource with schema.TypeMap does not contain values

788 views
Skip to first unread message

Raphael Randschau

unread,
Dec 15, 2015, 7:24:32 AM12/15/15
to Terraform
Hey there!

I'm writing new AWS resources for the API Gateway for terraform. But I'm running into a problem which does not make sense to me.

The resource definition compiles & I can interact with the AWS API, but there's a parameter that needs to be of type `schema.TypeMap` and 
I only get the keys, not the values.

My resource definition looks like this: 

```
func resourceAwsApiGatewayMethod() *schema.Resource {
// snip …
"parameters": &schema.Schema{
Type:     schema.TypeMap,
Optional: true,
ForceNew: true,
},
}
```

To my understanding, given a terraform script like this:

```
resource "aws_api_gateway_method" "users-get" {
  parameters {
    integration.request.header.host = "value"
  }
}
```

should result in a map if one key: `integration.request.header.host`, and one value, `value`. However, I get a map with the correct key, and an empty string as value.

Now - why is that? I've taken a look at the existing resources, but they seem to operate just like my new resource and work properly.

Ideas are welcome - the entire source is available here: https://github.com/hashicorp/terraform/pull/4295

--
Raphael

Paul Hinze

unread,
Dec 16, 2015, 2:46:58 PM12/16/15
to terrafo...@googlegroups.com
Hi Raphael,

Sorry for the trouble here, and thanks for your work on this so far! I believe you're seeing this behavior because TypeMap does not support keys with dots in them. This is because the internal state storage format uses dot delimited fields to denote nesting.

Based on my reading of the API docs for the API Gateway Method, I'd recommend working around this limitation by switching parameters to a TypeSet with a few nested fields, something like this:

"parameter": &schema.Schema{
  Type: schema.TypeSet
  Elem: &schema.Resource{
    Schema: map[string]*schema.Schema{
      "location": &schema.Schema{ /* ... */ },
      "name": &schema.Schema{ /* ... */ },
      "required": &schema.Schema{ /* ... */ },
    }
  },
}

This would let users write config like this:

resource "aws_api_gateway_method" "users-get" {
  # ...
  parameter {
    location = "header"
    name     = "host"
    required = true
  }
  parameter {
    location = "querystring"
    name     = "apikey"
    required = false
  }
}

And you should be able to find plenty of examples elsewhere in the AWS provider to see how to interact with the *schema.Set you'll get back from d.Get("parameter").

Let me know if this makes sense to you!

Paul

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/7233777d-ecd9-431e-aae3-b90c7295036a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages