sparse-intern-71089
09/27/2022, 9:37 PMstocky-account-72012
09/27/2022, 9:37 PMinfrastructure, which i successfully spun up. in this project is a Kubernetes cluster. in the script i used to create it, I exported a whole bunch of outputs which i will need to reference in other projects.
this code is from the next project i want to spin up, where i try to reference the values of the first project. my teammate - who has since left the company sad panda - created this handy function which passes your logic into an `apply`:
export const useClusterAttributes = (infraStackName: string, func: (outputs: ClusterAttributes) => any) => {
const stackRef = new pulumi.StackReference(infraStackName)
stackRef.getOutput('clusterName').apply(clusterName => { console.log(`The clusterName should be a string here, right?: ${clusterName}`) })
return pulumi.all([
stackRef.getOutput('vpcId'),
stackRef.getOutput('publicSubnetIds'),
stackRef.getOutput('privateSubnetIds'),
stackRef.getOutput('clusterName'),
stackRef.getOutput('kubeconfig'),
stackRef.getOutput('clusterOidcProviderArn'),
stackRef.getOutput('clusterOidcProviderUrl'),
])
.apply(([
vpcId,
publicSubnetIds,
privateSubnetIds,
clusterName,
kubeconfig,
clusterOidcProviderArn,
clusterOidcProviderUrl,
]) => {
console.log(`At least should be a string here: ${clusterName}`);
func({
vpcId,
publicSubnetIds,
privateSubnetIds,
clusterName,
kubeconfig,
clusterOidcProviderArn,
clusterOidcProviderUrl,
})
})
}
i added those console.log statements, we'll get to them in a sec.stocky-account-72012
09/27/2022, 9:39 PMuseClusterAttributes(infraStackName, async ({
vpcId,
clusterName,
kubeconfig,
clusterOidcProviderArn,
clusterOidcProviderUrl,
}) => {
const k8sProvider = ensureProvider(clusterName, kubeconfig)
... declare more resources down here ...
})stocky-account-72012
09/27/2022, 9:40 PMapply syntax. the goal of userClusterAttributes is to prevent us from rewriting pulumi.all and apply commands for the same outputs again and again. please let me know if anyone needs clarification on this function and i'd be happy to explain more!stocky-account-72012
09/27/2022, 9:42 PMclusterName, vpcId, etc. - all evaluate to undefined.
so when i try to create that k8sProvider, i get this error: Error: Missing resource name argument (for URN creation)
and my console.log statements from earlier?
hello orgname/infrastructure/stackname
OutputImpl {
__pulumiOutput: true,
resources: [Function (anonymous)],
allResources: [Function (anonymous)],
isKnown: Promise { <pending> },
isSecret: Promise { <pending> },
promise: [Function (anonymous)],
toString: [Function (anonymous)],
toJSON: [Function (anonymous)]
}
The clusterName should be a string here, right?: undefined
At least should be a string here: undefinedstocky-account-72012
09/27/2022, 9:42 PMstackRef.getOutput Outputs are evaluating to undefined?stocky-account-72012
09/27/2022, 9:45 PMbillowy-army-68599
stocky-account-72012
09/27/2022, 9:51 PMconst stackName = pulumi.getStack();
const infraStackName = `orgname/infrastructure/${stackName}`;
useClusterAttributes(infraStackName, async ({
vpcId,
clusterName,
kubeconfig,
clusterOidcProviderArn,
clusterOidcProviderUrl,
}) => {
..........
})
and, in a separate file is the definition of `useClusterAttributes`:
export const useClusterAttributes = (infraStackName: string, func: (outputs: ClusterAttributes) => any) => {
const stackRef = new pulumi.StackReference(infraStackName)
.......billowy-army-68599
stocky-account-72012
09/27/2022, 10:10 PMconsole.log to spit out the infraStackName inside the useClusterAttributes function, and the value it put out was orgname/infrastructure/stackname and looked correct.
2. i also tried altering the infraStackName variable in my main script to intentionally put a mistake in it. i then got this error:
error: Preview failed: unknown stack "orgname/infrararastructure/stackname"billowy-army-68599
billowy-army-68599
.apply on the stack refbillowy-army-68599
stackRef.getOutput('vpcId'),
stackRef.getOutput('publicSubnetIds'),
stackRef.getOutput('privateSubnetIds'),
stackRef.getOutput('clusterName'),
stackRef.getOutput('kubeconfig'),
stackRef.getOutput('clusterOidcProviderArn'),
stackRef.getOutput('clusterOidcProviderUrl'),billowy-army-68599
stocky-account-72012
09/27/2022, 10:16 PMbillowy-army-68599
billowy-army-68599
stocky-account-72012
09/27/2022, 10:16 PMstocky-account-72012
09/27/2022, 10:18 PMprocess in front of them, e.g. processClusterName, processVpcId, etc. I rewrote them all to not have process, and I am searching my codebase and there is no instance of anything that says processClusterName anymore.
also, i'm pasting the screenshot i showed above from my terminal when i ran pulumi up on my stack. it wrote that the outputs were just clusterName, no process.stocky-account-72012
09/27/2022, 10:19 PMstocky-account-72012
09/27/2022, 10:20 PMprocessClusterName and it actually found something. no more undefined 🎉
so now my question is: why don't my terminal's outputs match what appears to actually be running?stocky-account-72012
09/27/2022, 10:20 PMbillowy-army-68599
up and it should update themstocky-account-72012
09/27/2022, 10:24 PMstocky-account-72012
09/27/2022, 10:35 PMstocky-account-72012
09/27/2022, 10:36 PMpulumi up is donestocky-account-72012
09/27/2022, 11:07 PMinfrastructure project before. i thought i had wiped out all those old outputs, but i missed that the deployment failed.
as always, the issue lied between the chair and the keyboard 🤦♂️
thank you for your help @billowy-army-68599!! you walking me through it led to finding this, so you definitely contributed here. i should be able to straighten this out now that i have a handle on things.No matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.
Powered by