most-lighter-95902
12/02/2021, 12:58 AMnew StackReference
as many times I need, but when I put it in a function and it gets called twice, I get resource 'urn:pulumi:app-staging::ckc-test::pulumi:pulumi:StackReference::seunggs/ckc-test/app-build' registered twice (read and read)
error and pulumi up
fails during preview. What am I doing wrong?billowy-army-68599
12/02/2021, 1:15 AMmost-lighter-95902
12/02/2021, 2:57 AMconst main = async () => {
const stack = pulumi.getStack()
const checkStackExists = (qualifiedStackName: string) => {
try {
const stackRef = new pulumi.StackReference(qualifiedStackName)
return true
} catch (err) {
return false
}
}
const checkAppBuildStackExists = () => {
return checkStackExists(`${organization}/${project}/app-build`)
}
const getAppBuildStackOutputs = () => {
const appBuildStackRef = new pulumi.StackReference(`${organization}/${project}/app-build`)
const appEcrImageUrl = appBuildStackRef.getOutput('imageUrl') as pulumi.Output<string>
return appEcrImageUrl
}
if (stack === 'app-staging' || stack === 'app-prod') {
const appEcrImageUrl = checkAppBuildStackExists ? getAppBuildStackOutputs() : ''
const { AppStack } = await import('./pulumi/stacks/app')
const appStackOutput = new AppStack('app-stack', {
imageUrl: appEcrImageUrl,
}, { provider: k8sProvider })
return appStackOutput
}
}
export = main
billowy-army-68599
12/02/2021, 11:18 PMmost-lighter-95902
12/03/2021, 3:15 AMnew StackReference
multiple times then?new StackReference
freely because it errors out if the stack doesn’t exist.ambitious-father-68746
12/06/2021, 10:11 PMstack = pulumi.StackReference("unique_id_1", stack_name="blabla")
same_stack_again = pulumi.StackReference("unique_id_2", stack_name="blabla")
blabla
twice. The other way of doing it is changing your code so that you only need to reference it once, but this give you options.