pulumi / pulumi-pulumiservice

https://pulumi.com
Apache License 2.0
12 stars 5 forks source link

Provide Input<string> for YAML field in provider #327

Open liamawhite opened 1 week ago

liamawhite commented 1 week ago

Hello!

Issue details

Rather than have to write a bunch of additional boilerplate to convert to a promise and then an asset it would be good to just pass an input string.

I had to do the following in ts to achieve this:

 yaml: new pulumi.asset.StringAsset(
                    environment({
...
const environment = (args: {
    subName: string
    clientId: pulumi.Input<string>
    tenantId: pulumi.Input<string>
    subscriptionId: pulumi.Input<string>
}) =>
    PromisifyOutput<string>(pulumi.interpolate`
values:
  azure:
    login:
...
export function PromisifyOutput<T>(output: pulumi.Output<T>): Promise<T> {
    return new Promise((resolve) => output.apply(resolve))
}

which would become

 yaml: pulumi.interpolate`
values:
  azure:
    login:
...

Affected area/feature

esc provider

IaroslavTitov commented 1 week ago

Good morning Please take a look at our TS example of creating Environment resource here It should be pretty straightforward to turn a String into a StringAsset using new pulumi.asset.StringAsset(stringInput)

Does this solve your issue? I might have misunderstood

liamawhite commented 3 days ago

StringAsset doesn't take a Input<string> only a Promise<string>, hence the boilerplate. If the StringAsset took a. Input<string> that would also solve the problem.

IaroslavTitov commented 2 days ago

Oh, sorry I did not see the interpolate method at first. So the trouble is converting Output<string> into a StringAsset

I just tested the code below:

let yaml = pulumi.interpolate
    `values:
      myKey1: "myValue1"
      myNestedKey:
        myKey2: "myValue2"
        myNumber: 1`

var environment = new service.Environment("testing-environment", {
    organization: "service-provider-test-org",
    name: "testing-environment-ts",
    yaml: yaml.apply((y) => new pulumi.asset.StringAsset(y))
  })

You can convert Output<string>, by using the apply method, which extracts the underlying string, that can then be wrapped into StringAsset - yaml.apply((y) => new pulumi.asset.StringAsset(y)). I think you're already doing it very similarly in your code. I understand it's not as straightforward as yaml: yaml would have been. I think we went with Asset instead of string here to make loading environment yamls from files easier.

Does that help?