bedrock icon indicating copy to clipboard operation
bedrock copied to clipboard

SPK Infra should support multiple terraform input types

Open NathanielRose opened this issue 5 years ago • 5 comments

As a: Developer I want: Use various input types for my definition.yaml So that: I can map the input to terraform variables in my deployment Describe the solution you'd like: Terraform has multiple input types for variables:

variable "image_id" {
  type = string
}

variable "availability_zone_names" {
  type    = list(string)
  default = ["us-west-1a"]
}

variable "docker_ports" {
  type = list(object({
    internal = number
    external = number
    protocol = string
  }))
  default = [
    {
      internal = 8300
      external = 8300
      protocol = "tcp"
    }
  ]
}

The definition.yaml should be able to support these input types so generate is able to correctly configure a var file representative of the expected input.

Acceptance Criteria:

  • [ ] Refactor generate.ts(most likely dirIteration and generateTfvars) so that it handles lists and maps appropriately in Terraform.

Additional context:

What some folks are currently doing to get around this

We are storing those kind of variables as string and parsing them with terraform functions. ex: definition.yaml

event_hub_name_suffix: "dev|qa|prod"
turnstile_secrets: "KV_TURNSTILE_ENDPOINT=$turnstileEndpoint|KV_TURNSTILE_KEY=$turnstileKey|KV_TURNSTILE_SECRET=$turnstileSecret"

terraform remapping

locals {
  turnstile_secrets = merge(flatten([[
      for kv in split("|", var.turnstile_secrets) : [
        { split("=", kv)[0] : split("=", kv)[1] }
      ] if kv != ""
    ]])...)
  event_hub_name_suffix = split("|", var.event_hub_name_suffix)
}

Does this require updates to documentation?: Yes

NathanielRose avatar Feb 24 '20 15:02 NathanielRose

Just to clarify - spk infra is capable of handling strings and numbers in yaml definitions, just not lists and maps.

yradsmikham avatar Mar 02 '20 19:03 yradsmikham

@NathanielRose @yradsmikham given the response by the customer can we have an idea on a implementation for this?

I updated the description with a an example of what the customer is currently doing.

andrebriggs avatar Mar 04 '20 00:03 andrebriggs

@andrebriggs @NathanielRose this should be handled in generate.ts in how it parses and extracts definitions when writing to spk.tfvars. I will update the description to include this.

yradsmikham avatar Mar 04 '20 16:03 yradsmikham

@NathanielRose @yradsmikham do we have a design doc talking a bit about the implementation approach here? I'm not clear on the example in the description since

andrebriggs avatar Apr 27 '20 05:04 andrebriggs

@andrebriggs Currently there isn't a design doc on this yet, but to summarize briefly spk infra generate does not support lists, arrays as inputs to convert into a terraform input.

NathanielRose avatar Apr 27 '20 13:04 NathanielRose