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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested variable resolution #506

Open
aureq opened this issue Sep 6, 2023 · 5 comments
Open

Nested variable resolution #506

aureq opened this issue Sep 6, 2023 · 5 comments
Labels
kind/enhancement Improvements or new features

Comments

@aureq
Copy link
Member

aureq commented Sep 6, 2023

Hello!

  • Vote on this issue by adding a 馃憤 reaction
  • If you want to implement this feature, comment to let us know (we'll work with you on design, scheduling, etc.)

Issue details

Currently, pulumi YAML is unable to resolve nested variables such as this example. The important line here being project: ${projectDescription.${selector}} where the project description could be fet

name: example-yaml-app
runtime: yaml
description: A minimal AWS Pulumi YAML program
outputs:
  bucketName: ${my-bucket.id}

variables:
    projectDescription:
        projectA: "This is project A"
        projectB: "This is project B"

config:
    selector: "projectA"

resources:
  # Create an AWS resource (S3 Bucket)
  my-bucket:
    type: aws:s3:Bucket
    properties:
      tags:
        project: ${projectDescription.${selector}}

The pulumi pre --diff shows

+ pulumi:pulumi:Stack: (create)
    [urn=urn:pulumi:dev::delete-me::pulumi:pulumi:Stack::delete-me-dev]
    + aws:s3/bucket:Bucket: (create)
        [urn=urn:pulumi:dev::delete-me::aws:s3/bucket:Bucket::my-bucket]
        acl         : "private"
        bucket      : "my-bucket-849a90c"
        forceDestroy: false
        tags        : {
            project   : "<nil> }"
        }
    --outputs:--
    bucketName: output<string>

I've also tried using project: ${projectDescription}.${selector} but this returns:

+ pulumi:pulumi:Stack: (create)
    [urn=urn:pulumi:dev::delete-me::pulumi:pulumi:Stack::delete-me-dev]
    + aws:s3/bucket:Bucket: (create)
        [urn=urn:pulumi:dev::delete-me::aws:s3/bucket:Bucket::my-bucket]
        acl         : "private"
        bucket      : "my-bucket-bd16986"
        forceDestroy: false
        tags        : {
            project   : "map[projectA:This is project A projectB:This is project B].projectA"
        }
    --outputs:--
    bucketName: output<string>

Affected area/feature

  • nested variables
@aureq aureq added kind/enhancement Improvements or new features needs-triage Needs attention from the triage team labels Sep 6, 2023
@AaronFriel
Copy link
Member

As an alternative, would fn::select supporting maps and object types meet the user's needs?

(This is a straw proposal, but I think this would be a lower lift than changing the expression syntax similar to how you've described.)

# all other keys identical to example

resources:
  # Create an AWS resource (S3 Bucket)
  my-bucket:
    type: aws:s3:Bucket
    properties:
      tags:
        project: 
          fn::select:
            - ${selector}
            - ${projectDescription}

@grantbeattie
Copy link

grantbeattie commented Sep 6, 2023

fn::select would be an option.. but how would it work for multi-level objects? eg.

variables:
  projectDescription:
    regionA:
      projectA: "This is region A, project A"
      projectB: "This is region A, project B"
    regionB:
      projectA: "This is region B, project A"
      projectB: "This is region B, project B"

config:
  regionSelector: "regionA"
  projectSelector: "projectA"

projectDescription.${regionSelector}.${projectSelector} would read fairly well and is obvious what is happening.

@Frassle
Copy link
Member

Frassle commented Sep 6, 2023

Why not ${projectDescription[selector]}?

@grantbeattie
Copy link

Why not ${projectDescription[selector]}?

yep, that works too.

@AaronFriel
Copy link
Member

@Frassle changing the substitution parsing requires more significant changes, changing or adding a built-in is lower lift.

However I'm wondering if std already has this?

It looks like fn::std:lookup has the right shape.

@justinvp justinvp removed the needs-triage Needs attention from the triage team label Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements or new features
Projects
None yet
Development

No branches or pull requests

5 participants