https://pulumi.com logo
#dotnet
Title
# dotnet
l

lively-pizza-96645

01/10/2023, 7:18 PM
What is the best way of creating local files after Pulumi has deployed successfully?
ended up writing my own provider to solve this issue. If there is any better solutions. Let me know
s

stocky-restaurant-98004

01/10/2023, 11:40 PM
You can use the Command provider and set
dependsOn
to the last thing to be provisioned. https://www.pulumi.com/registry/packages/command/api-docs/local/command/
l

lively-pizza-96645

01/11/2023, 2:40 AM
writing multiline strings with command is a bit iffy tho. unless there is something i missed?
s

stocky-restaurant-98004

01/11/2023, 3:13 AM
Hmm. Maybe the Automation API would be a better fit?
l

lively-pizza-96645

01/11/2023, 3:15 AM
might be... But like. How would one write a kubeconfig etc to local file system? Just to give a random example of a local file that depends on cloud resources
s

stocky-restaurant-98004

01/11/2023, 3:15 AM
pulumi stack output kubeconfig --show-secrets > kubeconfig.yaml
l

lively-pizza-96645

01/11/2023, 3:16 AM
ah. manual step. gotcha
s

stocky-restaurant-98004

01/11/2023, 3:18 AM
BUT, if you're using the Pulumi K8s provider, you can just feed it into the provider (this is C# and AKS, but you should be able to translate for your lang/cloud):
Copy code
var creds = AzureNative.ContainerService.ListManagedClusterUserCredentials.Invoke(new() {
    ResourceGroupName = resourceGroup.Name,
    ResourceName = managedCluster.Name,
});
var encoded = creds.Apply(result => result.Kubeconfigs[0]!.Value);
var decoded = encoded.Apply(enc => {
    var bytes = Convert.FromBase64String(enc);
    return Encoding.UTF8.GetString(bytes);
});

var provider = new Provider("k8s", new ProviderArgs {
  KubeConfig = decoded
});

// create K8s resources here
If you want to orchestrate, you could use Make for sure.
l

lively-pizza-96645

01/11/2023, 3:19 AM
Yeah. Just using kubeconfig as an example. Make as in? Makefile?
s

stocky-restaurant-98004

01/11/2023, 3:20 AM
Yeah. You can automate the commands to run after
pulumi up
l

lively-pizza-96645

01/11/2023, 3:21 AM
ah gotcha!
s

stocky-restaurant-98004

01/11/2023, 3:22 AM
You will need to use a pseudotarget since
pulumi up
does not create a file, but you could do something like
pulumi up -y && touch .make/pulumiup
or just use
.PHONY
and run
pulumi up
every time.
l

lively-pizza-96645

01/11/2023, 3:23 AM
I assume outputs can store arrays?
s

stocky-restaurant-98004

01/11/2023, 4:35 PM
Yes. You can do
Output<string[]>
or
Output<string>[]
. I believe the former is preferred.
b

bored-activity-40468

01/11/2023, 5:25 PM
@lively-pizza-96645 I copy this design but don't use the k8 provider but it might have examples of what you're looking for https://github.com/gitfool/Pulumi.Dungeon
78 Views