terraform-provider-openapi icon indicating copy to clipboard operation
terraform-provider-openapi copied to clipboard

Support for Map[string]string

Open dikhan opened this issue 5 years ago • 3 comments

Is your feature request related to a problem?

Currently, the provider only supports complex object data structures (with nested properties etc) but it's not possible to have properties that are Map[string]string.

Describe the solution you'd like

As per swagger spec HashMaps of key/value strings can be described as follows:

definitions:
  HashMapExample:
    type: object
    additionalProperties:
      type: string # this defines the values of the map being strings

And the expectation would be to have that property translated to the following terraform schema which effectively is a Map[string]string:

 &schema.Schema{
		Type: schema.TypeMap,
		Elem: &schema.Schema{Type: schema.TypeString},
	}

Acceptance criteria

What's required to consider this feature request complete?

  • User should be able to defined hash maps as described above and be able to define that property accordingly in the terraform configuration file.

Checklist

Don't forget to go through the checklist to make sure the issue is created properly:

  • [x] I have added a corresponding label (feature request/bug/etc) to the issue (right side menu)
  • [x] I have added this issue to the 'API Terraform Provider' GitHub project (right side menu)

dikhan avatar Dec 09 '18 21:12 dikhan

Hi @dikhan do you have any work done on this subject or any ideas how to approach it?

fredericosilva avatar Nov 19 '19 16:11 fredericosilva

Hey @fredericosilva ,

We are planning to work on this next after the https://github.com/dikhan/terraform-provider-openapi/pull/186 is done. Haven't put much thought on it besides the initial research when creating the issue, but the idea would be to have the provider understand properties that are\ defined as follows and expose their terraform schema as a Type: schema.TypeMap with Elem: &schema.Schema{Type: schema.TypeString}

  HashMapProperty:
    type: object
    additionalProperties:
      type: string # this defines the values of the map being strings

If you fancy taking a stub at it, the two places to look into would be:

  • https://github.com/dikhan/terraform-provider-openapi/blob/master/openapi/openapi_v2_resource.go#L331 which is in charge of translating the OpenAPI resource schema into an intermediary model that then it's used to build the terraform schema.
  • https://github.com/dikhan/terraform-provider-openapi/blob/master/openapi/openapi_spec_resource_schema_definition.go#L17 which is in charge of composing the terraform resource schema.

I would start putting together a test in https://github.com/dikhan/terraform-provider-openapi/blob/master/tests/e2e/resources_test.go that has the map described and asserting on the provider schema containing the hashmap which would fail. That could serve as the basic to get going and start drilling into the code to understand better the different places that need updates.

Hope this helps! Dani

dikhan avatar Nov 24 '19 21:11 dikhan

Thank you for pointing me in the right direction. I'll try to have a look on that later this week.

fredericosilva avatar Nov 27 '19 10:11 fredericosilva