ambikanair
ambikanair

Reputation: 4590

helm template to fetch a value from nested yaml doesnt work

crossregion:
  us:
    public:
      us-geo: s3.us.cloud-object-storage.appdomain.cloud
      Dallas: s3.dal.us.cloud-object-storage.appdomain.cloud
      Washington: s3.wdc.us.cloud-object-storage.appdomain.cloud
      San Jose: s3.sjc.us.cloud-object-storage.appdomain.cloud
    private:
      us-geo: s3.private.us.cloud-object-storage.appdomain.cloud
      Dallas: s3.private.dal.us.cloud-object-storage.appdomain.cloud
      Washington: s3.private.wdc.us.cloud-object-storage.appdomain.cloud
      San Jose: s3.private.sjc.us.cloud-object-storage.appdomain.cloud
    direct:
      us-geo: s3.direct.us.cloud-object-storage.appdomain.cloud
      Dallas: s3.direct.dal.us.cloud-object-storage.appdomain.cloud
      Washington: s3.direct.wdc.us.cloud-object-storage.appdomain.cloud
      San Jose: s3.direct.sjc.us.cloud-object-storage.appdomain.cloud
  eu:
    public:
      eu-geo: s3.eu.cloud-object-storage.appdomain.cloud
      Amsterdam: s3.ams.eu.cloud-object-storage.appdomain.cloud
      Frankfurt: s3.fra.eu.cloud-object-storage.appdomain.cloud
      Milan: s3.mil.eu.cloud-object-storage.appdomain.cloud
    private:
      eu-geo: s3.private.eu.cloud-object-storage.appdomain.cloud
      Amsterdam: s3.private.ams.eu.cloud-object-storage.appdomain.cloud
      Frankfurt: s3.private.fra.eu.cloud-object-storage.appdomain.cloud
      Milan: s3.private.mil.eu.cloud-object-storage.appdomain.cloud
    direct:
      eu-geo: s3.direct.eu.cloud-object-storage.appdomain.cloud
      Amsterdam: s3.direct.ams.eu.cloud-object-storage.appdomain.cloud

The value I need to get is actually crossregion.us.private.us-geo

For above values.yaml file, I am assigning EndPointType based on a condition and the value will be private or direct regionSubstr will be us in this case and hence appending -geo to get the final string as in crossregion.us.private.us-geo

ibm.io/object-store-endpoint: "https://{{ index $secondaryValueFile.crossregion $regionSubstr.$EndPointType.$regionSubstr }}-geo"

The above templating doesnt work though many combinations were tried. Where am I going wrong here

Upvotes: 0

Views: 119

Answers (1)

David Maze
David Maze

Reputation: 158908

You need to nest the template expressions here. In particular, you need to pass an index invocation as a field parameter to index.

Breaking this down into smaller pieces:

{{- $regionGeo := printf "%s-geo" $regionSubstr -}}
{{- $hostname := index $secondaryValueFile.crossregion $regionSubstr $EndpointType $regionGeo -}}
ibm.io/object-store-endpoint: "https://{{ $hostname }}"

The -geo suffix needs to be inside the template expression somewhere; I assign us-geo to another temporary variable using printf to compute that, and then it can go in the nested index expression with the various map layers above it.

It'd also be valid to inline it

https://{{ index $secondaryValueFile ... (printf "%s-geo" $regionSubstr) }}

though that's probably less readable.

Upvotes: 1

Related Questions