eager-pillow-75917
04/23/2020, 12:03 PMTo 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`
faint-motherboard-95438
04/23/2020, 12:14 PMOutput
properly.wonderful-dog-9045
04/23/2020, 12:14 PMx
you can manipulate it with with x.apply(x => doSomethingWithX(x))
eager-pillow-75917
04/23/2020, 12:21 PMimport * 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-dependenciesinfra.getOutput("kubeConfig")
like it is in the documentation, I get the above error.wonderful-dog-9045
04/23/2020, 12:26 PMinfra.getOutput()
eager-pillow-75917
04/23/2020, 12:27 PMconst 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 });
});
wonderful-dog-9045
04/23/2020, 12:29 PMfaint-motherboard-95438
04/23/2020, 12:31 PMkubeConfig
?eager-pillow-75917
04/23/2020, 2:10 PMconst 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}`)
});
faint-motherboard-95438
04/23/2020, 2:13 PMinfra-staging
exporting your stagingClusterName
.
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.eager-pillow-75917
04/23/2020, 2:15 PMfaint-motherboard-95438
04/23/2020, 2:28 PMinfra-staging
creates a cluster and exports the config like this:
export const { kubeconfig } = cluster
You can then do somewhere else something like this:
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 })