pulumi-kubernetes
pulumi-kubernetes copied to clipboard
[improvement] - Support Input<string> for YAML path
Problem description
Output as an input for the file parameter on the yaml.ConfigFile resource isn't supported. This would be useful to have in certain scenarios when you want to construct the source of the file from another resource.
Errors & Logs
Type 'Output<string>' is not assignable to type 'string | undefined'.
Type 'Output<string>' is not assignable to type 'string'
Reproducing the issue
import * as pulumi from "@pulumi/pulumi"
import * as k8s from "@pulumi/kubernetes";
const provider = new k8s.Provider("render-yaml", {
renderYamlToDirectory: "rendered",
});
const appLabels = { app: "nginx" };
const deployment = new k8s.apps.v1.Deployment("nginx", {
spec: {
selector: { matchLabels: appLabels },
replicas: 1,
template: {
metadata: { labels: appLabels },
spec: { containers: [{ name: "nginx", image: "nginx" }] }
}
}
}, { provider });
const filePath = pulumi.interpolate `./rendered/${deployment.id}.yaml`
const yaml = new k8s.yaml.ConfigFile("nginx-deploy", {
file: filePath
}, { provider })
export const name = deployment.metadata.name;
As a workaround for this issue, you can call the ConfigFile or ConfigGroup constructor within an apply, which will unwrap the Input<string> for you. Note that this will reduce the accuracy of previews since the input may not be known.
@lblackstone I'm interested in #1129 which you closed as a duplicate (though I believe it refers to ConfigGroupArgs YAML field rather than Files).
I tried the suggested workaround of calling ConfigGroup constructor within an apply, but it results in the group and its k8s resources not being displayed as part of pulumi preview.
Is there any way to customize a k8s resource based on an output of another resource, with all resources included in pulumi preview (without converting all yaml files to native sdk objects)?
A basic scenario is setting a resource annotation based on an AWS role created in the same stack.
@osela In general, it's not possible to preview resources created inside an apply if the input is unknown. (apply is a callback that only runs once the input resolves, so it doesn't run when previewing an unknown input).
You would have more flexibility and better previews with native SDK resources, but it's unfortunately not always possible with YAML.
So I'm running into this (via #1129) as well, but for me, the issue seems even weirder: actually applying the applyed ConfigGroup with yaml from an input causes pulumi up to error out with "error: Duplicate resource URN 'urn:pulumi:asf::mzcloud::kubernetes:yaml:ConfigGroup::instances-eu-west-1-link-to-backend'; try giving it a unique name" (but that URN is the only one in the entire stack - in fact, the only resource that exists has that error on it in the resource viewer).
Does that mean that the ConfigGroup is re-created if the input yaml changes, but it collides with itself? I'm not sure, but it seems like a really weird one.
Does that mean that the
ConfigGroupis re-created if the input yaml changes, but it collides with itself? I'm not sure, but it seems like a really weird one.
@antifuchs That shouldn't be the case, so I'd guess it's related to something about the apply command you're using. Can you open a new issue with repro code if you're still having this issue?
Please just fix it. What is the problem?
As a workaround for this issue, you can call the
ConfigFileorConfigGroupconstructor within anapply, which will unwrap theInput<string>for you. Note that this will reduce the accuracy of previews since the input may not be known.
Thanks for the workaround. It's easy to forget such tricks when you try to stick to good practices.
I've just crossed this issue because I can't use crossplane resources with Pulumi due to https://github.com/pulumi/crd2pulumi/issues/126, therefore I need to use yaml files, but in my situation I need to interpolate things in the yaml file I'm applying.
Closing as a duplicate of https://github.com/pulumi/pulumi-kubernetes/issues/2203