I am trying to use an output as a value in another...
# general
I am trying to use an output as a value in another resource but keep getting this:
Copy code
To get the value of an Output<T> as an Output<string> consider either:
1: o.apply(v => `prefix${v}suffix`)
2: pulumi.interpolate `prefix${v}suffix`
Hi @eager-pillow-75917, You should provide us a snippet of your code in order to help you with. This error usually means what it says, your are not consuming the
that's because the value is not resolved yet (it will be resolved at a later stage).
So if you value is on variable
you can manipulate it with with
x.apply(x => doSomethingWithX(x))
Thanks Garik.
But hey, the documentation is wrong, then.
this is basically what I am trying to do…
Copy code
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
const env = pulumi.getStack();
const infra = new pulumi.StackReference(`acmecorp/infra/${env}`);
const provider = new k8s.Provider("k8s", { kubeconfig: infra.getOutput("kubeConfig") });
const service = new k8s.core.v1.Service(..., { provider: provider });
I got this snippet from https://www.pulumi.com/docs/intro/concepts/organizing-stacks-projects/#inter-stack-dependencies
If I `
Copy code
like it is in the documentation, I get the above error.
ok, that depends on how you are using the return value of
I had to do something like this to make it work.
Copy code
const infra = new pulumi.StackReference("acmecorp/infra/${env}");

export const kubeConfig = infra.getOutput("kubeConfig");
let provider;
kubeConfig.apply(clusterNameOutput => {
  bucket = new k8s.Provider("k8s", { kubeconfig: kubeConfig });
no it doesnt man
the documentation is just wrong
I am using an output as a value in a new resource just like in the documentation and it just does not work
to be fair, just like a number of other things are also misleading in the docs
i guess it may be outdated.
@eager-pillow-75917 if you provide the whole exact code you are using, someone can actually help you on your context. What the doc says works. I have several clusters doing exactly that.
What is the code of your stack exporting the
this is how I did it. (the kubeconfig I was using the same xample as the documentation)
Copy code
const infra = new pulumi.StackReference("infra-staging");

export const clusterNameOutput = infra.getOutput("stagingClusterName");

clusterNameOutput.apply(clusterNameOutput => {
  const bucket = new gcp.storage.Bucket(`my-test-bucket-${clusterNameOutput}`)
but the documentation for inter stack dependency does not say anything about the apply method and only uses getOutput
@eager-pillow-75917 I would be interested in what’s happening in the stack
exporting your
. But there’s already a problem in your code here: you shouldn’t try to use outputs in the name of a component, that should be a static string.
let´s try to abstract the issue here man
that was just the simplest example I could think of
I am dont need a bucket
this is just an exaple
read the first thing I sent this morning
I need to use an output as a value in another resource.
You know I’m actually trying to help you here, this is a community and we all give our time freely. We don’t work on “abstract”. The doc and examples work. So if you have an issue with your code that’s exactly where the problem resides, not on an “abstract” example of yours. So take it easy “man”. So, on an “asbtract” way of doing things, based on what you provided this morning, giving your
creates a cluster and exports the config like this:
export const { kubeconfig } = cluster
You can then do somewhere else something like this:
Copy code
const infraStack = new pulumi.StackReference('infra-staging')

const k8sProvider = new k8s.Provider('k8s-provider', {
  kubeconfig: infraStack.getOutput('kubeconfig')

const myNamespace = new k8s.core.v1.Namespace('whatever', {}, { provider: k8sProvider })