I'm new to Pulumi, and am trying to use it as an "...
# getting-started
m
I'm new to Pulumi, and am trying to use it as an "automation" type thing within a .net core web app. I found the "inline" code examples, but here is basically what I want. I have a basic default web page, with two buttons. Create, and Destroy. When I hit create, I want it to simply create a new VPC (my aws sso creds are current). When I click destroy, it should destroy said VPC. I have pulumi installed, aws cli installed, and of course .net stalled. Using visual studio at the moment. It is trying to say "pulumi" can't be found when debugging.
Copy code
{"An error occurred trying to start process 'pulumi' with working directory '<project directory>'. The system cannot find the file specified."}
m
The
pulumi
CLI command has to be available in the environment you're running your code because the Automation API is calling out to the CLI. It looks like the command is not in the
$PATH
of your debug session in VS Code.
m
Hmm...I'm using Visual Studio IDE, not VS Code and on Windows I see the pulumi path is in the "system" path setting, so in theory..it should be in the path regardless....
m
Yes, the IDE doesn't matter. It could also be that Pulumi cannot find the files or your project directory. "The system cannot find the file specified." doesn't seem to come from Pulumi.
m
Fixed that part..had to close all instances of VS.
For "inline" projects..is there a way to specify the AWS Profile to use?
I assume its something to do with: stack.SetConfigAsync("aws:region", new ConfigValue("us-east-1")); that line
m
Yes, in two ways: Either you use the AWS default provider, in which case you can do it via the terminal environment: https://www.pulumi.com/registry/packages/aws/installation-configuration/#aws-installation-configuration
Our you instantiate a dedicated AWS provider within your program: https://www.pulumi.com/registry/packages/aws/api-docs/provider/
I assume its something to do with: stack.SetConfigAsync("aws:region", new ConfigValue("us-east-1")); that line
This is also described in the first link, see the instructions for creating a Pulumi.<stack-name>.yaml file in this section: https://www.pulumi.com/registry/packages/aws/installation-configuration/#set-credentials-as-environment-variables
Instead of creating a YAML file, you can set the values as you described
m
Perfect
thanks! And as for "state". If the code is "re-used". For example, multiple users creating instances in AWS via the same page. How does pulumi managed the "state"? Is that via like the project name or the "stack" name? So like I would have to modify or dynamically set the stack name? or?
m
Canonically, you would give each user their own stack, based on the same program.
m
K. That should be easy enough. So its "stack" based. Thanks!! That should be enough to get me rolling down this hill...
m
You can also give each user their own project and the same set of stacks, which is sometimes more aligned with the overall structure of your application, but this is orthogonal to the way Pulumi is designed
m
Ya, in short, I need to provide a way for a limited set of users to create AWS Ec2's based on a name they provide. So it auto-tags/creates vpc, subnet, security group, ec2 (with same base tags). everything would be named like <company>-prod-<name>-resourcetype-<etc>
then when destroying, it just kills it all.
m
Yes, I'd say especially if you just have one stack per user, keep everything in one project
You can figure out the stack name in your program and use this to create your resource names: https://www.pulumi.com/docs/iac/concepts/stacks/#getting-the-current-stack-programmatically
Also check out the new advanced autonaming feature that was announced today, it should make your life even easier: https://www.pulumi.com/blog/autonaming-configuration/
m
If I'm configuring that inline, I would assume its another SetConfigValue, and then setting pulumiautonamingpattern...but i'm not entirely sure that is now "nested" config works inline
m
Not sure I ever had to do this, but have a look at https://github.com/pulumi/pulumi/issues/5506#issuecomment-703765944
(There's also the #C019YSXN04B channel where you'll likely get more eyes on your Automation API related questions)