This message was deleted.
# general
s
This message was deleted.
c
Copy code
import * as pulumi from "@pulumi/pulumi";

export interface LoftKubeconfigOptions {
    vclusterName: pulumi.Input<string> //name of vcluster itself
}

interface LoftKubeconfigDynamicProviderInputs {
    vclusterName: string //name of vcluster itself
}

interface LoftKubeconfigDynamicProviderOutputs extends LoftKubeconfigDynamicProviderInputs {
    data: string
}

const LoftKubeconfigProvider: pulumi.dynamic.ResourceProvider = {
    async create(inputs: LoftKubeconfigDynamicProviderInputs): Promise<pulumi.dynamic.CreateResult> {
        const data = require('child_process').execSync("loft use vcluster " + inputs.vclusterName + " --print --silent").toString('utf8')
        return {
            id: inputs.vclusterName,
            outs: <LoftKubeconfigDynamicProviderOutputs>{
                vclusterName: inputs.vclusterName,
                data: data,
            }
        };
    },
    async read(id: string, inputs: LoftKubeconfigDynamicProviderOutputs): Promise<pulumi.dynamic.CreateResult> {
        var vclusterName = inputs.vclusterName
        if ((typeof vclusterName) === "undefined") {
            <http://pulumi.log.info|pulumi.log.info>("vclusterName is undefined")
            vclusterName = id
            <http://pulumi.log.info|pulumi.log.info>("ID is:" + id)
        }
        if ((typeof vclusterName) === "undefined") {
            <http://pulumi.log.info|pulumi.log.info>("vclusterName is still undefined")
        } else {
            <http://pulumi.log.info|pulumi.log.info>("vclusterName is no longer undefined")
        }
        const data = require('child_process').execSync("loft use vcluster " + vclusterName + " --print --silent").toString('utf8')
        if ((typeof data) === "undefined") {
            <http://pulumi.log.info|pulumi.log.info>("data is undefined")
        } else {
            <http://pulumi.log.info|pulumi.log.info>("data is defined")
        }
        return {
            id: vclusterName,
            outs: <LoftKubeconfigDynamicProviderOutputs>{
                vclusterName: vclusterName,
                data: data,
            }
        };
    },
}

export class LoftKubeconfig extends pulumi.dynamic.Resource {
    public readonly data!: pulumi.Output<string> //kubeconfig yaml file

    constructor(name: string, props: LoftKubeconfigOptions, opts?: pulumi.CustomResourceOptions) {
        super(LoftKubeconfigProvider, `loft:vclusterKubeConfig:${name}`, {data: null, ...props}, opts);
    }
}
Refresh Output:
Copy code
info: [runtime] vclusterName is undefined
    info: [runtime] ID is:staging-x542cgot
    info: [runtime] vclusterName is no longer undefined
    info: [runtime] data is defined
Both vclusterName data stay undefined in the output.
figgered it out
p
what was it?
🙌 1
c
Output of read needs to be a ReadResult, not a CreateResult.
👍 1